nick-boss-tech commented on code in PR #5329:
URL: https://github.com/apache/solr/pull/5329#discussion_r4638912646


##########
solr/core/src/java/org/apache/solr/util/configuration/ZookeeperSSLConfigurations.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.solr.util.configuration;
+
+import java.security.KeyStore;
+import java.util.Properties;
+import org.apache.solr.client.solrj.impl.SolrHttpConstants;
+import org.apache.solr.common.util.EnvUtils;
+import org.apache.zookeeper.ClientCnxnSocketNetty;
+import org.apache.zookeeper.client.ZKClientConfig;
+import org.apache.zookeeper.server.NettyServerCnxnFactory;
+
+/** Derives ZooKeeper TLS defaults from Solr SSL settings, preserving 
ZooKeeper overrides. */
+public final class ZookeeperSSLConfigurations {
+  private ZookeeperSSLConfigurations() {}
+
+  /**
+   * Configures an embedded server's TLS listener without changing its 
configuration file. Unless
+   * {@code secureClientPort} is already set, the plaintext {@code clientPort} 
becomes the secure
+   * one.
+   */
+  public static void configureServer(Properties props) {
+    String clientPort = props.getProperty("clientPort");
+    if (props.getProperty("secureClientPort") == null && clientPort != null) {
+      props.setProperty("secureClientPort", clientPort);
+      props.remove("clientPort");
+      props.remove("clientPortAddress");
+    }
+    setDefault(props, "serverCnxnFactory", 
NettyServerCnxnFactory.class.getName());

Review Comment:
   🤖 *AI text below* 🤖
   
   An explicit NIO factory is left in place when an existing listener is 
converted to TLS, but ZooKeeper’s NIO factory cannot open a secure listener. 
Could startup reject incompatible explicit server or client transport settings 
with a message that tells operators what to change?



##########
solr/core/src/java/org/apache/solr/cli/RunExampleTool.java:
##########
@@ -680,15 +681,7 @@ void runSecureExample(CloudExampleParams params, boolean 
userManaged) throws Exc
         "Generated password: "
             + password
             + " (used for the keystore and all basic-auth/ZooKeeper 
demonstration accounts below).");
-    echo("ZooKeeper is protected by digest ACLs; its transport remains 
plaintext on loopback.");
-    if (!params.noPrompt()) {

Review Comment:
   🤖 *AI text below* 🤖
   
   Dropping this prompt makes an interactive `secure` run delete the selected 
Solr home immediately, including an existing home passed with `--solr-home`. 
Can the prompt stay unless the caller passes `--no-prompt`?



##########
solr/core/src/java/org/apache/solr/util/configuration/ZookeeperSSLConfigurations.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.solr.util.configuration;
+
+import java.security.KeyStore;
+import java.util.Properties;
+import org.apache.solr.client.solrj.impl.SolrHttpConstants;
+import org.apache.solr.common.util.EnvUtils;
+import org.apache.zookeeper.ClientCnxnSocketNetty;
+import org.apache.zookeeper.client.ZKClientConfig;
+import org.apache.zookeeper.server.NettyServerCnxnFactory;
+
+/** Derives ZooKeeper TLS defaults from Solr SSL settings, preserving 
ZooKeeper overrides. */
+public final class ZookeeperSSLConfigurations {
+  private ZookeeperSSLConfigurations() {}
+
+  /**
+   * Configures an embedded server's TLS listener without changing its 
configuration file. Unless
+   * {@code secureClientPort} is already set, the plaintext {@code clientPort} 
becomes the secure
+   * one.
+   */
+  public static void configureServer(Properties props) {
+    String clientPort = props.getProperty("clientPort");
+    if (props.getProperty("secureClientPort") == null && clientPort != null) {
+      props.setProperty("secureClientPort", clientPort);
+      props.remove("clientPort");
+      props.remove("clientPortAddress");
+    }
+    setDefault(props, "serverCnxnFactory", 
NettyServerCnxnFactory.class.getName());
+    SSLConfigurations ssl = SSLConfigurationsFactory.current();
+    configureStore(
+        props,
+        "keyStore",
+        EnvUtils.getProperty("solr.jetty.keystore", 
"./etc/solr-ssl.keystore.jks"),
+        EnvUtils.getProperty("solr.jetty.keystore.type", "PKCS12"),
+        ssl.getKeyStorePassword());
+    boolean useSolrTrustStore =
+        configureStore(
+            props,
+            "trustStore",
+            EnvUtils.getProperty("solr.jetty.truststore", 
"./etc/solr-ssl.keystore.jks"),
+            EnvUtils.getProperty("solr.jetty.truststore.type", "PKCS12"),
+            ssl.getTrustStorePassword());
+    configureContextSupplier(props, useSolrTrustStore);
+    setDefault(props, "ssl.clientAuth", "none");

Review Comment:
   🤖 *AI text below* 🤖
   
   ZooKeeper requires a client certificate when `ssl.clientAuth` is unset. This 
default also applies to listeners already configured in `zoo.cfg`, so upgrading 
can change their authentication policy. Could `none` apply only to the listener 
Solr creates automatically?



##########
solr/core/src/java/org/apache/solr/cloud/SolrZkServer.java:
##########
@@ -79,7 +82,7 @@ public String getClientString() {
       return null;
     }
 
-    InetSocketAddress addr = zkProps.getClientPortAddress();
+    InetSocketAddress addr = getClientAddress();

Review Comment:
   🤖 *AI text below* 🤖
   
   The embedded connect string still uses the numeric bind address by default. 
With TLS now on, a certificate valid for the configured DNS name can fail the 
local ZooKeeper connection without an IP SAN. Could the client use a 
certificate-compatible name independently of the bind address?



##########
solr/core/src/java/org/apache/solr/cloud/SolrZkServer.java:
##########
@@ -117,12 +135,19 @@ public void parseConfig() {
     try {
       props = SolrZkServerProps.getProperties(zooCfgPath);
       SolrZkServerProps.injectServers(props, zkRun, zkHost);
+      if (props.getProperty("clientPort") == null
+          && props.getProperty("secureClientPort") == null) {
+        props.setProperty("clientPort", Integer.toString(solrPort + 1000));
+      }
+      if (zkRun && isHttpsEnabled()) {
+        ZookeeperSSLConfigurations.configureServer(props);
+      }
       // This is the address that the embedded Zookeeper will bind to. Like 
Solr, it defaults to
       // "127.0.0.1".
-      props.setProperty(
-          "clientPortAddress", 
EnvUtils.getProperty("solr.zookeeper.embedded.host", "127.0.0.1"));
-      if (props.getProperty("clientPort") == null) {
-        props.setProperty("clientPort", Integer.toString(solrPort + 1000));
+      String bindHost = EnvUtils.getProperty("solr.zookeeper.embedded.host", 
"127.0.0.1");
+      if (props.containsKey("clientPort")) 
props.setProperty("clientPortAddress", bindHost);
+      if (props.containsKey("secureClientPort")) {
+        props.setProperty("secureClientPortAddress", bindHost);

Review Comment:
   🤖 *AI text below* 🤖
   
   This overwrites `secureClientPortAddress` even when the value was explicitly 
set in `zoo.cfg`. An existing secure listener can move to loopback on upgrade 
and lose its joining nodes. Could the Solr bind address be a fallback for an 
already-configured secure listener?



##########
solr/core/src/java/org/apache/solr/core/ZkContainer.java:
##########
@@ -101,12 +103,18 @@ public void initZooKeeper(final CoreContainer cc, 
CloudConfig config) {
               zkConfHome,
               config.getSolrHostPort());
       zkServer.parseConfig();
+      if (zkServer.isClientSecure()) {
+        System.setProperty(ZKClientConfig.SECURE_CLIENT, "true");
+      }
+      SSLConfigurationsFactory.current().initZooKeeper();

Review Comment:
   🤖 *AI text below* 🤖
   
   ZooKeeper publishes parsed server SSL settings as `zookeeper.*` system 
properties before client initialization. The client then treats those server 
values as explicit overrides, which can discard the separate outbound store 
settings. Could the server and client defaults stay separate while preserving 
intentional ZooKeeper overrides?



##########
solr/core/src/java/org/apache/solr/handler/admin/ZookeeperStatusHandler.java:
##########
@@ -333,23 +354,60 @@ protected List<String> getZkRawResponse(String 
zkHostPort, String fourLetterWord
       port = Integer.parseInt(hostPort[1]);
     }
 
-    try (Socket socket = new Socket(host, port);
-        Writer writer = new OutputStreamWriter(socket.getOutputStream(), 
StandardCharsets.UTF_8);
-        PrintWriter out = new PrintWriter(writer, true);
-        BufferedReader in =
-            new BufferedReader(
-                new InputStreamReader(socket.getInputStream(), 
StandardCharsets.UTF_8))) {
-      out.print(fourLetterWordCommand);
-      out.flush();
-      List<String> response = in.lines().collect(Collectors.toList());
-      log.debug("Got response from ZK on host {} and port {}: {}", host, port, 
response);
-      return response;
+    boolean zkClientSecure = 
EnvUtils.getPropertyAsBool(ZKClientConfig.SECURE_CLIENT, false);

Review Comment:
   🤖 *AI text below* 🤖
   
   The status handler can take its addresses from ZooKeeper’s dynamic ensemble 
metadata. In a dual-port ensemble that metadata can advertise the plain client 
port, so the probe can report a healthy TLS ensemble as down. Could TLS probes 
use the secure connect string when the metadata does not identify secure ports?



##########
solr/solr-ref-guide/modules/getting-started/pages/tutorial-securing-solr.adoc:
##########
@@ -392,7 +428,7 @@ keytool -importcert -noprompt -alias unrelated -storetype 
PKCS12 \
 bin/solr stop -p 8984
 SOLR_SSL_CLIENT_TRUST_STORE="$TUTORIAL_HOME/tls/untrusted-truststore.p12" \
 SOLR_LOGS_DIR="$TUTORIAL_HOME/node2/logs" \
-  bin/solr start -p 8984 --solr-home "$TUTORIAL_HOME/node2/solr" -z 
localhost:9983
+  bin/solr start -p 8984 --solr-home "$TUTORIAL_HOME/node2/solr" -z 
localhost:9983/solr

Review Comment:
   🤖 *AI text below* 🤖
   
   This step replaces node 2’s outbound trust before it joins the TLS-only 
ZooKeeper, so the node can fail startup before the distributed HTTPS query. 
Could the tutorial leave ZooKeeper trust intact for this check, or show the 
ZooKeeper startup failure as the expected result?



##########
solr/core/src/java/org/apache/solr/util/configuration/ZookeeperSSLConfigurations.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.solr.util.configuration;
+
+import java.security.KeyStore;
+import java.util.Properties;
+import org.apache.solr.client.solrj.impl.SolrHttpConstants;
+import org.apache.solr.common.util.EnvUtils;
+import org.apache.zookeeper.ClientCnxnSocketNetty;
+import org.apache.zookeeper.client.ZKClientConfig;
+import org.apache.zookeeper.server.NettyServerCnxnFactory;
+
+/** Derives ZooKeeper TLS defaults from Solr SSL settings, preserving 
ZooKeeper overrides. */
+public final class ZookeeperSSLConfigurations {
+  private ZookeeperSSLConfigurations() {}
+
+  /**
+   * Configures an embedded server's TLS listener without changing its 
configuration file. Unless
+   * {@code secureClientPort} is already set, the plaintext {@code clientPort} 
becomes the secure
+   * one.
+   */
+  public static void configureServer(Properties props) {
+    String clientPort = props.getProperty("clientPort");
+    if (props.getProperty("secureClientPort") == null && clientPort != null) {
+      props.setProperty("secureClientPort", clientPort);
+      props.remove("clientPort");
+      props.remove("clientPortAddress");
+    }
+    setDefault(props, "serverCnxnFactory", 
NettyServerCnxnFactory.class.getName());
+    SSLConfigurations ssl = SSLConfigurationsFactory.current();
+    configureStore(
+        props,
+        "keyStore",
+        EnvUtils.getProperty("solr.jetty.keystore", 
"./etc/solr-ssl.keystore.jks"),
+        EnvUtils.getProperty("solr.jetty.keystore.type", "PKCS12"),
+        ssl.getKeyStorePassword());
+    boolean useSolrTrustStore =
+        configureStore(
+            props,
+            "trustStore",
+            EnvUtils.getProperty("solr.jetty.truststore", 
"./etc/solr-ssl.keystore.jks"),
+            EnvUtils.getProperty("solr.jetty.truststore.type", "PKCS12"),
+            ssl.getTrustStorePassword());

Review Comment:
   🤖 *AI text below* 🤖
   
   Jetty decodes obfuscated passwords supplied by its credential provider, but 
ZooKeeper receives the derived value verbatim here. Could inherited Jetty 
values be normalized before opening the ZooKeeper stores, without changing 
explicitly supplied ZooKeeper passwords?



##########
solr/core/src/java/org/apache/solr/util/configuration/ZookeeperSSLContextSupplier.java:
##########
@@ -0,0 +1,206 @@
+/*
+ * 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.solr.util.configuration;
+
+import java.io.IOException;
+import java.net.Socket;
+import java.security.GeneralSecurityException;
+import java.security.KeyStore;
+import java.security.Security;
+import java.security.cert.CertPathValidator;
+import java.security.cert.CertificateException;
+import java.security.cert.PKIXBuilderParameters;
+import java.security.cert.PKIXRevocationChecker;
+import java.security.cert.X509CertSelector;
+import java.security.cert.X509Certificate;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.function.Supplier;
+import javax.net.ssl.CertPathTrustManagerParameters;
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.SSLSocket;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
+import javax.net.ssl.X509ExtendedTrustManager;
+import org.apache.zookeeper.common.ClientX509Util;
+import org.apache.zookeeper.common.X509Exception;
+import org.apache.zookeeper.common.X509Util;
+import org.apache.zookeeper.common.ZKConfig;
+
+/** Supplies ZooKeeper TLS contexts using Solr-compatible trust material. */
+public class ZookeeperSSLContextSupplier implements Supplier<SSLContext> {
+  @Override
+  public SSLContext get() {
+    try (ClientX509Util x509 = new ClientX509Util()) {
+      ZKConfig config = new ZKConfig();
+      KeyManager[] keys = null;
+      String location = 
config.getProperty(x509.getSslKeystoreLocationProperty(), "");
+      if (!location.isEmpty()) {
+        keys =
+            new KeyManager[] {
+              X509Util.createKeyManager(
+                  location,
+                  x509.getPasswordFromConfigPropertyOrFile(
+                      config,
+                      x509.getSslKeystorePasswdProperty(),
+                      x509.getSslKeystorePasswdPathProperty()),
+                  config.getProperty(x509.getSslKeystoreTypeProperty()))
+            };
+      }
+      SSLContext context =
+          SSLContext.getInstance(
+              config.getProperty(
+                  x509.getSslProtocolProperty(), 
X509Util.defaultTlsProtocol(config)));
+      context.init(keys, new TrustManager[] {trustManager(x509, config)}, 
null);
+      return context;
+    } catch (IOException | GeneralSecurityException | X509Exception e) {
+      throw new IllegalStateException("Could not create ZooKeeper SSL 
context", e);
+    }
+  }
+
+  private static X509ExtendedTrustManager trustManager(ClientX509Util x509, 
ZKConfig config)
+      throws IOException, GeneralSecurityException {
+    KeyStore store = null;
+    String location = 
config.getProperty(x509.getSslTruststoreLocationProperty(), "");
+    if (!location.isEmpty()) {
+      store =
+          X509Util.loadTrustStore(
+              location,
+              x509.getPasswordFromConfigPropertyOrFile(
+                  config,
+                  x509.getSslTruststorePasswdProperty(),
+                  x509.getSslTruststorePasswdPathProperty()),
+              config.getProperty(x509.getSslTruststoreTypeProperty()));
+    }
+    TrustManagerFactory factory = TrustManagerFactory.getInstance("PKIX");
+    boolean crl = config.getBoolean(x509.getSslCrlEnabledProperty());
+    boolean ocsp = config.getBoolean(x509.getSslOcspEnabledProperty());
+    if (store != null && (crl || ocsp)) {
+      KeyStore certificates = KeyStore.getInstance(KeyStore.getDefaultType());
+      certificates.load(null, null);
+      for (String alias : Collections.list(store.aliases())) {
+        var certificate = store.getCertificate(alias);
+        if (certificate != null) certificates.setCertificateEntry(alias, 
certificate);

Review Comment:
   🤖 *AI text below* 🤖
   
   This copies certificates from key entries into the trust-anchor set, which 
differs from ZooKeeper’s normal PKIX setup. Could the new path preserve the 
same trust anchors and add a test that verifies revocation is enforced, not 
just that a handshake succeeds?



##########
solr/core/src/java/org/apache/solr/cli/SolrCLI.java:
##########
@@ -270,7 +272,7 @@ public static int parseWithCommonsCli(String[] args) throws 
Exception {
         args = trimmedArgs;
       }
     }
-    SSLConfigurationsFactory.current().init();
+    SSLConfigurationsFactory.current().initZooKeeper();

Review Comment:
   🤖 *AI text below* 🤖
   
   ZooKeeper’s store paths are initialized before the CLI parses arguments 
here. If the effective SSL settings use relative store paths (for example, a 
path under `etc/`), ZooKeeper can resolve them against the process working 
directory instead of the Solr home or path the CLI is about to establish. Could 
the entry points resolve the store paths before this initialization?



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

Reply via email to