janhoy commented on code in PR #5329:
URL: https://github.com/apache/solr/pull/5329#discussion_r4580564747


##########
solr/bin/solr:
##########
@@ -1134,6 +1134,57 @@ if [ "${SOLR_MODE:-}" == 'solrcloud' ]; then
     fi
 
     CLOUD_MODE_OPTS+=('-Dsolr.zookeeper.server.enabled=true')
+
+    if [ "$SOLR_SSL_ENABLED" == "true" ]; then
+      # There's no good reason to run a plaintext embedded ZooKeeper next to 
an HTTPS
+      # Solr, so secure it too, reusing Solr's own keystore/truststore. This 
branch only
+      # runs when ZK_HOST is unset, i.e. Solr is starting its own embedded 
ZooKeeper -
+      # an external ensemble (-z/--zk-host) is never touched by this: Solr has 
no way to
+      # know whether an external ensemble uses TLS, so nothing is assumed 
there.
+      ZK_SECURE_PORT=$((SOLR_PORT_LISTEN + 1000))
+      ZK_ZOO_CFG="$SOLR_HOME/zoo.cfg"

Review Comment:
    Could this whole zoo.cfg rewrite move into `SolrZkServer.parseConfig()` 
instead of living in each OS script? I.e. not touch `zoo.cfg` at all, but add 
those props at parse time (if they are missing from zoo.cfg). It already 
injects `clientPort`, `clientPortAddress`, the server list and the 4lw 
whitelist, so setting `secureClientPort` plus the `zookeeper.ssl.*` properties 
there would need no file edits, no password files on disk, and would cover 
`bin\solr.cmd` for free.
   
   The client side could follow the same principle: the node knows it is 
running a TLS-only embedded ZooKeeper, so `ZkContainer` can configure its own 
`SolrZkClient` for TLS in process, and SolrCLI already builds an SSL context 
from `SOLR_SSL_*` for HTTPS, so `bin/solr zk …`/`auth` could derive the 
ZooKeeper trust material from the same variables. Then the only thing left for 
the scripts, and the only thing persisted, is one explicit switch that this 
ZooKeeper speaks TLS (`-Dzookeeper.client.secure=true`), instead of the whole 
`SOLR_ZK_TLS_OPTS` flag list, and it should be scoped to the embedded ZooKeeper 
rather than to every `-z` from that install.



##########
changelog/unreleased/SOLR-18659-zk-tls.yml:
##########
@@ -0,0 +1,15 @@
+title: >

Review Comment:
   🤖 A `changed` default that turns an existing embedded ZooKeeper TLS-only on 
upgrade also deserves an entry in the upgrade notes; the changelog is not where 
operators look for that.



