Skip to content

Commit

Permalink
Support HADOOP_PROXY_USER for secure impersonation in hive metastore …
Browse files Browse the repository at this point in the history
…client (Nanda kumar via Thejas Nair)
  • Loading branch information
nandakumar131 authored and Thejas M Nair committed Jan 24, 2017
1 parent 4a42bec commit 3f90794
Showing 1 changed file with 37 additions and 0 deletions.
Expand Up @@ -45,6 +45,7 @@
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.security.PrivilegedExceptionAction;

import javax.security.auth.login.LoginException;

Expand Down Expand Up @@ -201,6 +202,42 @@ public HiveMetaStoreClient(HiveConf conf, HiveMetaHookLoader hookLoader, Boolean
LOG.error("NOT getting uris from conf");
throw new MetaException("MetaStoreURIs not found in conf file");
}

//If HADOOP_PROXY_USER is set in env or property,
//then need to create metastore client that proxies as that user.
String HADOOP_PROXY_USER = "HADOOP_PROXY_USER";
String proxyUser = System.getenv(HADOOP_PROXY_USER);
if (proxyUser == null) {
proxyUser = System.getProperty(HADOOP_PROXY_USER);
}
//if HADOOP_PROXY_USER is set, create DelegationToken using real user
if(proxyUser != null) {
LOG.info(HADOOP_PROXY_USER + " is set. Using delegation "
+ "token for HiveMetaStore connection.");
try {
UserGroupInformation.getLoginUser().getRealUser().doAs(
new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
open();
return null;
}
});
String delegationTokenPropString = "DelegationTokenForHiveMetaStoreServer";
String delegationTokenStr = getDelegationToken(proxyUser, proxyUser);
Utils.setTokenStr(UserGroupInformation.getCurrentUser(), delegationTokenStr,
delegationTokenPropString);
this.conf.setVar(ConfVars.METASTORE_TOKEN_SIGNATURE, delegationTokenPropString);
close();
} catch (Exception e) {
LOG.error("Error while setting delegation token for " + proxyUser, e);
if(e instanceof MetaException) {
throw (MetaException)e;
} else {
throw new MetaException(e.getMessage());
}
}
}
// finally open the store
open();
}
Expand Down

0 comments on commit 3f90794

Please sign in to comment.