Search in sources :

Example 11 with LlapTokenIdentifier

use of org.apache.hadoop.hive.llap.security.LlapTokenIdentifier in project hive by apache.

the class LlapTokenClient method extractToken.

private Token<LlapTokenIdentifier> extractToken(ByteString tokenBytes) throws IOException {
    Token<LlapTokenIdentifier> token = new Token<>();
    DataInputByteBuffer in = new DataInputByteBuffer();
    in.reset(tokenBytes.asReadOnlyByteBuffer());
    token.readFields(in);
    return token;
}
Also used : LlapTokenIdentifier(org.apache.hadoop.hive.llap.security.LlapTokenIdentifier) DataInputByteBuffer(org.apache.hadoop.io.DataInputByteBuffer) Token(org.apache.hadoop.security.token.Token)

Example 12 with LlapTokenIdentifier

use of org.apache.hadoop.hive.llap.security.LlapTokenIdentifier in project hive by apache.

the class LlapProtocolClientProxy method getProxy.

private LlapProtocolBlockingPB getProxy(final LlapNodeId nodeId) {
    String hostId = getHostIdentifier(nodeId.getHostname(), nodeId.getPort());
    LlapProtocolBlockingPB proxy = hostProxies.get(hostId);
    if (proxy == null) {
        if (llapToken == null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Creating a client without a token for " + nodeId);
            }
            proxy = new LlapProtocolClientImpl(getConfig(), nodeId.getHostname(), nodeId.getPort(), null, retryPolicy, socketFactory);
        } else {
            final UserGroupInformation ugi = UserGroupInformation.createRemoteUser(llapTokenUser);
            // Clone the token as we'd need to set the service to the one we are talking to.
            Token<LlapTokenIdentifier> nodeToken = new Token<LlapTokenIdentifier>(llapToken);
            SecurityUtil.setTokenService(nodeToken, NetUtils.createSocketAddrForHost(nodeId.getHostname(), nodeId.getPort()));
            ugi.addToken(nodeToken);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Creating a client for " + nodeId + "; the token is " + nodeToken);
            }
            proxy = ugi.doAs(new PrivilegedAction<LlapProtocolBlockingPB>() {

                @Override
                public LlapProtocolBlockingPB run() {
                    return new LlapProtocolClientImpl(getConfig(), nodeId.getHostname(), nodeId.getPort(), ugi, retryPolicy, socketFactory);
                }
            });
        }
        LlapProtocolBlockingPB proxyOld = hostProxies.putIfAbsent(hostId, proxy);
        if (proxyOld != null) {
            // TODO Shutdown the new proxy.
            proxy = proxyOld;
        }
    }
    return proxy;
}
Also used : LlapTokenIdentifier(org.apache.hadoop.hive.llap.security.LlapTokenIdentifier) PrivilegedAction(java.security.PrivilegedAction) Token(org.apache.hadoop.security.token.Token) LlapProtocolClientImpl(org.apache.hadoop.hive.llap.impl.LlapProtocolClientImpl) LlapProtocolBlockingPB(org.apache.hadoop.hive.llap.protocol.LlapProtocolBlockingPB) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 13 with LlapTokenIdentifier

use of org.apache.hadoop.hive.llap.security.LlapTokenIdentifier in project hive by apache.

the class SecretManager method decodeTokenIdentifier.

@Override
public LlapTokenIdentifier decodeTokenIdentifier(Token<LlapTokenIdentifier> token) throws IOException {
    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(token.getIdentifier()));
    LlapTokenIdentifier id = new LlapTokenIdentifier();
    id.readFields(dis);
    dis.close();
    return id;
}
Also used : LlapTokenIdentifier(org.apache.hadoop.hive.llap.security.LlapTokenIdentifier) ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream)

Example 14 with LlapTokenIdentifier

use of org.apache.hadoop.hive.llap.security.LlapTokenIdentifier in project hive by apache.

the class SecretManager method createLlapToken.

