|
@@ -39,6 +39,7 @@ import static org.junit.Assert.fail;
|
|
|
import java.io.IOException;
|
|
|
import java.lang.reflect.Method;
|
|
|
import java.net.URISyntaxException;
|
|
|
+import java.security.PrivilegedExceptionAction;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Comparator;
|
|
@@ -218,6 +219,14 @@ public class TestRouterRpc {
|
|
|
cluster.setIndependentDNs();
|
|
|
|
|
|
Configuration conf = new Configuration();
|
|
|
+ // Setup proxy users.
|
|
|
+ conf.set("hadoop.proxyuser.testRealUser.groups", "*");
|
|
|
+ conf.set("hadoop.proxyuser.testRealUser.hosts", "*");
|
|
|
+ String loginUser = UserGroupInformation.getLoginUser().getUserName();
|
|
|
+ conf.set(String.format("hadoop.proxyuser.%s.groups", loginUser), "*");
|
|
|
+ conf.set(String.format("hadoop.proxyuser.%s.hosts", loginUser), "*");
|
|
|
+ // Enable IP proxy users.
|
|
|
+ conf.set(DFSConfigKeys.DFS_NAMENODE_IP_PROXY_USERS, "placeholder");
|
|
|
conf.setInt(DFSConfigKeys.DFS_LIST_LIMIT, 5);
|
|
|
cluster.addNamenodeOverrides(conf);
|
|
|
// Start NNs and DNs and wait until ready
|
|
@@ -2077,6 +2086,38 @@ public class TestRouterRpc {
|
|
|
assertTrue(verifyFileExists(routerFS, dirPath));
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testRealUserPropagationInCallerContext()
|
|
|
+ throws IOException, InterruptedException {
|
|
|
+ GenericTestUtils.LogCapturer auditlog =
|
|
|
+ GenericTestUtils.LogCapturer.captureLogs(FSNamesystem.auditLog);
|
|
|
+
|
|
|
+ // Current callerContext is null
|
|
|
+ assertNull(CallerContext.getCurrent());
|
|
|
+
|
|
|
+ UserGroupInformation loginUser = UserGroupInformation.getLoginUser();
|
|
|
+ UserGroupInformation realUser = UserGroupInformation
|
|
|
+ .createUserForTesting("testRealUser", new String[]{"group"});
|
|
|
+ UserGroupInformation proxyUser = UserGroupInformation
|
|
|
+ .createProxyUser("testProxyUser", realUser);
|
|
|
+ FileSystem proxyFs = proxyUser.doAs(
|
|
|
+ (PrivilegedExceptionAction<FileSystem>) () -> router.getFileSystem());
|
|
|
+ proxyFs.listStatus(new Path("/"));
|
|
|
+
|
|
|
+
|
|
|
+ final String logOutput = auditlog.getOutput();
|
|
|
+ // Login user, which is used as the router's user, is different from the realUser.
|
|
|
+ assertNotEquals(loginUser.getUserName(), realUser.getUserName());
|
|
|
+ // Login user is used in the audit log's ugi field.
|
|
|
+ assertTrue("The login user is the proxyUser in the UGI field",
|
|
|
+ logOutput.contains(String.format("ugi=%s (auth:PROXY) via %s (auth:SIMPLE)",
|
|
|
+ proxyUser.getUserName(),
|
|
|
+ loginUser.getUserName())));
|
|
|
+ // Real user is added to the caller context.
|
|
|
+ assertTrue("The audit log should contain the real user.",
|
|
|
+ logOutput.contains(String.format("realUser:%s", realUser.getUserName())));
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testSetBalancerBandwidth() throws Exception {
|
|
|
long defaultBandwidth =
|