##########
solr/server/etc/security.policy:
##########
@@ -181,6 +183,11 @@ grant {
 
   permission java.io.FilePermission "${javax.net.ssl.trustStore}", 
"read,readlink";
 
+  permission java.io.FilePermission "${zookeeper.ssl.keyStore.location}", 
"read,readlink";
+  permission java.io.FilePermission "${zookeeper.ssl.keyStore.passwordPath}", 
"read,readlink";

Review Comment:
   🤖 `zookeeper.ssl.keyStore.location` and `.passwordPath` are never set as 
system properties (zoo.cfg only turns them into properties after the policy is 
loaded), so these entries expand-fail and are dropped. The grants that actually 
carry the server side are `${solr.jetty.keystore}` and `${solr.solr.home}${/}-`.



##########
solr/core/src/java/org/apache/solr/cloud/SolrZkServer.java:
##########
@@ -91,6 +91,12 @@ public String getClientString() {
     return hostName + ":" + addr.getPort();
   }
 
+  private InetSocketAddress getClientAddress() {

Review Comment:
   🤖 `getClientAddress()` prefers the plaintext address when both ports are 
configured, while `zookeeper.client.secure=true` forces TLS, so Solr would 
advertise and dial the wrong port. Prefer the secure address when that flag is 
set.



##########
solr/core/src/java/org/apache/solr/cloud/SolrZkServer.java:
##########
@@ -119,11 +125,15 @@ public void parseConfig() {
       SolrZkServerProps.injectServers(props, zkRun, zkHost);
       // 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) {
+      String bindHost = EnvUtils.getProperty("solr.zookeeper.embedded.host", 
"127.0.0.1");
+      boolean hasClientPort = props.getProperty("clientPort") != null;
+      boolean hasSecureClientPort = props.getProperty("secureClientPort") != 
null;

Review Comment:
   🤖 Design note, not a request for this PR: this secures only the client port 
of a single embedded ZooKeeper. The ensemble that SOLR-18094 (#2391) is heading 
for also needs quorum TLS on the peer and election ports (`sslQuorum=true`, 
`ssl.quorum.keyStore.*`/`ssl.quorum.trustStore.*`, 
`ssl.quorum.hostnameVerification`), which takes the same keystore, and 
`SOLR_SSL_CHECK_PEER_NAME` should map to `ssl.hostnameVerification` for both 
layers, or a dev cluster with per-node self-signed certificates fails the 
moment there are two nodes. One place that derives all of ZooKeeper TLS from 
Solr's SSL settings would keep that from being redone later; this method is 
that place.



##########
solr/solr-ref-guide/modules/getting-started/pages/tutorial-securing-solr.adoc:
##########
@@ -188,6 +186,33 @@ curl --fail 'http://localhost:8984/api/node/health'
 
 Do not use `curl -k` to bypass verification.
 
+Because `SOLR_SSL_ENABLED=true` and node 1 started its own embedded ZooKeeper 
(no `-z`), `bin/solr` automatically also secured that ZooKeeper's transport, 
reusing the same keystore and truststore, and printed a note that it updated 
the include file.
+Inspect what it did:
+
+[source,bash]
+----
+tail -12 "$TUTORIAL_HOME/node1/solr/zoo.cfg"
+tail -3 "$SOLR_INCLUDE"
+----
+
+`secureClientPort` replaces the plain `clientPort` ZooKeeper would otherwise 
default to, and `client.portUnification=false` makes the port reject plaintext 
connections outright.

Review Comment:
   🤖 `client.portUnification=false` is already ZooKeeper's default; the port 
rejects plaintext because it is a `secureClientPort`, not because of that line.



##########
solr/core/src/java/org/apache/solr/handler/admin/ZookeeperStatusHandler.java:
##########
@@ -350,6 +368,36 @@ protected List<String> getZkRawResponse(String zkHostPort, 
String fourLetterWord
     }
   }
 
+  /**
+   * Opens a TLS socket to a ZooKeeper server, using the same {@code 
zookeeper.ssl.*} trust material
+   * {@code -Dzookeeper.client.secure=true} already configures for the regular 
ZooKeeper client (see
+   * {@link org.apache.zookeeper.common.ClientX509Util}), rather than Solr's 
own HTTPS
+   * keystore/truststore system properties.
+   */
+  private Socket createSecureSocket(String host, int port) throws IOException {
+    try {
+      SSLSocket socket = 
x509Util().getDefaultSSLContextAndOptions().createSSLSocket();
+      socket.connect(new InetSocketAddress(host, port));

Review Comment:
   🤖 `socket.connect()` has no connect timeout and no `setSoTimeout`; the 
plaintext path had the same gap, but a stalled TLS handshake now hangs the 
admin request too. Also worth confirming SNI/endpoint identification applies on 
a `createSSLSocket()` + `connect()` socket.



##########
solr/packaging/test/test_secure_example.bats:
##########
@@ -111,11 +111,34 @@ teardown() {
   assert_success
   assert_output --partial 'collections'
 
+  # The Admin UI's ZK status page (ZookeeperStatusHandler) talks to ZooKeeper 
over a raw
+  # socket with four-letter-word commands, separately from the SolrZkClient 
used above;
+  # confirm it also works against the now TLS-only embedded ZooKeeper.
+  run curl --noproxy '*' --silent --show-error --fail --cacert 
"$SOLR_HOME/tls/cert.pem" \
+    --user "admin:$password" 
"https://localhost:$SOLR_PORT/solr/admin/zookeeper/status?wt=json";
+  assert_success
+  assert_output --partial '"ok":true'
+  assert_output --partial '"status":"green"'
+
+  # bin/solr writes SOLR_ZK_TLS_OPTS into the include file automatically 
(because
+  # SOLR_SSL_ENABLED=true and node 1 started its own embedded ZooKeeper); read 
it back
+  # rather than hardcoding its keystore/password-file paths here.
+  local tls_opts
+  tls_opts=$(grep '^SOLR_ZK_TLS_OPTS=' "$SOLR_HOME/tls/solr.in.sh" | sed -E 
's/^SOLR_ZK_TLS_OPTS="(.*)"$/\1/')
+  [ -n "$tls_opts" ]
+
+  # Embedded ZooKeeper's clientPort is TLS-only; a client that doesn't speak 
TLS at all can't
+  # even reach the ACL check, so it times out instead of getting a clean 
rejection.
   run env SOLR_INCLUDE=/dev/null SOLR_ZK_CREDS_AND_ACLS= solr zk ls / 
--zk-host "localhost:$ZK_PORT"
   assert_failure
+  assert_output --partial 'Timeout while waiting for Zookeeper Client to 
connect'
+
+  run env SOLR_INCLUDE=/dev/null SOLR_ZK_CREDS_AND_ACLS="$tls_opts" \

Review Comment:
   🤖 Isn't passing the TLS flags through `SOLR_ZK_CREDS_AND_ACLS` what the new 
note in zookeeper-access-control.adoc tells users not to do? Alternative: 
`SOLR_ZK_TLS_OPTS=`?



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