-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HDFS-16591. Setup JaasConfiguration in ZKCuratorManager when SASL is … #4447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /** | ||
| * Licensed 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 | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * 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. See accompanying LICENSE file. | ||
| */ | ||
| package org.apache.hadoop.security.authentication.util; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import javax.security.auth.login.AppConfigurationEntry; | ||
| import javax.security.auth.login.Configuration; | ||
|
|
||
|
|
||
| /** | ||
| * Creates a programmatic version of a jaas.conf file. This can be used | ||
| * instead of writing a jaas.conf file and setting the system property, | ||
| * "java.security.auth.login.config", to point to that file. It is meant to be | ||
| * used for connecting to ZooKeeper. | ||
| */ | ||
| public class JaasConfiguration extends Configuration { | ||
|
|
||
| private final javax.security.auth.login.Configuration baseConfig = | ||
| javax.security.auth.login.Configuration.getConfiguration(); | ||
| private static AppConfigurationEntry[] entry; | ||
|
||
| private final String entryName; | ||
|
|
||
| /** | ||
| * Add an entry to the jaas configuration with the passed in name, | ||
| * principal, and keytab. The other necessary options will be set for you. | ||
| * | ||
| * @param entryName The name of the entry (e.g. "Client") | ||
| * @param principal The principal of the user | ||
| * @param keytab The location of the keytab | ||
| */ | ||
| public JaasConfiguration(String entryName, String principal, String keytab) { | ||
| this.entryName = entryName; | ||
| Map<String, String> options = new HashMap<>(); | ||
| options.put("keyTab", keytab); | ||
| options.put("principal", principal); | ||
| options.put("useKeyTab", "true"); | ||
| options.put("storeKey", "true"); | ||
| options.put("useTicketCache", "false"); | ||
| options.put("refreshKrb5Config", "true"); | ||
| String jaasEnvVar = System.getenv("HADOOP_JAAS_DEBUG"); | ||
| if ("true".equalsIgnoreCase(jaasEnvVar)) { | ||
| options.put("debug", "true"); | ||
| } | ||
| entry = new AppConfigurationEntry[]{ | ||
| new AppConfigurationEntry(getKrb5LoginModuleName(), | ||
| AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, | ||
| options)}; | ||
| } | ||
|
|
||
| @Override | ||
| public AppConfigurationEntry[] getAppConfigurationEntry(String name) { | ||
| return (entryName.equals(name)) ? entry : ((baseConfig != null) | ||
| ? baseConfig.getAppConfigurationEntry(name) : null); | ||
| } | ||
|
|
||
| private String getKrb5LoginModuleName() { | ||
| String krb5LoginModuleName; | ||
| if (System.getProperty("java.vendor").contains("IBM")) { | ||
| krb5LoginModuleName = "com.ibm.security.auth.module.Krb5LoginModule"; | ||
| } else { | ||
| krb5LoginModuleName = "com.sun.security.auth.module.Krb5LoginModule"; | ||
| } | ||
| return krb5LoginModuleName; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,7 @@ | |
| import org.apache.hadoop.classification.InterfaceStability.Unstable; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are unused imports between line 28 and 34.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. I've removed these and other unused imports in RegistrySecurity |
||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.security.SecurityUtil; | ||
| import org.apache.hadoop.security.authentication.util.JaasConfiguration; | ||
| import org.apache.hadoop.security.token.Token; | ||
| import org.apache.hadoop.security.token.delegation.web.DelegationTokenManager; | ||
| import static org.apache.hadoop.util.Time.now; | ||
|
|
@@ -251,68 +252,6 @@ private String setJaasConfiguration(Configuration config) throws Exception { | |
| return principal.split("[/@]")[0]; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a programmatic version of a jaas.conf file. This can be used | ||
| * instead of writing a jaas.conf file and setting the system property, | ||
| * "java.security.auth.login.config", to point to that file. It is meant to be | ||
| * used for connecting to ZooKeeper. | ||
| */ | ||
| @InterfaceAudience.Private | ||
| public static class JaasConfiguration extends | ||
| javax.security.auth.login.Configuration { | ||
|
|
||
| private final javax.security.auth.login.Configuration baseConfig = | ||
| javax.security.auth.login.Configuration.getConfiguration(); | ||
| private static AppConfigurationEntry[] entry; | ||
| private String entryName; | ||
|
|
||
| /** | ||
| * Add an entry to the jaas configuration with the passed in name, | ||
| * principal, and keytab. The other necessary options will be set for you. | ||
| * | ||
| * @param entryName | ||
| * The name of the entry (e.g. "Client") | ||
| * @param principal | ||
| * The principal of the user | ||
| * @param keytab | ||
| * The location of the keytab | ||
| */ | ||
| public JaasConfiguration(String entryName, String principal, String keytab) { | ||
| this.entryName = entryName; | ||
| Map<String, String> options = new HashMap<String, String>(); | ||
| options.put("keyTab", keytab); | ||
| options.put("principal", principal); | ||
| options.put("useKeyTab", "true"); | ||
| options.put("storeKey", "true"); | ||
| options.put("useTicketCache", "false"); | ||
| options.put("refreshKrb5Config", "true"); | ||
| String jaasEnvVar = System.getenv("HADOOP_JAAS_DEBUG"); | ||
| if (jaasEnvVar != null && "true".equalsIgnoreCase(jaasEnvVar)) { | ||
| options.put("debug", "true"); | ||
| } | ||
| entry = new AppConfigurationEntry[] { | ||
| new AppConfigurationEntry(getKrb5LoginModuleName(), | ||
| AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, | ||
| options) }; | ||
| } | ||
|
|
||
| @Override | ||
| public AppConfigurationEntry[] getAppConfigurationEntry(String name) { | ||
| return (entryName.equals(name)) ? entry : ((baseConfig != null) | ||
| ? baseConfig.getAppConfigurationEntry(name) : null); | ||
| } | ||
|
|
||
| private String getKrb5LoginModuleName() { | ||
| String krb5LoginModuleName; | ||
| if (System.getProperty("java.vendor").contains("IBM")) { | ||
| krb5LoginModuleName = "com.ibm.security.auth.module.Krb5LoginModule"; | ||
| } else { | ||
| krb5LoginModuleName = "com.sun.security.auth.module.Krb5LoginModule"; | ||
| } | ||
| return krb5LoginModuleName; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void startThreads() throws IOException { | ||
| if (!isExternalClient) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this non-static?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why it's been declared static in all the duplicate classes, but I agree it should be non-static