diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/kms/KMSClientProvider.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/kms/KMSClientProvider.java index 3ce7f1dbce0..12ce9158569 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/kms/KMSClientProvider.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/kms/KMSClientProvider.java @@ -1038,10 +1038,9 @@ public class KMSClientProvider extends KeyProvider implements CryptoExtension, return dtService; } - private boolean currentUgiContainsKmsDt() throws IOException { - // Add existing credentials from current UGI, since provider is cached. - Credentials creds = UserGroupInformation.getCurrentUser(). - getCredentials(); + private boolean containsKmsDt(UserGroupInformation ugi) throws IOException { + // Add existing credentials from the UGI, since provider is cached. + Credentials creds = ugi.getCredentials(); if (!creds.getAllTokens().isEmpty()) { org.apache.hadoop.security.token.Token dToken = creds.getToken(getDelegationTokenService()); @@ -1063,11 +1062,15 @@ public class KMSClientProvider extends KeyProvider implements CryptoExtension, if (currentUgi.getRealUser() != null) { // Use real user for proxy user actualUgi = currentUgi.getRealUser(); - } else if (!currentUgiContainsKmsDt() && - !currentUgi.hasKerberosCredentials()) { + } + + if (!containsKmsDt(actualUgi) && + !actualUgi.hasKerberosCredentials()) { // Use login user for user that does not have either // Kerberos credential or KMS delegation token for KMS operations - actualUgi = currentUgi.getLoginUser(); + LOG.debug("using loginUser no KMS Delegation Token " + + "no Kerberos Credentials"); + actualUgi = UserGroupInformation.getLoginUser(); } return actualUgi; }