Skip to content

Commit

Permalink
[FLINK-6117] [security] Make setting of 'zookeeper.sasl.disable' work…
Browse files Browse the repository at this point in the history
… correctly

This closes apache#3600
  • Loading branch information
zcbAzfl authored and StephanEwen committed Apr 21, 2017
1 parent daf4038 commit eef85e0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public class SecurityOptions {
// ZooKeeper Security Options
// ------------------------------------------------------------------------

public static final ConfigOption<Boolean> ZOOKEEPER_SASL_DISABLE =
key("zookeeper.sasl.disable")
.defaultValue(false);

public static final ConfigOption<String> ZOOKEEPER_SASL_SERVICE_NAME =
key("zookeeper.sasl.service-name")
.defaultValue("zookeeper");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ public static class SecurityConfiguration {

private final org.apache.hadoop.conf.Configuration hadoopConf;

private final boolean isZkSaslDisable;

private final boolean useTicketCache;

private final String keytab;
Expand Down Expand Up @@ -164,6 +166,7 @@ public SecurityConfiguration(Configuration flinkConf,
org.apache.hadoop.conf.Configuration hadoopConf,
List<? extends Class<? extends SecurityModule>> securityModules) {
this.hadoopConf = checkNotNull(hadoopConf);
this.isZkSaslDisable = flinkConf.getBoolean(SecurityOptions.ZOOKEEPER_SASL_DISABLE);
this.keytab = flinkConf.getString(SecurityOptions.KERBEROS_LOGIN_KEYTAB);
this.principal = flinkConf.getString(SecurityOptions.KERBEROS_LOGIN_PRINCIPAL);
this.useTicketCache = flinkConf.getBoolean(SecurityOptions.KERBEROS_LOGIN_USETICKETCACHE);
Expand All @@ -175,6 +178,10 @@ public SecurityConfiguration(Configuration flinkConf,
validate();
}

public boolean isZkSaslDisable() {
return isZkSaslDisable;
}

public String getKeytab() {
return keytab;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,18 @@ public class ZooKeeperModule implements SecurityModule {
*/
private static final String ZK_LOGIN_CONTEXT_NAME = "zookeeper.sasl.clientconfig";

private String priorSaslEnable;

private String priorServiceName;

private String priorLoginContextName;

@Override
public void install(SecurityUtils.SecurityConfiguration configuration) throws SecurityInstallException {

priorSaslEnable = System.getProperty(ZK_ENABLE_CLIENT_SASL, null);
System.setProperty(ZK_ENABLE_CLIENT_SASL, String.valueOf(!configuration.isZkSaslDisable()));

priorServiceName = System.getProperty(ZK_SASL_CLIENT_USERNAME, null);
if (!"zookeeper".equals(configuration.getZooKeeperServiceName())) {
System.setProperty(ZK_SASL_CLIENT_USERNAME, configuration.getZooKeeperServiceName());
Expand All @@ -61,6 +66,11 @@ public void install(SecurityUtils.SecurityConfiguration configuration) throws Se

@Override
public void uninstall() throws SecurityInstallException {
if(priorSaslEnable != null) {
System.setProperty(ZK_ENABLE_CLIENT_SASL, priorSaslEnable);
} else {
System.clearProperty(ZK_ENABLE_CLIENT_SASL);
}
if(priorServiceName != null) {
System.setProperty(ZK_SASL_CLIENT_USERNAME, priorServiceName);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public static void prepare(TemporaryFolder tempFolder) {
//ctx.setHadoopConfiguration() for the UGI implementation to work properly.
//See Yarn test case module for reference
Configuration flinkConfig = GlobalConfiguration.loadConfiguration();
flinkConfig.setBoolean(SecurityOptions.ZOOKEEPER_SASL_DISABLE, false);
flinkConfig.setString(SecurityOptions.KERBEROS_LOGIN_KEYTAB, testKeytab);
flinkConfig.setBoolean(SecurityOptions.KERBEROS_LOGIN_USETICKETCACHE, false);
flinkConfig.setString(SecurityOptions.KERBEROS_LOGIN_PRINCIPAL, testPrincipal);
Expand Down

0 comments on commit eef85e0

Please sign in to comment.