You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by li...@apache.org on 2020/08/27 07:17:56 UTC
[hadoop] branch branch-3.1 updated: HADOOP-17159. Make UGI support
forceful relogin from keytab ignoring the last login time (#2249)
This is an automated email from the ASF dual-hosted git repository.
liuml07 pushed a commit to branch branch-3.1
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/branch-3.1 by this push:
new e1ac832 HADOOP-17159. Make UGI support forceful relogin from keytab ignoring the last login time (#2249)
e1ac832 is described below
commit e1ac832d5dce283c659ccfc47534c71cef10d921
Author: sguggilam <sa...@gmail.com>
AuthorDate: Wed Aug 26 23:45:21 2020 -0700
HADOOP-17159. Make UGI support forceful relogin from keytab ignoring the last login time (#2249)
Contributed by Sandeep Guggilam.
Signed-off-by: Mingliang Liu <li...@apache.org>
Signed-off-by: Steve Loughran <st...@apache.org>
---
.../hadoop/security/UserGroupInformation.java | 36 ++++++++++++++++++----
.../hadoop/security/TestUGILoginFromKeytab.java | 36 ++++++++++++++++++++++
2 files changed, 66 insertions(+), 6 deletions(-)
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java
index 0e4168c..ea22f53 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java
@@ -1115,7 +1115,29 @@ public class UserGroupInformation {
reloginFromKeytab(false);
}
+ /**
+ * Force re-Login a user in from a keytab file irrespective of the last login
+ * time. Loads a user identity from a keytab file and logs them in. They
+ * become the currently logged-in user. This method assumes that
+ * {@link #loginUserFromKeytab(String, String)} had happened already. The
+ * Subject field of this UserGroupInformation object is updated to have the
+ * new credentials.
+ *
+ * @throws IOException
+ * @throws KerberosAuthException on a failure
+ */
+ @InterfaceAudience.Public
+ @InterfaceStability.Evolving
+ public void forceReloginFromKeytab() throws IOException {
+ reloginFromKeytab(false, true);
+ }
+
private void reloginFromKeytab(boolean checkTGT) throws IOException {
+ reloginFromKeytab(checkTGT, false);
+ }
+
+ private void reloginFromKeytab(boolean checkTGT, boolean ignoreLastLoginTime)
+ throws IOException {
if (!shouldRelogin() || !isFromKeytab()) {
return;
}
@@ -1130,7 +1152,7 @@ public class UserGroupInformation {
return;
}
}
- relogin(login);
+ relogin(login, ignoreLastLoginTime);
}
/**
@@ -1151,25 +1173,27 @@ public class UserGroupInformation {
if (login == null) {
throw new KerberosAuthException(MUST_FIRST_LOGIN);
}
- relogin(login);
+ relogin(login, false);
}
- private void relogin(HadoopLoginContext login) throws IOException {
+ private void relogin(HadoopLoginContext login, boolean ignoreLastLoginTime)
+ throws IOException {
// ensure the relogin is atomic to avoid leaving credentials in an
// inconsistent state. prevents other ugi instances, SASL, and SPNEGO
// from accessing or altering credentials during the relogin.
synchronized(login.getSubjectLock()) {
// another racing thread may have beat us to the relogin.
if (login == getLogin()) {
- unprotectedRelogin(login);
+ unprotectedRelogin(login, ignoreLastLoginTime);
}
}
}
- private void unprotectedRelogin(HadoopLoginContext login) throws IOException {
+ private void unprotectedRelogin(HadoopLoginContext login,
+ boolean ignoreLastLoginTime) throws IOException {
assert Thread.holdsLock(login.getSubjectLock());
long now = Time.now();
- if (!hasSufficientTimeElapsed(now)) {
+ if (!hasSufficientTimeElapsed(now) && !ignoreLastLoginTime) {
return;
}
// register most recent relogin attempt
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestUGILoginFromKeytab.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestUGILoginFromKeytab.java
index bf4a2cc..47084ce 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestUGILoginFromKeytab.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestUGILoginFromKeytab.java
@@ -154,6 +154,42 @@ public class TestUGILoginFromKeytab {
Assert.assertNotSame(login1, login2);
}
+ /**
+ * Force re-login from keytab using the MiniKDC and verify the UGI can
+ * successfully relogin from keytab as well.
+ */
+ @Test
+ public void testUGIForceReLoginFromKeytab() throws Exception {
+ // Set this to false as we are testing force re-login anyways
+ UserGroupInformation.setShouldRenewImmediatelyForTests(false);
+ String principal = "foo";
+ File keytab = new File(workDir, "foo.keytab");
+ kdc.createPrincipal(keytab, principal);
+
+ UserGroupInformation.loginUserFromKeytab(principal, keytab.getPath());
+ UserGroupInformation ugi = UserGroupInformation.getLoginUser();
+ Assert.assertTrue("UGI should be configured to login from keytab",
+ ugi.isFromKeytab());
+
+ // Verify relogin from keytab.
+ User user = getUser(ugi.getSubject());
+ final long firstLogin = user.getLastLogin();
+ final LoginContext login1 = user.getLogin();
+ Assert.assertNotNull(login1);
+
+ // Sleep for 2 secs to have a difference between first and second login
+ Thread.sleep(2000);
+
+ // Force relogin from keytab
+ ugi.forceReloginFromKeytab();
+ final long secondLogin = user.getLastLogin();
+ final LoginContext login2 = user.getLogin();
+ Assert.assertTrue("User should have been able to relogin from keytab",
+ secondLogin > firstLogin);
+ Assert.assertNotNull(login2);
+ Assert.assertNotSame(login1, login2);
+ }
+
@Test
public void testGetUGIFromKnownSubject() throws Exception {
KerberosPrincipal principal = new KerberosPrincipal("user");
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org