|
@@ -42,12 +42,9 @@ import org.apache.hadoop.security.authentication.client.PseudoAuthenticator;
|
|
|
import org.apache.hadoop.security.authorize.AuthorizationException;
|
|
|
import org.apache.hadoop.security.ssl.KeyStoreTestUtil;
|
|
|
import org.apache.hadoop.security.token.Token;
|
|
|
-import org.apache.hadoop.test.GenericTestUtils;
|
|
|
-import org.apache.log4j.Level;
|
|
|
-import org.junit.AfterClass;
|
|
|
+import org.junit.After;
|
|
|
import org.junit.Assert;
|
|
|
import org.junit.Before;
|
|
|
-import org.junit.BeforeClass;
|
|
|
import org.junit.Rule;
|
|
|
import org.junit.Test;
|
|
|
import org.junit.rules.Timeout;
|
|
@@ -88,11 +85,11 @@ public class TestKMS {
|
|
|
public final Timeout testTimeout = new Timeout(180000);
|
|
|
|
|
|
@Before
|
|
|
- public void cleanUp() {
|
|
|
+ public void setUp() throws Exception {
|
|
|
+ setUpMiniKdc();
|
|
|
// resetting kerberos security
|
|
|
Configuration conf = new Configuration();
|
|
|
UserGroupInformation.setConfiguration(conf);
|
|
|
- GenericTestUtils.setLogLevel(LOG, Level.INFO);
|
|
|
}
|
|
|
|
|
|
public static File getTestDir() throws Exception {
|
|
@@ -232,10 +229,8 @@ public class TestKMS {
|
|
|
private static MiniKdc kdc;
|
|
|
private static File keytab;
|
|
|
|
|
|
- @BeforeClass
|
|
|
- public static void setUpMiniKdc() throws Exception {
|
|
|
+ private static void setUpMiniKdc(Properties kdcConf) throws Exception {
|
|
|
File kdcDir = getTestDir();
|
|
|
- Properties kdcConf = MiniKdc.createConf();
|
|
|
kdc = new MiniKdc(kdcConf, kdcDir);
|
|
|
kdc.start();
|
|
|
keytab = new File(kdcDir, "keytab");
|
|
@@ -255,11 +250,18 @@ public class TestKMS {
|
|
|
principals.toArray(new String[principals.size()]));
|
|
|
}
|
|
|
|
|
|
- @AfterClass
|
|
|
- public static void tearDownMiniKdc() throws Exception {
|
|
|
+ private void setUpMiniKdc() throws Exception {
|
|
|
+ Properties kdcConf = MiniKdc.createConf();
|
|
|
+ setUpMiniKdc(kdcConf);
|
|
|
+ }
|
|
|
+
|
|
|
+ @After
|
|
|
+ public void tearDownMiniKdc() throws Exception {
|
|
|
if (kdc != null) {
|
|
|
kdc.stop();
|
|
|
+ kdc = null;
|
|
|
}
|
|
|
+ UserGroupInformation.setShouldRenewImmediatelyForTests(false);
|
|
|
}
|
|
|
|
|
|
private <T> T doAs(String user, final PrivilegedExceptionAction<T> action)
|
|
@@ -2053,6 +2055,73 @@ public class TestKMS {
|
|
|
doWebHDFSProxyUserTest(false);
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testTGTRenewal() throws Exception {
|
|
|
+ tearDownMiniKdc();
|
|
|
+ Properties kdcConf = MiniKdc.createConf();
|
|
|
+ kdcConf.setProperty(MiniKdc.MAX_TICKET_LIFETIME, "3");
|
|
|
+ kdcConf.setProperty(MiniKdc.MIN_TICKET_LIFETIME, "3");
|
|
|
+ setUpMiniKdc(kdcConf);
|
|
|
+
|
|
|
+ Configuration conf = new Configuration();
|
|
|
+ conf.set("hadoop.security.authentication", "kerberos");
|
|
|
+ UserGroupInformation.setConfiguration(conf);
|
|
|
+ final File testDir = getTestDir();
|
|
|
+ conf = createBaseKMSConf(testDir);
|
|
|
+ conf.set("hadoop.kms.authentication.type", "kerberos");
|
|
|
+ conf.set("hadoop.kms.authentication.kerberos.keytab",
|
|
|
+ keytab.getAbsolutePath());
|
|
|
+ conf.set("hadoop.kms.authentication.kerberos.principal", "HTTP/localhost");
|
|
|
+ conf.set("hadoop.kms.authentication.kerberos.name.rules", "DEFAULT");
|
|
|
+ conf.set("hadoop.kms.proxyuser.client.users", "*");
|
|
|
+ conf.set("hadoop.kms.proxyuser.client.hosts", "*");
|
|
|
+ writeConf(testDir, conf);
|
|
|
+
|
|
|
+ runServer(null, null, testDir, new KMSCallable<Void>() {
|
|
|
+ @Override
|
|
|
+ public Void call() throws Exception {
|
|
|
+ final Configuration conf = new Configuration();
|
|
|
+ final URI uri = createKMSUri(getKMSUrl());
|
|
|
+ UserGroupInformation.setShouldRenewImmediatelyForTests(true);
|
|
|
+ UserGroupInformation
|
|
|
+ .loginUserFromKeytab("client", keytab.getAbsolutePath());
|
|
|
+ final UserGroupInformation clientUgi =
|
|
|
+ UserGroupInformation.getCurrentUser();
|
|
|
+ clientUgi.doAs(new PrivilegedExceptionAction<Void>() {
|
|
|
+ @Override
|
|
|
+ public Void run() throws Exception {
|
|
|
+ // Verify getKeys can relogin
|
|
|
+ Thread.sleep(3100);
|
|
|
+ KeyProvider kp = createProvider(uri, conf);
|
|
|
+ kp.getKeys();
|
|
|
+
|
|
|
+ // Verify addDelegationTokens can relogin
|
|
|
+ // (different code path inside KMSClientProvider than getKeys)
|
|
|
+ Thread.sleep(3100);
|
|
|
+ kp = createProvider(uri, conf);
|
|
|
+ ((KeyProviderDelegationTokenExtension.DelegationTokenExtension) kp)
|
|
|
+ .addDelegationTokens("myuser", new Credentials());
|
|
|
+
|
|
|
+ // Verify getKeys can relogin with proxy user
|
|
|
+ UserGroupInformation anotherUgi =
|
|
|
+ UserGroupInformation.createProxyUser("client1", clientUgi);
|
|
|
+ anotherUgi.doAs(new PrivilegedExceptionAction<Void>() {
|
|
|
+ @Override
|
|
|
+ public Void run() throws Exception {
|
|
|
+ Thread.sleep(3100);
|
|
|
+ KeyProvider kp = createProvider(uri, conf);
|
|
|
+ kp.getKeys();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
public void doWebHDFSProxyUserTest(final boolean kerberos) throws Exception {
|
|
|
Configuration conf = new Configuration();
|
|
|
conf.set("hadoop.security.authentication", "kerberos");
|