ferdelyi commented on code in PR #5638: URL: https://github.com/apache/hadoop/pull/5638#discussion_r1193989267
########## hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/curator/TestSecureZKCuratorManager.java: ########## @@ -0,0 +1,157 @@ +/** + * 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 + * + * 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. + */ +package org.apache.hadoop.util.curator; + +import org.apache.curator.test.InstanceSpec; +import org.apache.curator.test.TestingServer; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.CommonConfigurationKeys; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.client.ZKClientConfig; +import org.apache.zookeeper.common.ClientX509Util; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import static org.apache.hadoop.fs.FileContext.LOG; +import static org.junit.Assert.assertEquals; + + +/** + * Test the manager for ZooKeeper Curator when SSL/TLS is enabled for the ZK server-client connection. + */ +public class TestSecureZKCuratorManager { + + private TestingServer server; + private ZKCuratorManager curator; + private Configuration hadoopConf; + private Integer secureClientPort = 2281; + private File zkDataDir = new File("testZkSSLClientConnectionDataDir"); + + @Before + public void setup() throws Exception { + //set zkServer + this.hadoopConf = setUpSecure(); + Map<String, Object> customConfiguration = new HashMap<>(); + customConfiguration.put("secureClientPort",this.secureClientPort.toString()); + customConfiguration.put("audit.enable",true); + + InstanceSpec spec = new InstanceSpec( + this.zkDataDir, + this.secureClientPort, + -1, + -1, + true, + 1, + 100, + 10, + customConfiguration); + this.server = new TestingServer(spec, true); + hadoopConf.set(CommonConfigurationKeys.ZK_ADDRESS, this.server.getConnectString()); + this.curator = new ZKCuratorManager(hadoopConf); + this.curator.start(new ArrayList<>(), true); + } + + public Configuration setUpSecure() throws Exception { + Configuration hadoopConf = new Configuration(); + String testDataPath = "src/test/java/org/apache/hadoop/util/curator/resources/data"; + System.setProperty("zookeeper.serverCnxnFactory", "org.apache.zookeeper.server.NettyServerCnxnFactory"); + //System.setProperty("zookeeper.client.secure", "true"); + + + System.setProperty("zookeeper.ssl.keyStore.location", testDataPath + "/ssl/keystore.jks"); + System.setProperty("zookeeper.ssl.keyStore.password", "password"); + System.setProperty("zookeeper.ssl.trustStore.location", testDataPath + "/ssl/truststore.jks"); + System.setProperty("zookeeper.ssl.trustStore.password", "password"); + System.setProperty("zookeeper.request.timeout", "12345"); + + System.setProperty("jute.maxbuffer", "469296129"); + + System.setProperty("javax.net.debug", "ssl"); + System.setProperty("zookeeper.authProvider.x509", "org.apache.zookeeper.server.auth.X509AuthenticationProvider"); + + + hadoopConf.set(CommonConfigurationKeys.ZK_SSL_KEYSTORE_LOCATION, testDataPath + "/ssl/keystore.jks"); + hadoopConf.set(CommonConfigurationKeys.ZK_SSL_KEYSTORE_PASSWORD, "password"); + hadoopConf.set(CommonConfigurationKeys.ZK_SSL_TRUSTSTORE_LOCATION, testDataPath + "/ssl/truststore.jks"); + hadoopConf.set(CommonConfigurationKeys.ZK_SSL_TRUSTSTORE_PASSWORD, "password"); + return hadoopConf; + } + + @After + public void teardown() throws Exception { + this.curator.close(); + if (this.server != null) { + this.server.close(); + this.server = null; + } + } + + @Test + public void testSecureZKConfiguration() throws Exception { + LOG.info("Entered to the testSecureZKConfiguration test case."); + // Validate that HadoopZooKeeperFactory will set ZKConfig with given principals + ZKCuratorManager.HadoopZookeeperFactory factory1 = + new ZKCuratorManager.HadoopZookeeperFactory( + null, + null, + null, + true, + this.hadoopConf.get(CommonConfigurationKeys.ZK_SSL_KEYSTORE_LOCATION), + this.hadoopConf.get(CommonConfigurationKeys.ZK_SSL_KEYSTORE_PASSWORD), + this.hadoopConf.get(CommonConfigurationKeys.ZK_SSL_TRUSTSTORE_LOCATION), + this.hadoopConf.get(CommonConfigurationKeys.ZK_SSL_TRUSTSTORE_PASSWORD)); + ZooKeeper zk1 = factory1.newZooKeeper(this.server.getConnectString(), 1000, null, false); + validateSSLConfiguration( + this.hadoopConf.get(CommonConfigurationKeys.ZK_SSL_KEYSTORE_LOCATION), + this.hadoopConf.get(CommonConfigurationKeys.ZK_SSL_KEYSTORE_PASSWORD), + this.hadoopConf.get(CommonConfigurationKeys.ZK_SSL_TRUSTSTORE_LOCATION), + this.hadoopConf.get(CommonConfigurationKeys.ZK_SSL_TRUSTSTORE_PASSWORD), + zk1); + } + + private void validateSSLConfiguration( + String keystoreLocation, + String keystorePassword, + String truststoreLocation, + String truststorePassword, + ZooKeeper zk){ + ClientX509Util x509Util = new ClientX509Util(); Review Comment: Fixed it, thanks! -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
