You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by GitBox <gi...@apache.org> on 2022/06/27 09:50:39 UTC

[GitHub] [hadoop] steveloughran commented on a diff in pull request #4354: YARN-6539. Create SecureLogin inside Router.

steveloughran commented on code in PR #4354:
URL: https://github.com/apache/hadoop/pull/4354#discussion_r907191547


##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/security/TestSecureLogin.java:
##########
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership.  The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.hadoop.yarn.server.router.security;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.server.router.Router;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+import org.apache.hadoop.minikdc.MiniKdc;
+import org.junit.Test;
+import org.apache.hadoop.security.authentication.KerberosTestUtils;
+
+import java.io.File;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+public class TestSecureLogin {
+
+  private static final File TEST_ROOT_DIR = new File("target",
+      TestSecureLogin.class.getName() + "-root");
+  private static File routerKeytabFile = new File(
+      KerberosTestUtils.getKeytabFile());
+
+  private static MiniKdc testMiniKDC;
+
+  @BeforeClass
+  public static void setUp() {
+    try {
+      testMiniKDC = new MiniKdc(MiniKdc.createConf(), TEST_ROOT_DIR);
+      testMiniKDC.start();
+      testMiniKDC.createPrincipal(routerKeytabFile, "yarn/localhost");
+    } catch (Exception e) {
+      fail("Couldn't setup MiniKDC");
+    }
+  }
+
+  @Test
+  public void testRouterSecureLogin() {
+    Router router = null;
+    try {
+      Configuration conf = new YarnConfiguration();
+      conf.set(YarnConfiguration.ROUTER_BIND_HOST, "0.0.0.0");
+      conf.set(YarnConfiguration.ROUTER_CLIENTRM_INTERCEPTOR_CLASS_PIPELINE,
+          "org.apache.hadoop.yarn.server.router.clientrm.FederationClientInterceptor");
+      conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION,
+          "kerberos");
+      conf.set("yarn.router.principal", "yarn/localhost@EXAMPLE.COM");
+      conf.set("yarn.router.keytab", routerKeytabFile.getAbsolutePath());
+      assertEquals(AuthenticationMethod.SIMPLE,
+          UserGroupInformation.getLoginUser().getAuthenticationMethod());
+      UserGroupInformation.setConfiguration(conf);
+      router = new Router();
+      router.init(conf);
+      router.start();
+      assertEquals(AuthenticationMethod.KERBEROS,
+          UserGroupInformation.getLoginUser().getAuthenticationMethod());
+      assertEquals("yarn/localhost@EXAMPLE.COM",
+          UserGroupInformation.getLoginUser().getUserName());
+    } catch (Throwable t) {
+      fail("Can't start router!");

Review Comment:
   this will also lose all error messages from any raised assertions. remove the try/catch and just declare the test case as throwing a Throwable



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/security/TestSecureLogin.java:
##########
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership.  The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.hadoop.yarn.server.router.security;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.server.router.Router;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+import org.apache.hadoop.minikdc.MiniKdc;
+import org.junit.Test;
+import org.apache.hadoop.security.authentication.KerberosTestUtils;
+
+import java.io.File;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+public class TestSecureLogin {
+
+  private static final File TEST_ROOT_DIR = new File("target",
+      TestSecureLogin.class.getName() + "-root");
+  private static File routerKeytabFile = new File(
+      KerberosTestUtils.getKeytabFile());
+
+  private static MiniKdc testMiniKDC;
+
+  @BeforeClass
+  public static void setUp() {
+    try {
+      testMiniKDC = new MiniKdc(MiniKdc.createConf(), TEST_ROOT_DIR);
+      testMiniKDC.start();
+      testMiniKDC.createPrincipal(routerKeytabFile, "yarn/localhost");
+    } catch (Exception e) {
+      fail("Couldn't setup MiniKDC");
+    }
+  }
+
+  @Test
+  public void testRouterSecureLogin() {
+    Router router = null;
+    try {
+      Configuration conf = new YarnConfiguration();
+      conf.set(YarnConfiguration.ROUTER_BIND_HOST, "0.0.0.0");
+      conf.set(YarnConfiguration.ROUTER_CLIENTRM_INTERCEPTOR_CLASS_PIPELINE,
+          "org.apache.hadoop.yarn.server.router.clientrm.FederationClientInterceptor");
+      conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION,
+          "kerberos");
+      conf.set("yarn.router.principal", "yarn/localhost@EXAMPLE.COM");
+      conf.set("yarn.router.keytab", routerKeytabFile.getAbsolutePath());
+      assertEquals(AuthenticationMethod.SIMPLE,
+          UserGroupInformation.getLoginUser().getAuthenticationMethod());
+      UserGroupInformation.setConfiguration(conf);
+      router = new Router();
+      router.init(conf);
+      router.start();
+      assertEquals(AuthenticationMethod.KERBEROS,

Review Comment:
   nit: add description of what is being checked.



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/security/TestSecureLogin.java:
##########
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership.  The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.hadoop.yarn.server.router.security;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.server.router.Router;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+import org.apache.hadoop.minikdc.MiniKdc;
+import org.junit.Test;
+import org.apache.hadoop.security.authentication.KerberosTestUtils;
+
+import java.io.File;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+public class TestSecureLogin {
+
+  private static final File TEST_ROOT_DIR = new File("target",
+      TestSecureLogin.class.getName() + "-root");
+  private static File routerKeytabFile = new File(
+      KerberosTestUtils.getKeytabFile());
+
+  private static MiniKdc testMiniKDC;
+
+  @BeforeClass
+  public static void setUp() {
+    try {
+      testMiniKDC = new MiniKdc(MiniKdc.createConf(), TEST_ROOT_DIR);
+      testMiniKDC.start();
+      testMiniKDC.createPrincipal(routerKeytabFile, "yarn/localhost");
+    } catch (Exception e) {

Review Comment:
   remove try/catch. add exception to method signature



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/security/TestSecureLogin.java:
##########
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership.  The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.hadoop.yarn.server.router.security;
+
+import org.apache.hadoop.conf.Configuration;

Review Comment:
   imports aren't following normall hadoop guidelines



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/security/TestSecureLogin.java:
##########
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership.  The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.hadoop.yarn.server.router.security;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.server.router.Router;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+import org.apache.hadoop.minikdc.MiniKdc;
+import org.junit.Test;
+import org.apache.hadoop.security.authentication.KerberosTestUtils;
+
+import java.io.File;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+public class TestSecureLogin {
+
+  private static final File TEST_ROOT_DIR = new File("target",
+      TestSecureLogin.class.getName() + "-root");
+  private static File routerKeytabFile = new File(
+      KerberosTestUtils.getKeytabFile());
+
+  private static MiniKdc testMiniKDC;
+
+  @BeforeClass
+  public static void setUp() {
+    try {
+      testMiniKDC = new MiniKdc(MiniKdc.createConf(), TEST_ROOT_DIR);
+      testMiniKDC.start();
+      testMiniKDC.createPrincipal(routerKeytabFile, "yarn/localhost");
+    } catch (Exception e) {
+      fail("Couldn't setup MiniKDC");
+    }
+  }
+
+  @Test
+  public void testRouterSecureLogin() {
+    Router router = null;
+    try {
+      Configuration conf = new YarnConfiguration();
+      conf.set(YarnConfiguration.ROUTER_BIND_HOST, "0.0.0.0");
+      conf.set(YarnConfiguration.ROUTER_CLIENTRM_INTERCEPTOR_CLASS_PIPELINE,
+          "org.apache.hadoop.yarn.server.router.clientrm.FederationClientInterceptor");
+      conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION,
+          "kerberos");
+      conf.set("yarn.router.principal", "yarn/localhost@EXAMPLE.COM");
+      conf.set("yarn.router.keytab", routerKeytabFile.getAbsolutePath());
+      assertEquals(AuthenticationMethod.SIMPLE,

Review Comment:
   nit: add description of what is being checked.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org