g3rg0 commented on code in PR #532:
URL: https://github.com/apache/tez/pull/532#discussion_r3768999403
##########
tez-api/src/main/java/org/apache/tez/client/registry/zookeeper/ZkConfig.java:
##########
@@ -110,17 +129,82 @@ public int getConnectionTimeoutMs() {
return connectionTimeoutMs;
}
+ public String getZookeeperTrustStorePassword() {
+ return sslTruststorePassword;
+ }
+
+ public String getZookeeperTrustStoreLocation() {
+ return sslTruststoreLocation;
+ }
+
+ public String getZookeeperKeyStorePassword() {
+ return sslKeystorePassword;
+ }
+
+ public String getZookeeperKeyStoreLocation() {
+ return sslKeystoreLocation;
+ }
+
+ /**
+ * Returns whether the zookeeper connection will be secure or insecure.
+ * @return An Optional containing the boolean value that indicates whether
zookeeper client
+ * uses a secure zookeeper connection. An empty Optional indicates that it
is not specified,
+ * and in this case the default settings of zookeeper are used, which can be
controlled by
+ * specific JVM properties.
+ * @see TezConfiguration#TEZ_AM_ZOOKEEPER_SSL_ENABLE
+ */
+ public Optional<Boolean> isSslEnabled() {
+ if (this.sslEnabled == null || this.sslEnabled.isEmpty()) {
+ return Optional.empty();
+ }
+ return Optional.of(Boolean.parseBoolean(sslEnabled));
+ }
+
public RetryPolicy getRetryPolicy() {
return new ExponentialBackoffRetry(getCuratorBackoffSleepMs(),
getCuratorMaxRetries());
}
public CuratorFramework createCuratorFramework() {
- return CuratorFrameworkFactory.newClient(
- getZkQuorum(),
- getSessionTimeoutMs(),
- getConnectionTimeoutMs(),
- getRetryPolicy()
- );
+ if (!isSslEnabled().isPresent()) {
+ return CuratorFrameworkFactory.newClient(
+ getZkQuorum(),
+ getSessionTimeoutMs(),
+ getConnectionTimeoutMs(),
+ getRetryPolicy()
+ );
+ }
+
+ ZKClientConfig zkClientConfig = new ZKClientConfig();
+ zkClientConfig.setProperty(ZKClientConfig.SECURE_CLIENT,
Boolean.toString(isSslEnabled().get()));
+ zkClientConfig.setProperty(ZKClientConfig.ZOOKEEPER_CLIENT_CNXN_SOCKET,
+ "org.apache.zookeeper.ClientCnxnSocketNetty");
+ if (isSslEnabled().get()) {
+ ClientX509Util x509Util = new ClientX509Util();
+ if (StringUtils.isEmpty(getZookeeperKeyStoreLocation())) {
+ LOG.warn("Missing keystoreLocation parameter");
+ }
+ if (StringUtils.isEmpty(getZookeeperTrustStoreLocation())) {
+ LOG.warn("Missing trustStoreLocation parameter");
+ }
+ zkClientConfig.setProperty(x509Util.getSslKeystoreLocationProperty(),
getZookeeperKeyStoreLocation());
Review Comment:
If we throw an exception here, these parameters will become mandatory
instead of optional.
The keystore is only needed if zookeeper is configured for mTLS
authentication, so I think it should remain optional. The truststore, on the
other hand, is also optional, because if the system truststore trusts the
zookeeper TLS cert, then this configuration would be redundant.
How about something like this?
```
if (isSslEnabled().get()) {
try (ClientX509Util x509Util = new ClientX509Util()) {
if (StringUtils.isNotEmpty(getZookeeperKeyStoreLocation())) {
zkClientConfig.setProperty(x509Util.getSslKeystoreLocationProperty(),
getZookeeperKeyStoreLocation());
zkClientConfig.setProperty(x509Util.getSslKeystorePasswdProperty(),
getZookeeperKeyStorePassword());
} else {
LOG.info("No keystore location configured, using ZooKeeper client
defaults");
}
if (StringUtils.isNotEmpty(getZookeeperTrustStoreLocation())) {
zkClientConfig.setProperty(x509Util.getSslTruststoreLocationProperty(),
getZookeeperTrustStoreLocation());
zkClientConfig.setProperty(x509Util.getSslTruststorePasswdProperty(),
getZookeeperTrustStorePassword());
} else {
LOG.info("No truststore location configured, using ZooKeeper
client defaults");
}
}
}
```
--
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]