From 95904f6b3ccd1d167088086472eabdd85b2d148d Mon Sep 17 00:00:00 2001 From: Eric Yang Date: Thu, 22 Feb 2018 16:12:40 -0500 Subject: [PATCH] YARN-7942. Add check for JAAS configuration for Yarn Service. Contributed by Billie Rinaldi --- .../client/impl/zk/RegistrySecurity.java | 44 ++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/client/impl/zk/RegistrySecurity.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/client/impl/zk/RegistrySecurity.java index bb829d888bc..5c6c983f5be 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/client/impl/zk/RegistrySecurity.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/client/impl/zk/RegistrySecurity.java @@ -736,8 +736,10 @@ public class RegistrySecurity extends AbstractService { * Apply the security environment to this curator instance. This * may include setting up the ZK system properties for SASL * @param builder curator builder + * @throws IOException if jaas configuration can't be generated or found */ - public void applySecurityEnvironment(CuratorFrameworkFactory.Builder builder) { + public void applySecurityEnvironment(CuratorFrameworkFactory.Builder + builder) throws IOException { if (isSecureRegistry()) { switch (access) { @@ -752,16 +754,36 @@ public class RegistrySecurity extends AbstractService { break; case sasl: - JaasConfiguration jconf = - new JaasConfiguration(jaasClientEntry, principal, keytab); - javax.security.auth.login.Configuration.setConfiguration(jconf); - setSystemPropertyIfUnset(ZooKeeperSaslClient.ENABLE_CLIENT_SASL_KEY, - "true"); - setSystemPropertyIfUnset(ZooKeeperSaslClient.LOGIN_CONTEXT_NAME_KEY, - jaasClientEntry); - LOG.info( - "Enabling ZK sasl client: jaasClientEntry = " + jaasClientEntry - + ", principal = " + principal + ", keytab = " + keytab); + String existingJaasConf = System.getProperty( + "java.security.auth.login.config"); + if (existingJaasConf == null || existingJaasConf.isEmpty()) { + if (principal == null || keytab == null) { + throw new IOException("SASL is configured for registry, " + + "but neither keytab/principal nor java.security.auth.login" + + ".config system property are specified"); + } + // in this case, keytab and principal are specified and no jaas + // config is specified, so we will create one + LOG.info( + "Enabling ZK sasl client: jaasClientEntry = " + jaasClientEntry + + ", principal = " + principal + ", keytab = " + keytab); + JaasConfiguration jconf = + new JaasConfiguration(jaasClientEntry, principal, keytab); + javax.security.auth.login.Configuration.setConfiguration(jconf); + setSystemPropertyIfUnset(ZooKeeperSaslClient.ENABLE_CLIENT_SASL_KEY, + "true"); + setSystemPropertyIfUnset(ZooKeeperSaslClient.LOGIN_CONTEXT_NAME_KEY, + jaasClientEntry); + } else { + // in this case, jaas config is specified so we will not change it + LOG.info("Using existing ZK sasl configuration: " + + "jaasClientEntry = " + System.getProperty( + ZooKeeperSaslClient.LOGIN_CONTEXT_NAME_KEY, "Client") + + ", sasl client = " + System.getProperty( + ZooKeeperSaslClient.ENABLE_CLIENT_SASL_KEY, + ZooKeeperSaslClient.ENABLE_CLIENT_SASL_DEFAULT) + + ", jaas = " + existingJaasConf); + } break; default: