Apache Solr open-source search software
SOLR-18224: New allowZkHosts setting for cross-collection join/streaming zkHost
David Smileyb66758a1d03b
diff --git a/changelog/unreleased/SOLR-18224-allowZkHosts.yml b/changelog/unreleased/SOLR-18224-allowZkHosts.ymlnew file mode 100644index 00000000000..86116e14691--- /dev/null+++ b/changelog/unreleased/SOLR-18224-allowZkHosts.yml@@ -0,0 +1,15 @@+title: >-+ New solr.xml setting allowZkHosts limits which ZooKeeper connection strings+ a cross-collection join or streaming expression may use (zkHost or+ solrConnection); an HTTP(s) solrConnection must be a live node or be listed+ in allowUrls. The local SolrCloud ensemble is always allowed. zkHost+ and solrUrl are now mutually exclusive in a single cross-collection join+ clause. The local ensemble is matched verbatim, including any chroot: a node+ started with `-DzkHost=zk1:2181/solr` allows `zkHost="zk1:2181/solr"` but not+ `zkHost="zk1:2181"` unless listed in `allowZkHosts`.+type: changed+authors:+ - name: Mark Robert Miller+links:+ - name: SOLR-18224+ url: https://issues.apache.org/jira/browse/SOLR-18224diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkController.java b/solr/core/src/java/org/apache/solr/cloud/ZkController.javaindex 4333ec1cb6c..6d8310c01f7 100644--- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java+++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java@@ -124,6 +124,7 @@ import org.apache.solr.core.SolrCoreInitializationException;import org.apache.solr.handler.component.HttpShardHandler;import org.apache.solr.logging.MDCLoggingContext;import org.apache.solr.search.SolrIndexSearcher;+import org.apache.solr.security.AllowListZkHostChecker;import org.apache.solr.update.UpdateLog;import org.apache.solr.util.AddressUtils;import org.apache.solr.util.RTimer;@@ -218,6 +219,7 @@ public class ZkController implements Closeable {private final AtomicBoolean zkSessionExpired = new AtomicBoolean();private final String zkServerAddress; // example: 127.0.0.1:54062/solr+ private final AllowListZkHostChecker allowListZkHostChecker;private final int localHostPort; // example: 54065private final String hostName; // example: 127.0.0.1@@ -302,6 +304,7 @@ public class ZkController implements Closeable {this.cloudConfig = cloudConfig;this.zkServerAddress = zkServerAddress;+ this.allowListZkHostChecker = AllowListZkHostChecker.create(cc.getConfig(), zkServerAddress);this.localHostPort = cloudConfig.getSolrHostPort();this.hostName = normalizeHostName(cloudConfig.getHost());this.nodeName = generateNodeName(this.hostName, Integer.toString(this.localHostPort));@@ -1010,6 +1013,15 @@ public class ZkController implements Closeable {return zkServerAddress;}+ /**+ * Returns the ZooKeeper-host checker based on the {@code allowZkHosts} configuration in {@code+ * solr.xml}, always allowing this cluster's ZK ensemble. Used by features that accept a+ * caller-supplied {@code zkHost}.+ */+ public AllowListZkHostChecker getAllowListZkHostChecker() {+ return allowListZkHostChecker;+ }+boolean isClosed() {return isClosed;}diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.javaindex ef6852a14db..9bacc62746a 100644--- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java+++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java@@ -40,6 +40,7 @@ import io.opentelemetry.api.trace.Tracer;import jakarta.inject.Singleton;import java.io.IOException;import java.lang.invoke.MethodHandles;+import java.net.MalformedURLException;import java.nio.file.Files;import java.nio.file.Path;import java.text.SimpleDateFormat;@@ -68,6 +69,7 @@ import org.apache.solr.api.ClusterPluginsSource;import org.apache.solr.api.ContainerPluginsRegistry;import org.apache.solr.api.JerseyResource;import org.apache.solr.client.solrj.SolrRequest;+import org.apache.solr.client.solrj.impl.CloudSolrClient;import org.apache.solr.client.solrj.impl.HttpSolrClient;import org.apache.solr.client.solrj.io.SolrClientCache;import org.apache.solr.client.solrj.util.SolrIdentifierValidator;@@ -798,6 +800,9 @@ public class CoreContainer {new HttpSolrClientProvider(cfg.getUpdateShardHandlerConfig(), solrMetricsContext);updateShardHandler.initializeMetrics(solrMetricsContext, Attributes.empty());solrClientCache = new SolrClientCache(solrClientProvider.getSolrClient());+ // Validate caller-supplied zkHost/solrConnection (cross-collection join, streaming+ // expressions).+ solrClientCache.setConnectionValidator(this::validateSolrConnection);Map<String, CacheConfig> cachesConfig = cfg.getCachesConfig();if (cachesConfig.isEmpty()) {@@ -1636,6 +1641,38 @@ public class CoreContainer {return allowListUrlChecker;}+ /**+ * Validates a connection to a SolrCloud cluster: ZooKeeper via {@link+ * ZkController#getAllowListZkHostChecker()} (never allowed in standalone mode), HTTP via {@link+ * AllowListUrlChecker} (live nodes of this cluster are allowed).+ *+ * @throws SolrException FORBIDDEN if not allowed+ */+ private void validateSolrConnection(CloudSolrClient.CloudSolrClientConnection solrConnection) {+ ZkController zkController = getZkController();+ if (solrConnection.isZookeeper()) {+ String zkHost = solrConnection.toString();+ if (zkController == null) {+ throw new SolrException(+ ErrorCode.FORBIDDEN,+ "ZooKeeper host '" + zkHost + "' is not allowed when Solr is not in SolrCloud mode.");+ }+ if (!zkController.getAllowListZkHostChecker().isAllowed(zkHost)) {+ throw new SolrException(+ ErrorCode.FORBIDDEN, SolrClientCache.zkHostRejectionMessage(zkHost));+ }+ } else {+ try {+ allowListUrlChecker.checkAllowList(+ solrConnection.quorumItems(),+ zkController == null ? null : zkController.getClusterState());+ } catch (MalformedURLException e) {+ throw new SolrException(+ ErrorCode.BAD_REQUEST, "Invalid URL in solrConnection: " + solrConnection, e);+ }+ }+ }+/*** Creates a new core based on a CoreDescriptor.*diff --git a/solr/core/src/java/org/apache/solr/core/NodeConfig.java b/solr/core/src/java/org/apache/solr/core/NodeConfig.javaindex 53e9a07315b..bde3d6932d1 100644--- a/solr/core/src/java/org/apache/solr/core/NodeConfig.java+++ b/solr/core/src/java/org/apache/solr/core/NodeConfig.java@@ -120,6 +120,8 @@ public class NodeConfig {private final String defaultZkHost;+ private final List<String> allowZkHosts;+private NodeConfig(String nodeName,Path coreRootDirectory,@@ -154,6 +156,7 @@ public class NodeConfig {String defaultZkHost,Set<Path> allowPaths,List<String> allowUrls,+ List<String> allowZkHosts,boolean hideStackTraces,String configSetServiceClass,String modules,@@ -192,6 +195,7 @@ public class NodeConfig {this.defaultZkHost = defaultZkHost;this.allowPaths = allowPaths;this.allowUrls = allowUrls;+ this.allowZkHosts = allowZkHosts;this.hideStackTraces = hideStackTraces;this.configSetServiceClass = configSetServiceClass;this.modules = modules;@@ -437,6 +441,15 @@ public class NodeConfig {return allowUrls;}+ /**+ * Allow-list of remote ZooKeeper connection strings that may be passed to query/streaming+ * features which accept a {@code zkHost} parameter (e.g. cross-collection join, /stream+ * expressions). The local cluster's own ZK ensemble is always trusted and need not be listed.+ */+ public List<String> getAllowZkHosts() {+ return allowZkHosts;+ }+public boolean hideStackTraces() {return hideStackTraces;}@@ -600,6 +613,7 @@ public class NodeConfig {private String defaultZkHost;private Set<Path> allowPaths = Set.of();private List<String> allowUrls = List.of();+ private List<String> allowZkHosts = List.of();private boolean hideStackTrace =!EnvUtils.getPropertyAsBool("solr.responses.stacktrace.enabled", true);@@ -804,6 +818,11 @@ public class NodeConfig {return this;}+ public NodeConfigBuilder setAllowZkHosts(List<String> zkHosts) {+ this.allowZkHosts = zkHosts;+ return this;+ }+public NodeConfigBuilder setHideStackTrace(boolean hide) {this.hideStackTrace = hide;return this;@@ -895,6 +914,7 @@ public class NodeConfig {defaultZkHost,allowPaths,allowUrls,+ allowZkHosts,hideStackTrace,configSetServiceClass,modules,diff --git a/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java b/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.javaindex de58f5f50aa..5c55bc00eef 100644--- a/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java+++ b/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java@@ -376,6 +376,9 @@ public class SolrXmlConfig {case "allowUrls":builder.setAllowUrls(separateStrings(it.txt()));break;+ case "allowZkHosts":+ builder.setAllowZkHosts(separateZkHosts(it.txt()));+ break;default:throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,@@ -398,6 +401,20 @@ public class SolrXmlConfig {return Arrays.asList(COMMA_SEPARATED_PATTERN.split(commaSeparatedString));}+ /**+ * Like {@link #separateStrings(String)} but drops blank entries so a stray comma or unset {@code+ * ${prop:}} placeholder does not produce an empty allow-list entry. {@code allowUrls}/{@code+ * allowPaths} keep their pre-existing behavior.+ */+ private static List<String> separateZkHosts(String commaSeparatedString) {+ if (StrUtils.isNullOrEmpty(commaSeparatedString)) {+ return List.of();+ }+ return Arrays.stream(COMMA_SEPARATED_PATTERN.split(commaSeparatedString))+ .filter(s -> !s.isBlank())+ .toList();+ }+private static Set<Path> separatePaths(String commaSeparatedString) {if (StrUtils.isNullOrEmpty(commaSeparatedString)) {return Set.of();diff --git a/solr/core/src/java/org/apache/solr/search/join/CrossCollectionJoinQParser.java b/solr/core/src/java/org/apache/solr/search/join/CrossCollectionJoinQParser.javaindex 696c5b286cb..b336124bb4b 100644--- a/solr/core/src/java/org/apache/solr/search/join/CrossCollectionJoinQParser.java+++ b/solr/core/src/java/org/apache/solr/search/join/CrossCollectionJoinQParser.java@@ -23,9 +23,11 @@ import java.util.Iterator;import java.util.Set;import org.apache.lucene.search.Query;import org.apache.solr.client.solrj.impl.CloudSolrClient;+import org.apache.solr.common.SolrException;import org.apache.solr.common.params.ModifiableSolrParams;import org.apache.solr.common.params.ShardParams;import org.apache.solr.common.params.SolrParams;+import org.apache.solr.core.CoreContainer;import org.apache.solr.request.SolrQueryRequest;import org.apache.solr.search.QParser;import org.apache.solr.search.QueryParsing;@@ -51,6 +53,7 @@ public class CrossCollectionJoinQParser extends QParser {QueryParsing.TYPE,QueryParsing.V,ZK_HOST,+ SOLR_CONNECTION,SOLR_URL,FROM_INDEX,FROM,@@ -80,6 +83,11 @@ public class CrossCollectionJoinQParser extends QParser {String zkHost = localParams.get(ZK_HOST);String solrConnectionString = localParams.get(SOLR_CONNECTION);String solrUrl = localParams.get(SOLR_URL);+ // CrossCollectionJoinQuery.getDocSet() silently prefers zkHost when both are set.+ if (zkHost != null && solrUrl != null) {+ throw new SyntaxError(+ "zkHost and solrUrl are mutually exclusive; specify at most one of them.");+ }// Test if this is a valid solr url.if (solrUrl != null) {if (allowSolrUrls == null) {@@ -117,6 +125,14 @@ public class CrossCollectionJoinQParser extends QParser {} else if (zkHost != null && !zkHost.isBlank()) {solrConnection = CloudSolrClient.CloudSolrClientConnection.parse(zkHost);}+ CoreContainer cc = req.getCoreContainer();+ if (solrConnection != null && cc != null) { // no CoreContainer -- unit test+ try {+ cc.getSolrClientCache().validateConnection(solrConnection);+ } catch (SolrException e) {+ throw new SyntaxError(e.getMessage(), e);+ }+ }return new CrossCollectionJoinQuery(query,solrConnection,diff --git a/solr/core/src/java/org/apache/solr/security/AllowListZkHostChecker.java b/solr/core/src/java/org/apache/solr/security/AllowListZkHostChecker.javanew file mode 100644index 00000000000..c6ec76f7f4c--- /dev/null+++ b/solr/core/src/java/org/apache/solr/security/AllowListZkHostChecker.java@@ -0,0 +1,76 @@+/*+ * 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.security;++import java.util.Collection;+import java.util.Set;+import org.apache.solr.core.NodeConfig;++/**+ * Validates a caller-supplied ZooKeeper connection string against the local cluster's ensemble and+ * a configured allow-list. The ZooKeeper counterpart of {@link AllowListUrlChecker}.+ *+ * <p>A {@code zkHost} value is allowed if any of the following are true:+ *+ * <ul>+ * <li>It is {@code null} (caller did not specify one; Solr will use the local ensemble).+ * <li>It equals the local SolrCloud ZooKeeper connection string verbatim.+ * <li>It appears verbatim in the {@code allowZkHosts} list configured in {@code solr.xml}.+ * </ul>+ *+ * <p>Comparison is strict character-for-character; no normalization of trailing slashes, chroot+ * suffixes, host order, whitespace, or case. Operators must list each form they intend to accept.+ */+public class AllowListZkHostChecker {++ /** {@link org.apache.solr.core.SolrXmlConfig} property to configure the allowed ZK hosts. */+ public static final String ZK_HOST_ALLOW_LIST = "allowZkHosts";++ private final Set<String> allowedZkHosts;+ private final String localZkHost;++ /**+ * @param allowedZkHosts the verbatim ZooKeeper connection strings configured under {@link+ * #ZK_HOST_ALLOW_LIST} in {@code solr.xml}. May be null or empty.+ * @param localZkHost the local SolrCloud ZooKeeper connection string. May be null.+ */+ public AllowListZkHostChecker(Collection<String> allowedZkHosts, String localZkHost) {+ this.allowedZkHosts =+ allowedZkHosts == null || allowedZkHosts.isEmpty() ? Set.of() : Set.copyOf(allowedZkHosts);+ this.localZkHost = localZkHost;+ }++ /** Creates a checker from the {@link NodeConfig} and the local ZK address. */+ public static AllowListZkHostChecker create(NodeConfig config, String localZkHost) {+ return new AllowListZkHostChecker(config.getAllowZkHosts(), localZkHost);+ }++ /**+ * Returns true if {@code zkHost} is null, equals the local ensemble, or appears verbatim in the+ * configured allow-list.+ */+ public boolean isAllowed(String zkHost) {+ if (zkHost == null) {+ return true;+ }+ if (zkHost.equals(localZkHost)) {+ return true;+ }+ return allowedZkHosts.contains(zkHost);+ }+}diff --git a/solr/core/src/test/org/apache/solr/core/TestSolrXml.java b/solr/core/src/test/org/apache/solr/core/TestSolrXml.javaindex eeab65afbf1..8aa23659c7f 100644--- a/solr/core/src/test/org/apache/solr/core/TestSolrXml.java+++ b/solr/core/src/test/org/apache/solr/core/TestSolrXml.java@@ -21,6 +21,7 @@ import static org.hamcrest.core.StringContains.containsString;import java.io.IOException;import java.nio.file.Files;import java.nio.file.Path;+import java.util.List;import java.util.Locale;import java.util.Map;import java.util.Properties;@@ -207,6 +208,24 @@ public class TestSolrXml extends SolrTestCaseJ4 {assertEquals("hostPort", 8000, cfg.getCloudConfig().getSolrHostPort());}+ // SOLR-18224: allowZkHosts is parsed via a helper that drops blank entries so a+ // stray comma or unset ${prop:} expansion cannot produce an empty allow-list entry.+ public void testAllowZkHostsParsing() {+ String withEntries =+ "<solr><str name=\"allowZkHosts\">zk-a:2181,,zk-b:2181/chroot, ,zk-c:2181</str></solr>";+ NodeConfig cfgEntries = SolrXmlConfig.fromString(solrHome, withEntries);+ assertEquals(+ List.of("zk-a:2181", "zk-b:2181/chroot", "zk-c:2181"), cfgEntries.getAllowZkHosts());++ String empty = "<solr><str name=\"allowZkHosts\"></str></solr>";+ NodeConfig cfgEmpty = SolrXmlConfig.fromString(solrHome, empty);+ assertEquals(List.of(), cfgEmpty.getAllowZkHosts());++ String absent = "<solr></solr>";+ NodeConfig cfgAbsent = SolrXmlConfig.fromString(solrHome, absent);+ assertEquals(List.of(), cfgAbsent.getAllowZkHosts());+ }+public void testIntAsLongBad() {String bad = "" + TestUtil.nextLong(random(), Integer.MAX_VALUE, Long.MAX_VALUE);String solrXml =diff --git a/solr/core/src/test/org/apache/solr/search/join/CrossCollectionJoinQueryTest.java b/solr/core/src/test/org/apache/solr/search/join/CrossCollectionJoinQueryTest.javaindex 078fd4dcf98..341be4d6223 100644--- a/solr/core/src/test/org/apache/solr/search/join/CrossCollectionJoinQueryTest.java+++ b/solr/core/src/test/org/apache/solr/search/join/CrossCollectionJoinQueryTest.java@@ -40,6 +40,7 @@ import org.apache.solr.embedded.JettySolrRunner;import org.apache.solr.request.SolrQueryRequest;import org.apache.solr.request.SolrQueryRequestBase;import org.apache.solr.search.QueryParsing;+import org.apache.solr.search.SyntaxError;import org.apache.solr.util.SolrJMetricTestUtils;import org.junit.BeforeClass;import org.junit.Test;@@ -161,6 +162,7 @@ public class CrossCollectionJoinQueryTest extends SolrCloudTestCase {String url = runner.getBaseUrl().toString();System.setProperty("test.ccjoin.solr.url." + i, url);}+ String quorumHosts = cluster.getSolrClient().getClusterStateProvider().getQuorumHosts();try {// now we need to re-upload our config , now that we know a valid solr url for the cluster.CloudSolrClient client = cluster.getSolrClient();@@ -200,11 +202,12 @@ public class CrossCollectionJoinQueryTest extends SolrCloudTestCase {"{!join method=crossCollection solrUrl=\"%s\" fromIndex=products from=product_id_s to=product_id_s}size_s:M",getSolrUrl()),true);+ // The local cluster's ZK ensemble is always allowed; no allowZkHosts entry needed.testCcJoinQuery(String.format(Locale.ROOT,"{!join method=crossCollection zkHost=\"%s\" fromIndex=products from=product_id_s to=product_id_s}size_s:M",- client.getClusterStateProvider().getQuorumHosts()),+ quorumHosts),true);testCcJoinQuery(String.format(@@ -326,6 +329,146 @@ public class CrossCollectionJoinQueryTest extends SolrCloudTestCase {}}+ @Test+ public void testAllowZkHostsList() throws Exception {+ setupIndexes(false);++ int i = 0;+ for (JettySolrRunner runner : cluster.getJettySolrRunners()) {+ i++;+ System.setProperty("test.ccjoin.solr.url." + i, runner.getBaseUrl().toString());+ }+ String quorumHosts = cluster.getSolrClient().getClusterStateProvider().getQuorumHosts();+ try {+ CloudSolrClient client = cluster.getSolrClient();+ cluster.uploadConfigSet(configset("ccjoin"), "ccjoin");+ CollectionAdminRequest.Reload.reloadCollection("products").process(client);+ CollectionAdminRequest.Reload.reloadCollection("parts").process(client);++ Exception unlisted =+ expectThrows(+ Exception.class,+ () ->+ testCcJoinQuery(+ "{!join method=crossCollection zkHost=\"other-zk.example.com:2181/solr\""+ + " fromIndex=products from=product_id_i to=product_id_i}size_s:M",+ true));+ assertTrue(+ "Unexpected message: " + unlisted.getMessage(),+ unlisted.getMessage().contains("other-zk.example.com:2181/solr"));++ // The local cluster's ZK ensemble is always allowed, so the local quorum string must+ // succeed. product_id_i (not _s) so the join does not default to routed-by-join-key --+ // setupIndexes(false) does not shard-route by that field.+ testCcJoinQuery(+ String.format(+ Locale.ROOT,+ "{!join method=crossCollection zkHost=\"%s\""+ + " fromIndex=products from=product_id_i to=product_id_i}size_s:M",+ quorumHosts),+ true);++ Exception unlistedHttp =+ expectThrows(+ Exception.class,+ () ->+ testCcJoinQuery(+ "{!join method=crossCollection"+ + " solrConnection=\"http://other-solr.example.com:8983/solr\""+ + " fromIndex=products from=product_id_i to=product_id_i}size_s:M",+ true));+ assertTrue(+ "Unexpected message: " + unlistedHttp.getMessage(),+ unlistedHttp.getMessage().contains("other-solr.example.com")+ && unlistedHttp.getMessage().contains("allowUrls"));++ Exception both =+ expectThrows(+ Exception.class,+ () ->+ testCcJoinQuery(+ String.format(+ Locale.ROOT,+ "{!join method=crossCollection zkHost=\"%s\" solrUrl=\"%s\""+ + " fromIndex=products from=product_id_i to=product_id_i}size_s:M",+ quorumHosts,+ getSolrUrl()),+ true));+ assertTrue(+ "Unexpected message: " + both.getMessage(),+ both.getMessage().contains("mutually exclusive"));++ // Mutual exclusion is checked before either allow-list.+ Exception bothUnlistedZk =+ expectThrows(+ Exception.class,+ () ->+ testCcJoinQuery(+ String.format(+ Locale.ROOT,+ "{!join method=crossCollection"+ + " zkHost=\"other-zk.example.com:2181/solr\" solrUrl=\"%s\""+ + " fromIndex=products from=product_id_i to=product_id_i}size_s:M",+ getSolrUrl()),+ true));+ assertTrue(+ "Unexpected message: " + bothUnlistedZk.getMessage(),+ bothUnlistedZk.getMessage().contains("mutually exclusive"));++ Exception bothUnlistedUrl =+ expectThrows(+ Exception.class,+ () ->+ testCcJoinQuery(+ String.format(+ Locale.ROOT,+ "{!join method=crossCollection zkHost=\"%s\""+ + " solrUrl=\"http://other-solr.example.com:18080/solr\""+ + " fromIndex=products from=product_id_i to=product_id_i}size_s:M",+ quorumHosts),+ true));+ assertTrue(+ "Unexpected message: " + bothUnlistedUrl.getMessage(),+ bothUnlistedUrl.getMessage().contains("mutually exclusive"));++ } finally {+ int j = 0;+ for (JettySolrRunner runner : cluster.getJettySolrRunners()) {+ j++;+ System.getProperties().remove("test.ccjoin.solr.url." + j);+ }+ }+ }++ @Test+ public void testZkHostAndSolrUrlMutualExclusionAtParser() throws SyntaxError {+ ModifiableSolrParams localParams = new ModifiableSolrParams();+ localParams.set(QueryParsing.V, "*:*");+ localParams.set(CrossCollectionJoinQParser.ZK_HOST, "trusted-zk:2181/chroot");+ localParams.set(CrossCollectionJoinQParser.SOLR_URL, "http://trusted-solr:8983/solr");+ localParams.set(CrossCollectionJoinQParser.FROM_INDEX, "products");+ localParams.set(CrossCollectionJoinQParser.FROM, "product_id_s");+ localParams.set(CrossCollectionJoinQParser.TO, "product_id_s");+ localParams.set(CrossCollectionJoinQParser.ROUTED_BY_JOIN_KEY, "false");++ ModifiableSolrParams requestParams = new ModifiableSolrParams();+ try (SolrQueryRequest req = new SolrQueryRequestBase(null, requestParams) {}) {+ CrossCollectionJoinQParser parser =+ new CrossCollectionJoinQParser(+ null, localParams, requestParams, req, "product_id_s", null);+ SyntaxError e =+ expectThrows(+ SyntaxError.class,+ "Expected SyntaxError when both zkHost and solrUrl are specified",+ parser::parse);+ assertTrue(+ "Unexpected message: " + e.getMessage(),+ e.getMessage().contains("mutually exclusive")+ && e.getMessage().contains("zkHost")+ && e.getMessage().contains("solrUrl"));+ }+ }+@Testpublic void testShardsPreferenceRequestParamPropagation() throws Exception {// shards.preference set as a request-level param (not in localParams) should bediff --git a/solr/server/solr/solr.xml b/solr/server/solr/solr.xmlindex ff7c7505c69..bfc74a30156 100644--- a/solr/server/solr/solr.xml+++ b/solr/server/solr/solr.xml@@ -33,6 +33,7 @@<str name="modules">${solr.modules:}</str><str name="allowPaths">${solr.security.allow.paths:}</str><str name="allowUrls">${solr.security.allow.urls:}</str>+ <str name="allowZkHosts">${solr.security.allow.zk.hosts:}</str><str name="hideStackTrace">${solr.hideStackTrace:false}</str><int name="indexSearcherExecutorThreads">${solr.searchThreads:0}</int>diff --git a/solr/solr-ref-guide/modules/configuration-guide/pages/configuring-solr-xml.adoc b/solr/solr-ref-guide/modules/configuration-guide/pages/configuring-solr-xml.adocindex 66e6d21dc7a..bc22a2ed2f5 100644--- a/solr/solr-ref-guide/modules/configuration-guide/pages/configuring-solr-xml.adoc+++ b/solr/solr-ref-guide/modules/configuration-guide/pages/configuring-solr-xml.adoc@@ -37,6 +37,7 @@ The default `solr.xml` file is found in `$SOLR_TIP/server/solr/solr.xml` and loo<str name="modules">${solr.modules:}</str><str name="allowPaths">${solr.security.allow.paths:}</str><str name="allowUrls">${solr.security.allow.urls:}</str>+ <str name="allowZkHosts">${solr.security.allow.zk.hosts:}</str><str name="hideStackTrace">${solr.hideStackTrace:false}</str><solrcloud>@@ -273,6 +274,24 @@ In SolrCloud mode, the allow-list is automatically configured to include all livThe allow-list can also be configured with the `solr.security.allow.urls` system property in `solr.in.sh` / `solr.in.cmd`.If you need to disable this feature for backwards compatibility, you can set the system property `solr.security.allow.urls.enabled=false`.+[#allow-zk-hosts]+`allowZkHosts`::+++[%autowidth,frame=none]+|===+|Optional |Default: none+|===+++Comma-separated list of ZooKeeper connection strings of other SolrCloud clusters that may be passed as a `zkHost` (or ZooKeeper-based `solrConnection`) parameter to features that fetch data from another cluster, such as cross-collection join and streaming expressions.+The local SolrCloud ZooKeeper ensemble is always allowed and need not be listed.+Solr in standalone (non-SolrCloud) mode does not allow any `zkHost`.+++Matching is character-for-character against the full connection string -- e.g. `zk1:2181,zk2:2181,zk3:2181/solr` is a different value from `zk1:2181,zk2:2181,zk3:2181` or from the same hosts in a different order.+The local ensemble's value includes any chroot suffix configured at startup: if Solr was started with `-DzkHost=zk1:2181/solr`, then `zkHost="zk1:2181/solr"` is allowed but `zkHost="zk1:2181"` is not unless listed.+A value that is not allowed is rejected with an error mentioning `allowZkHosts`.+++The allow-list can also be configured with the `solr.security.allow.zk.hosts` system property in `solr.in.sh` / `solr.in.cmd`.+`hideStackTrace`::+[%autowidth,frame=none]diff --git a/solr/solr-ref-guide/modules/query-guide/pages/join-query-parser.adoc b/solr/solr-ref-guide/modules/query-guide/pages/join-query-parser.adocindex e62ec8b8614..bd0f80d2914 100644--- a/solr/solr-ref-guide/modules/query-guide/pages/join-query-parser.adoc+++ b/solr/solr-ref-guide/modules/query-guide/pages/join-query-parser.adoc@@ -288,6 +288,13 @@ This restriction is necessary to prevent an attacker from using Solr to explore</queryParser>----+[NOTE]+====+The `zkHost` parameter is governed by a node-level allow-list in `solr.xml` (`<str name="allowZkHosts">`), *not* by `solrconfig.xml`.+The local SolrCloud ZooKeeper ensemble is always trusted -- only remote ensembles need to be listed.+See <<Cross Collection Join Query Parameters>> below and the `solr.xml` reference for details.+====+=== Cross Collection Join Query Parameters`fromIndex`::@@ -309,6 +316,9 @@ The name of the external Solr collection to be queried to retrieve the set of joThe connection string to be used to connect to SolrCloud cluster via ZooKeeper or HTTP(s).`solrConnection`, `zkHost` and `solrUrl` are optional parameters, and at most one of them should be specified.If neither `solrConnection`, `zkHost` nor `solrUrl` are specified, the local ZooKeeper cluster will be used.+++A ZooKeeper connection string is validated like `zkHost` below.+An HTTP(s) connection string must be a live node of the local cluster or be listed in the `allowUrls` entry in `solr.xml`; otherwise the request is rejected.`zkHost`::+@@ -318,9 +328,14 @@ If neither `solrConnection`, `zkHost` nor `solrUrl` are specified, the local Zoo|===+The connection string to be used to connect to ZooKeeper.-`zkHost` and `solrUrl` are both optional parameters, and at most one of them should be specified.+`zkHost` and `solrUrl` are both optional parameters, and at most one of them may be specified; passing both is rejected.If neither `zkHost` nor `solrUrl` are specified, the local ZooKeeper cluster will be used.This parameter is deprecated. Use `solrConnection` instead.+++An explicit `zkHost` value must either match the local SolrCloud ensemble verbatim or be listed verbatim in the node-level `<str name="allowZkHosts">` entry in `solr.xml`.+The match is a character-for-character exact comparison of the full connection string -- e.g. `zk1:2181,zk2:2181,zk3:2181/solr` is a different value from `zk1:2181,zk2:2181,zk3:2181` or from the same hosts in a different order.+The local value includes any chroot suffix configured at startup -- so for a node started with `-DzkHost=zk1:2181/solr`, `zkHost="zk1:2181/solr"` is allowed while `zkHost="zk1:2181"` is not.+If the value does not match, the request is rejected with a `SyntaxError`.`solrUrl`::+diff --git a/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-10.adoc b/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-10.adocindex cfa96a93865..f36c6ca7c2c 100644--- a/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-10.adoc+++ b/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-10.adoc@@ -66,6 +66,16 @@ The universal connection string is now supported in the following components and* Updated Solr CLI `-s` short option to invoke `--solr-connection` instead of `--solr-url`, which is a backwards compatible change.* Added `solrConnection` parameter to the Join Query Parser.+=== Connecting to Other Clusters++Streaming expressions and the cross-collection join query parser now restrict which SolrCloud clusters a `zkHost` or `solrConnection` parameter may refer to:++* A ZooKeeper connection string must match the local cluster's exactly (including any chroot), or be listed in the new xref:configuration-guide:configuring-solr-xml.adoc#allow-zk-hosts[`allowZkHosts`] setting in `solr.xml` (or the `solr.security.allow.zk.hosts` system property).+* An HTTP(S) connection string must refer to live nodes of the local cluster, or to hosts listed in xref:configuration-guide:configuring-solr-xml.adoc#allow-urls[`allowUrls`].+* The cross-collection join query parser no longer accepts both `zkHost` and `solrUrl`; specify at most one.++If you use these features to query another cluster, add its connection details to the corresponding setting before upgrading.+=== v2 APIStarting in Solr 10.1 it is no longer possible for users to disable the v2 API by use of the `solr.api.v2.enabled` system property, and the Solr server and tooling (`bin/solr`, Admin UI, etc.) will start using these APIs internally.diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/SolrClientCache.javaindex b2e698c3cd3..89a89ea9eb6 100644--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java@@ -24,6 +24,7 @@ import java.util.Optional;import java.util.concurrent.TimeUnit;import java.util.concurrent.atomic.AtomicBoolean;import java.util.concurrent.atomic.AtomicReference;+import java.util.function.Consumer;import org.apache.solr.client.solrj.SolrClient;import org.apache.solr.client.solrj.impl.CloudSolrClient;import org.apache.solr.client.solrj.impl.HttpSolrClient;@@ -52,6 +53,7 @@ public class SolrClientCache implements Closeable {private final HttpSolrClient httpSolrClient;private final AtomicBoolean isClosed = new AtomicBoolean(false);private final AtomicReference<String> defaultZkHost = new AtomicReference<>();+ private volatile Consumer<CloudSolrClient.CloudSolrClientConnection> connectionValidator;public SolrClientCache() {this.httpSolrClient = null;@@ -65,6 +67,37 @@ public class SolrClientCache implements Closeable {this.basicAuthCredentials = basicAuthCredentials;}+ /**+ * Installs a connection validator that {@link+ * #getCloudSolrClient(CloudSolrClient.CloudSolrClientConnection)} consults on every call, before+ * any ZK or HTTP contact. The validator rejects a connection by throwing, typically a {@code 403+ * Forbidden} {@link org.apache.solr.common.SolrException}. A {@code null} validator disables+ * validation.+ *+ * <p>The validator is invoked while holding the cache monitor, so it must be non-blocking and+ * must not perform I/O.+ */+ public void setConnectionValidator(+ Consumer<CloudSolrClient.CloudSolrClientConnection> connectionValidator) {+ this.connectionValidator = connectionValidator;+ }++ /** Throws if the installed validator rejects the connection. */+ public void validateConnection(CloudSolrClient.CloudSolrClientConnection solrConnection) {+ var validator = connectionValidator;+ if (validator != null) {+ validator.accept(solrConnection);+ }+ }++ /** Message for a rejected ZooKeeper connection string. */+ public static String zkHostRejectionMessage(String connectionString) {+ return "ZooKeeper host '"+ + connectionString+ + "' is not on the 'allowZkHosts' allow-list in solr.xml and does not match the local"+ + " cluster's ZK ensemble.";+ }+public void setDefaultZKHost(String zkHost) {if (zkHost != null) {zkHost = zkHost.split("/")[0];@@ -88,6 +121,8 @@ public class SolrClientCache implements Closeable {public synchronized CloudSolrClient getCloudSolrClient(CloudSolrClient.CloudSolrClientConnection solrConnection) {ensureOpen();+ // before the cache lookup, so cached clients are also subject to the validator+ validateConnection(solrConnection);return cloudSolClients.computeIfAbsent(solrConnection, sc -> newCloudSolrClient(sc, httpSolrClient, useAclForZookeeper(sc)));}diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/TupleStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/TupleStream.javaindex 3dc3ceb6f78..1b94038d482 100644--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/TupleStream.java+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/TupleStream.java@@ -150,6 +150,8 @@ public abstract class TupleStream implements Closeable, Serializable, MapWriterlocalSolrClientCache; // tracks any locally allocated cache that needs to be closed locallyif (solrClientCache== null) { // streamContext was null OR streamContext.getSolrClientCache() returned null+ // Note: this cache doesn't validate connections. Within Solr, callers (StreamHandler,+ // CrossCollectionJoinQuery) supply CoreContainer's cache via the StreamContext.solrClientCache = localSolrClientCache = new SolrClientCache();} else {localSolrClientCache = null;