mcvsubbu commented on a change in pull request #6418:
URL: https://github.com/apache/incubator-pinot/pull/6418#discussion_r557669864



##########
File path: pinot-core/src/main/java/org/apache/pinot/core/util/TlsUtils.java
##########
@@ -0,0 +1,258 @@
+/**
+ * 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.pinot.core.util;
+
+import com.google.common.base.Preconditions;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.UnknownHostException;
+import java.security.GeneralSecurityException;
+import java.security.KeyStore;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
+import org.apache.commons.httpclient.ConnectTimeoutException;
+import org.apache.commons.httpclient.params.HttpConnectionParams;
+import org.apache.commons.httpclient.protocol.Protocol;
+import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
+import org.apache.pinot.common.utils.CommonConstants;
+import org.apache.pinot.core.transport.TlsConfig;
+import org.apache.pinot.spi.env.PinotConfiguration;
+
+
+/**
+ * Utility class for shared TLS configuration logic
+ */
+public final class TlsUtils {
+  private static final String ENABLED = "enabled";
+  private static final String CLIENT_AUTH_ENABLED = "client.auth.enabled";
+  private static final String KEYSTORE_PATH = "keystore.path";
+  private static final String KEYSTORE_PASSWORD = "keystore.password";
+  private static final String TRUSTSTORE_PATH = "truststore.path";
+  private static final String TRUSTSTORE_PASSWORD = "truststore.password";
+
+  private TlsUtils() {
+    // left blank
+  }
+
+  /**
+   * Extract a TlsConfig instance from a namespaced set of configuration key, 
with optional defaults.
+   *
+   * @param pinotConfig pinot configuration
+   * @param namespace namespace prefix
+   *
+   * @return TlsConfig instance
+   */
+  public static TlsConfig extractTlsConfig(TlsConfig tlsDefaults, 
PinotConfiguration pinotConfig, String namespace) {
+    TlsConfig tlsConfig = new TlsConfig();
+    tlsConfig.setEnabled(tlsDefaults.isEnabled());
+    tlsConfig.setClientAuthEnabled(tlsDefaults.isClientAuthEnabled());
+    tlsConfig.setKeyStorePath(tlsDefaults.getKeyStorePath());
+    tlsConfig.setKeyStorePassword(tlsDefaults.getKeyStorePassword());
+    tlsConfig.setTrustStorePath(tlsDefaults.getTrustStorePath());
+    tlsConfig.setTrustStorePassword(tlsDefaults.getTrustStorePassword());
+
+    if (pinotConfig.containsKey(key(namespace, ENABLED))) {
+      tlsConfig.setEnabled(pinotConfig.getProperty(key(namespace, ENABLED), 
false));

Review comment:
       if pinotConfig contains the key, then we don't need to call the API with 
default of false, right? We can just set it to whatever is in pinotconfig. Or, 
are you considering some erroneous configuration there?

##########
File path: 
pinot-broker/src/main/java/org/apache/pinot/broker/broker/helix/HelixBrokerStarter.java
##########
@@ -117,13 +124,18 @@ public HelixBrokerStarter(PinotConfiguration brokerConf, 
String clusterName, Str
       brokerHost = 
_brokerConf.getProperty(CommonConstants.Helix.SET_INSTANCE_ID_TO_HOSTNAME_KEY, 
false) ? NetUtil
           .getHostnameOrAddress() : NetUtil.getHostAddress();
     }
+
     _brokerId = _brokerConf.getProperty(Helix.Instance.INSTANCE_ID_KEY,
-        Helix.PREFIX_OF_BROKER_INSTANCE + brokerHost + "_" + _brokerConf
-            .getProperty(Helix.KEY_OF_BROKER_QUERY_PORT, 
Helix.DEFAULT_BROKER_QUERY_PORT));
+        Helix.PREFIX_OF_BROKER_INSTANCE + brokerHost + "_" + inferPort());
 
     _brokerConf.addProperty(Broker.CONFIG_OF_BROKER_ID, _brokerId);
   }
 
+  private int inferPort() {
+    return 
Optional.ofNullable(_brokerConf.getProperty(Helix.KEY_OF_BROKER_QUERY_PORT)).map(Integer::parseInt)

Review comment:
       Not sure how this ensures that if nothing is configured, we still start 
without tls on DEFAULT_BROKER_QUERY_PORT (previous behavior).

##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/transport/ServerRoutingInstance.java
##########
@@ -37,14 +38,20 @@
   private static final String SHORT_REALTIME_SUFFIX = "_R";
   private static final Map<String, String> SHORT_HOSTNAME_MAP = new 
ConcurrentHashMap<>();
 
+  private final boolean _tls;

Review comment:
       rename to `isTlsEnabled`

##########
File path: pinot-core/src/main/java/org/apache/pinot/core/util/TlsUtils.java
##########
@@ -0,0 +1,258 @@
+/**
+ * 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.pinot.core.util;
+
+import com.google.common.base.Preconditions;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.UnknownHostException;
+import java.security.GeneralSecurityException;
+import java.security.KeyStore;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
+import org.apache.commons.httpclient.ConnectTimeoutException;
+import org.apache.commons.httpclient.params.HttpConnectionParams;
+import org.apache.commons.httpclient.protocol.Protocol;
+import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
+import org.apache.pinot.common.utils.CommonConstants;
+import org.apache.pinot.core.transport.TlsConfig;
+import org.apache.pinot.spi.env.PinotConfiguration;
+
+
+/**
+ * Utility class for shared TLS configuration logic
+ */
+public final class TlsUtils {
+  private static final String ENABLED = "enabled";
+  private static final String CLIENT_AUTH_ENABLED = "client.auth.enabled";
+  private static final String KEYSTORE_PATH = "keystore.path";
+  private static final String KEYSTORE_PASSWORD = "keystore.password";
+  private static final String TRUSTSTORE_PATH = "truststore.path";
+  private static final String TRUSTSTORE_PASSWORD = "truststore.password";
+
+  private TlsUtils() {
+    // left blank
+  }
+
+  /**
+   * Extract a TlsConfig instance from a namespaced set of configuration key, 
with optional defaults.
+   *
+   * @param pinotConfig pinot configuration
+   * @param namespace namespace prefix

Review comment:
       Add javadoc for tlsDefaults

##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/transport/QueryRouter.java
##########
@@ -60,20 +84,23 @@ public AsyncQueryResponse submitQuery(long requestId, 
String rawTableName,
       long timeoutMs) {
     assert offlineBrokerRequest != null || realtimeBrokerRequest != null;
 
+    // can prefer but not require TLS until all servers guaranteed to be on TLS

Review comment:
       Not sure I understand completely. If I follow the code, it seems like 
preferTLS == requireTLS. If it errors out, do we try to go with plain? Maybe I 
missed that code?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to