public Token<LlapTokenIdentifier> createLlapToken(String appId, String user, boolean isSignatureRequired) throws IOException {
    Text realUser = null, renewer = null;
    if (user == null) {
        UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
        user = ugi.getUserName();
        if (ugi.getRealUser() != null) {
            realUser = new Text(ugi.getRealUser().getUserName());
        }
        renewer = new Text(ugi.getShortUserName());
    } else {
        renewer = new Text(user);
    }
    LlapTokenIdentifier llapId = new LlapTokenIdentifier(new Text(user), renewer, realUser, clusterId, appId, isSignatureRequired);
    // TODO: note that the token is not renewable right now and will last for 2 weeks by default.
    Token<LlapTokenIdentifier> token = new Token<LlapTokenIdentifier>(llapId, this);
    if (LOG.isInfoEnabled()) {
        LOG.info("Created LLAP token {}", token);
    }
    return token;
}
Also used : LlapTokenIdentifier(org.apache.hadoop.hive.llap.security.LlapTokenIdentifier) Text(org.apache.hadoop.io.Text) Token(org.apache.hadoop.security.token.Token) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 15 with LlapTokenIdentifier

use of org.apache.hadoop.hive.llap.security.LlapTokenIdentifier in project hive by apache.

the class TezSessionState method getLlapToken.

private static Token<LlapTokenIdentifier> getLlapToken(String user, final Configuration conf) throws IOException {
    // TODO: parts of this should be moved out of TezSession to reuse the clients, but there's
    // no good place for that right now (HIVE-13698).
    // TODO: De-link from SessionState. A TezSession can be linked to different Hive Sessions via the pool.
    SessionState session = SessionState.get();
    boolean isInHs2 = session != null && session.isHiveServerQuery();
    Token<LlapTokenIdentifier> token = null;
    // For Tez, we don't use appId to distinguish the tokens.
    LlapCoordinator coordinator = null;
    if (isInHs2) {
        // We are in HS2, get the token locally.
        // TODO: coordinator should be passed in; HIVE-13698. Must be initialized for now.
        coordinator = LlapCoordinator.getInstance();
        if (coordinator == null) {
            throw new IOException("LLAP coordinator not initialized; cannot get LLAP tokens");
        }
        // Signing is not required for Tez.
        token = coordinator.getLocalTokenClient(conf, user).createToken(null, null, false);
    } else {
        // We are not in HS2; always create a new client for now.
        token = new LlapTokenClient(conf).getDelegationToken(null);
    }
    if (LOG.isInfoEnabled()) {
        LOG.info("Obtained a LLAP token: " + token);
    }
    return token;
}
Also used : SessionState(org.apache.hadoop.hive.ql.session.SessionState) LlapTokenIdentifier(org.apache.hadoop.hive.llap.security.LlapTokenIdentifier) IOException(java.io.IOException) LlapCoordinator(org.apache.hadoop.hive.llap.coordinator.LlapCoordinator) LlapTokenClient(org.apache.hadoop.hive.llap.security.LlapTokenClient)

Aggregations

LlapTokenIdentifier (org.apache.hadoop.hive.llap.security.LlapTokenIdentifier)16 IOException (java.io.IOException)5 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)5 ByteString (com.google.protobuf.ByteString)3 LlapCoordinator (org.apache.hadoop.hive.llap.coordinator.LlapCoordinator)3 Token (org.apache.hadoop.security.token.Token)3 ServiceException (com.google.protobuf.ServiceException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 URISyntaxException (java.net.URISyntaxException)2 LoginException (javax.security.auth.login.LoginException)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 Path (org.apache.hadoop.fs.Path)2 LlapInputSplit (org.apache.hadoop.hive.llap.LlapInputSplit)2 SubmitWorkInfo (org.apache.hadoop.hive.llap.SubmitWorkInfo)2 LlapServiceInstance (org.apache.hadoop.hive.llap.registry.LlapServiceInstance)2 LlapSigner (org.apache.hadoop.hive.llap.security.LlapSigner)2 SignedMessage (org.apache.hadoop.hive.llap.security.LlapSigner.SignedMessage)2 LlapTokenLocalClient (org.apache.hadoop.hive.llap.security.LlapTokenLocalClient)2