Apache Lucene open-source search software
SOLR-14163: SOLR_SSL_CLIENT_HOSTNAME_VERIFICATION needs to work with Jetty server/client SSL contexts
Kevin Risden22155bf7a7cb
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 32781e830dc..ce20f8527fa 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -210,6 +210,8 @@ Bug Fixes* SOLR-13089: Fix lsof edge cases in the solr CLI script (Martijn Koster via janhoy)+* SOLR-14163: SOLR_SSL_CLIENT_HOSTNAME_VERIFICATION needs to work with Jetty server/client SSL contexts (Kevin Risden)+Other Changes---------------------diff --git a/solr/bin/solr b/solr/bin/solrindex 869a9ff6be1..4faf61b772b 100755--- a/solr/bin/solr+++ b/solr/bin/solr@@ -206,14 +206,13 @@ if [ "$SOLR_SSL_ENABLED" == "true" ]; thenSOLR_SSL_OPTS+=" -Dsolr.jetty.truststore.type=$SOLR_SSL_TRUST_STORE_TYPE"fi- if [ -n "$SOLR_SSL_NEED_CLIENT_AUTH" ]; then- SOLR_SSL_OPTS+=" -Dsolr.jetty.ssl.needClientAuth=$SOLR_SSL_NEED_CLIENT_AUTH"- fi-if [ -z "$SOLR_SSL_CLIENT_HOSTNAME_VERIFICATION" ] ; thenSOLR_SSL_OPTS+=" -Dsolr.jetty.ssl.verifyClientHostName=HTTPS"fi+ if [ -n "$SOLR_SSL_NEED_CLIENT_AUTH" ]; then+ SOLR_SSL_OPTS+=" -Dsolr.jetty.ssl.needClientAuth=$SOLR_SSL_NEED_CLIENT_AUTH"+ fiif [ -n "$SOLR_SSL_WANT_CLIENT_AUTH" ]; thenSOLR_SSL_OPTS+=" -Dsolr.jetty.ssl.wantClientAuth=$SOLR_SSL_WANT_CLIENT_AUTH"fidiff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmdindex fe816947ba1..05a7472c6c3 100755--- a/solr/bin/solr.cmd+++ b/solr/bin/solr.cmd@@ -82,6 +82,10 @@ IF "%SOLR_SSL_ENABLED%"=="true" (set "SOLR_SSL_OPTS=!SOLR_SSL_OPTS! -Dsolr.jetty.truststore.type=%SOLR_SSL_TRUST_STORE_TYPE%")+ IF NOT DEFINED SOLR_SSL_CLIENT_HOSTNAME_VERIFICATION (+ set "SOLR_SSL_OPTS=!SOLR_SSL_OPTS! -Dsolr.jetty.ssl.verifyClientHostName=HTTPS"+ )+IF DEFINED SOLR_SSL_NEED_CLIENT_AUTH (set "SOLR_SSL_OPTS=!SOLR_SSL_OPTS! -Dsolr.jetty.ssl.needClientAuth=%SOLR_SSL_NEED_CLIENT_AUTH%")diff --git a/solr/server/etc/jetty-ssl.xml b/solr/server/etc/jetty-ssl.xmlindex 3688c4c7159..53e0ec1109b 100644--- a/solr/server/etc/jetty-ssl.xml+++ b/solr/server/etc/jetty-ssl.xml@@ -17,7 +17,6 @@<Set name="TrustStorePassword"><Ref refid="trustStorePassword"/></Set><Set name="NeedClientAuth"><Property name="solr.jetty.ssl.needClientAuth" default="false"/></Set><Set name="WantClientAuth"><Property name="solr.jetty.ssl.wantClientAuth" default="false"/></Set>- <Set name="EndpointIdentificationAlgorithm"><Property name="solr.jetty.ssl.verifyClientHostName"/></Set><Set name="KeyStoreType"><Property name="solr.jetty.keystore.type" default="PKCS12"/></Set><Set name="TrustStoreType"><Property name="solr.jetty.truststore.type" default="PKCS12"/></Set>diff --git a/solr/solr-ref-guide/src/enabling-ssl.adoc b/solr/solr-ref-guide/src/enabling-ssl.adocindex ccfbf008d20..5840e3f35e0 100644--- a/solr/solr-ref-guide/src/enabling-ssl.adoc+++ b/solr/solr-ref-guide/src/enabling-ssl.adoc@@ -66,7 +66,7 @@ NOTE: If you setup Solr as a service on Linux using the steps outlined in <<taki.bin/solr.in.sh example SOLR_SSL_* configuration[source,bash]-----# Enables HTTPS. It is implictly true if you set SOLR_SSL_KEY_STORE. Use this config+# Enables HTTPS. It is implicitly true if you set SOLR_SSL_KEY_STORE. Use this config# to enable https module with custom jetty configuration.SOLR_SSL_ENABLED=true# Uncomment to set SSL-related system properties@@ -79,8 +79,6 @@ SOLR_SSL_TRUST_STORE_PASSWORD=secretSOLR_SSL_NEED_CLIENT_AUTH=false# Enable clients to authenticate (but not require)SOLR_SSL_WANT_CLIENT_AUTH=false-# Verify client's hostname during SSL handshake-SOLR_SSL_CLIENT_HOSTNAME_VERIFICATION=false# SSL Certificates contain host/ip "peer name" information that is validated by default. Setting# this to false can be useful to disable these checks when re-using a certificate on many hostsSOLR_SSL_CHECK_PEER_NAME=true@@ -89,14 +87,14 @@ SOLR_SSL_CHECK_PEER_NAME=trueWhen you start Solr, the `bin/solr` script includes the settings in `bin/solr.in.sh` and will pass these SSL-related system properties to the JVM..Client Authentication Settings-WARNING: Enable either SOLR_SSL_NEED_CLIENT_AUTH or SOLR_SSL_WANT_CLIENT_AUTH but not both at the same time. They are mutually exclusive and Jetty will select one of them which may not be what you expect. SOLR_SSL_CLIENT_HOSTNAME_VERIFICATION should be set to true if you only want requests from authenticated host-names to be accepted.+WARNING: Enable either SOLR_SSL_NEED_CLIENT_AUTH or SOLR_SSL_WANT_CLIENT_AUTH but not both at the same time. They are mutually exclusive and Jetty will select one of them which may not be what you expect. SOLR_SSL_CLIENT_HOSTNAME_VERIFICATION should be set to false if you want to disable hostname verification.Similarly, when you start Solr on Windows, the `bin\solr.cmd` script includes the settings in `bin\solr.in.cmd` - uncomment and update the set of properties beginning with `SOLR_SSL_*` to pass these SSL-related system properties to the JVM:.bin\solr.in.cmd example SOLR_SSL_* configuration[source,text]-----REM Enables HTTPS. It is implictly true if you set SOLR_SSL_KEY_STORE. Use this config+REM Enables HTTPS. It is implicitly true if you set SOLR_SSL_KEY_STORE. Use this configREM to enable https module with custom jetty configuration.set SOLR_SSL_ENABLED=trueREM Uncomment to set SSL-related system properties@@ -109,8 +107,6 @@ REM Require clients to authenticateset SOLR_SSL_NEED_CLIENT_AUTH=falseREM Enable clients to authenticate (but not require)set SOLR_SSL_WANT_CLIENT_AUTH=false-REM Verify client hostname during SSL handshake-set SOLR_SSL_CLIENT_HOSTNAME_VERIFICATION=falseREM SSL Certificates contain host/ip "peer name" information that is validated by default. SettingREM this to false can be useful to disable these checks when re-using a certificate on many hostsset SOLR_SSL_CHECK_PEER_NAME=truediff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/embedded/SSLConfig.java b/solr/solrj/src/java/org/apache/solr/client/solrj/embedded/SSLConfig.javaindex c5d0f3df4f3..d77a1db93d6 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/embedded/SSLConfig.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/embedded/SSLConfig.java@@ -136,7 +136,27 @@ public class SSLConfig {}public SslContextFactory.Client createClientContextFactory() {- return new SslContextFactory.Client();+ if (! isSSLMode()) {+ return null;+ }+ // else...++ SslContextFactory.Client factory = new SslContextFactory.Client();+ if (getKeyStore() != null) {+ factory.setKeyStorePath(getKeyStore());+ }+ if (getKeyStorePassword() != null) {+ factory.setKeyStorePassword(getKeyStorePassword());+ }++ if (isClientAuthMode()) {+ if (getTrustStore() != null)+ factory.setTrustStorePath(getTrustStore());+ if (getTrustStorePassword() != null)+ factory.setTrustStorePassword(getTrustStorePassword());+ }++ return factory;}private static SslContextFactory.Server configureSslFromSysProps() {diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.javaindex 13b68c2b586..8c6e546b14d 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java@@ -919,7 +919,8 @@ public class Http2SolrClient extends SolrClient {Http2SolrClient.defaultSSLConfig = null;}- private static SslContextFactory.Client getDefaultSslContextFactory() {+ /* package-private for testing */+ static SslContextFactory.Client getDefaultSslContextFactory() {String checkPeerNameStr = System.getProperty(HttpClientUtil.SYS_PROP_CHECK_PEER_NAME);boolean sslCheckPeerName = true;if (checkPeerNameStr == null || "false".equalsIgnoreCase(checkPeerNameStr)) {@@ -945,6 +946,8 @@ public class Http2SolrClient extends SolrClient {(System.getProperty("javax.net.ssl.trustStorePassword"));}+ sslContextFactory.setEndpointIdentificationAlgorithm(System.getProperty("solr.jetty.ssl.verifyClientHostName"));+return sslContextFactory;}}diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.javaindex ad7838bb44f..06e4ba9efa0 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java@@ -45,6 +45,7 @@ import org.apache.solr.common.SolrInputDocument;import org.apache.solr.common.params.CommonParams;import org.apache.solr.common.util.SuppressForbidden;import org.eclipse.jetty.servlet.ServletHolder;+import org.eclipse.jetty.util.ssl.SslContextFactory;import org.junit.BeforeClass;import org.junit.Test;@@ -588,6 +589,16 @@ public class Http2SolrClientTest extends SolrJettyTestBase {}}+ @Test+ public void testGetDefaultSslContextFactory() {+ assertNull(Http2SolrClient.getDefaultSslContextFactory().getEndpointIdentificationAlgorithm());++ System.setProperty("solr.jetty.ssl.verifyClientHostName", "HTTPS");+ SslContextFactory.Client sslContextFactory = Http2SolrClient.getDefaultSslContextFactory();+ assertEquals("HTTPS", sslContextFactory.getEndpointIdentificationAlgorithm());+ System.clearProperty("solr.jetty.ssl.verifyClientHostName");+ }+/*** Missed tests :* - set cookies via interceptor