diff --git a/core/src/main/java/org/elasticsearch/action/search/RemoteClusterService.java b/core/src/main/java/org/elasticsearch/action/search/RemoteClusterService.java index aa443b0766ba4..45e3fc5bc0bd5 100644 --- a/core/src/main/java/org/elasticsearch/action/search/RemoteClusterService.java +++ b/core/src/main/java/org/elasticsearch/action/search/RemoteClusterService.java @@ -98,6 +98,14 @@ public final class RemoteClusterService extends AbstractComponent implements Clo public static final Setting REMOTE_NODE_ATTRIBUTE = Setting.simpleString("search.remote.node.attr", Setting.Property.NodeScope); + /** + * If true connecting to remote clusters is supported on this node. If false this node will not establish + * connections to any remote clusters configured. Search requests executed against this node (where this node is the coordinating node) + * will fail if remote cluster syntax is used as an index pattern. The default is true + */ + public static final Setting ENABLE_REMOTE_CLUSTERS = Setting.boolSetting("search.remote.connect", true, + Setting.Property.NodeScope); + private static final char REMOTE_CLUSTER_INDEX_SEPARATOR = ':'; private final TransportService transportService; diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchTransportService.java b/core/src/main/java/org/elasticsearch/action/search/SearchTransportService.java index 6cd9e559aa145..4c4372d57495a 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchTransportService.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchTransportService.java @@ -79,13 +79,18 @@ public class SearchTransportService extends AbstractLifecycleComponent { private final TransportService transportService; private final RemoteClusterService remoteClusterService; + private final boolean connectToRemote; public SearchTransportService(Settings settings, ClusterSettings clusterSettings, TransportService transportService) { super(settings); + this.connectToRemote = RemoteClusterService.ENABLE_REMOTE_CLUSTERS.get(settings); this.transportService = transportService; this.remoteClusterService = new RemoteClusterService(settings, transportService); - clusterSettings.addAffixUpdateConsumer(RemoteClusterService.REMOTE_CLUSTERS_SEEDS, remoteClusterService::updateRemoteCluster, - (namespace, value) -> {}); + if (connectToRemote) { + clusterSettings.addAffixUpdateConsumer(RemoteClusterService.REMOTE_CLUSTERS_SEEDS, remoteClusterService::updateRemoteCluster, + (namespace, value) -> { + }); + } } public void sendFreeContext(Transport.Connection connection, final long contextId, SearchRequest request) { @@ -390,8 +395,10 @@ Transport.Connection getConnection(DiscoveryNode node) { @Override protected void doStart() { - // here we start to connect to the remote clusters - remoteClusterService.initializeRemoteClusters(); + if (connectToRemote) { + // here we start to connect to the remote clusters + remoteClusterService.initializeRemoteClusters(); + } } @Override diff --git a/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java b/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java index 64b09adb43411..5f7466f4ddae8 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java +++ b/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java @@ -266,6 +266,7 @@ public void apply(Settings value, Settings current, Settings previous) { RemoteClusterService.REMOTE_CONNECTIONS_PER_CLUSTER, RemoteClusterService.REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING, RemoteClusterService.REMOTE_NODE_ATTRIBUTE, + RemoteClusterService.ENABLE_REMOTE_CLUSTERS, TransportService.TRACE_LOG_EXCLUDE_SETTING, TransportService.TRACE_LOG_INCLUDE_SETTING, TransportCloseIndexAction.CLUSTER_INDICES_CLOSE_ENABLE_SETTING, diff --git a/docs/reference/modules/cross-cluster-search.asciidoc b/docs/reference/modules/cross-cluster-search.asciidoc index 1fa2693678ead..e1b6d86eda385 100644 --- a/docs/reference/modules/cross-cluster-search.asciidoc +++ b/docs/reference/modules/cross-cluster-search.asciidoc @@ -128,3 +128,10 @@ will be prefixed with their remote cluster name: `node.attr.gateway: true` such that only nodes with this attribute will be connected to if `search.remote.node.attr` is set to `gateway`. +`search.remote.connect`:: + By default, any node in the cluster can act as a cross-cluster client and connect to remote clusters. + The `search.remote.connect` setting can be set to `false` (defaults to `true`) to prevent certain nodes from + connecting to remote clusters. Cross-cluster search requests must be sent to a node that is allowed to act as a + cross-cluster client. + + diff --git a/qa/multi-cluster-search/build.gradle b/qa/multi-cluster-search/build.gradle index b48cd9a3dd1e3..385c547cf6dea 100644 --- a/qa/multi-cluster-search/build.gradle +++ b/qa/multi-cluster-search/build.gradle @@ -27,6 +27,7 @@ task remoteClusterTest(type: RestIntegTestTask) { distribution = 'zip' numNodes = 2 clusterName = 'remote-cluster' + setting 'search.remote.connect', false } systemProperty 'tests.rest.suite', 'remote_cluster' } @@ -37,7 +38,7 @@ task mixedClusterTest(type: RestIntegTestTask) { distribution = 'zip' setting 'search.remote.my_remote_cluster.seeds', "\"${-> remoteClusterTest.nodes.get(0).transportUri()}\"" setting 'search.remote.connections_per_cluster', 1 - + setting 'search.remote.connect', true } systemProperty 'tests.rest.suite', 'multi_cluster' finalizedBy 'remoteClusterTest#node0.stop','remoteClusterTest#node1.stop'