Skip to content

Commit d9405fb

Browse files
Disable cross-cluster functionality for _fleet/_fleet_search (#136039)
As part of the CPS requirement S2D47, this PR disables cross-cluster functionality for the `_fleet/_fleet_search` endpoint.
1 parent de74536 commit d9405fb

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

docs/changelog/136039.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
pr: 136039
2+
summary: Disable cross-cluster functionality for `_fleet/_fleet_search`
3+
area: Search
4+
type: breaking
5+
issues: []
6+
breaking:
7+
title: Disable cross-cluster functionality for `_fleet/_fleet_search`
8+
area: Search
9+
details: |-
10+
This endpoint is largely used for local searches only and is not compatible with true cross-cluster searches where
11+
arbitrary number of indices and remotes can be specified. Although it is meant to accept an index parameter that
12+
denotes a single searchable target, such a limitation can be bypassed through various means.
13+
14+
Keeping in view this endpoint's stated intent and future scope, cross-cluster functionality is being explicitly disabled.
15+
impact: |-
16+
This endpoint will no longer accept remote indices. Should one be provided, a top-level error is returned with
17+
an appropriate explanation.
18+
notable: false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.fleet.action;
9+
10+
import org.elasticsearch.client.Request;
11+
import org.elasticsearch.client.ResponseException;
12+
import org.elasticsearch.plugins.Plugin;
13+
import org.elasticsearch.test.ESIntegTestCase;
14+
import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin;
15+
import org.elasticsearch.xpack.fleet.Fleet;
16+
import org.elasticsearch.xpack.ilm.IndexLifecycle;
17+
import org.hamcrest.Matchers;
18+
19+
import java.util.Collection;
20+
import java.util.stream.Collectors;
21+
import java.util.stream.Stream;
22+
23+
public class FleetSearchRemoteIndicesDisallowedIT extends ESIntegTestCase {
24+
@Override
25+
protected boolean addMockHttpTransport() {
26+
return false;
27+
}
28+
29+
@Override
30+
protected Collection<Class<? extends Plugin>> nodePlugins() {
31+
return Stream.of(Fleet.class, LocalStateCompositeXPackPlugin.class, IndexLifecycle.class).collect(Collectors.toList());
32+
}
33+
34+
public void testEndpointsShouldRejectRemoteIndices() {
35+
String remoteIndex = randomAlphaOfLength(randomIntBetween(2, 10)) + ":" + randomAlphaOfLength(randomIntBetween(2, 10));
36+
{
37+
Request request = new Request("GET", "/" + remoteIndex + "/_fleet/_fleet_search");
38+
ResponseException responseException = expectThrows(ResponseException.class, () -> getRestClient().performRequest(request));
39+
assertThat(
40+
responseException.getMessage(),
41+
Matchers.containsString("Fleet search API does not support remote indices. Found: [" + remoteIndex + "]")
42+
);
43+
}
44+
}
45+
}

x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/rest/RestFleetSearchAction.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.elasticsearch.rest.action.RestCancellableNodeClient;
2121
import org.elasticsearch.rest.action.RestRefCountedChunkedToXContentListener;
2222
import org.elasticsearch.rest.action.search.RestSearchAction;
23+
import org.elasticsearch.transport.RemoteClusterService;
2324
import org.elasticsearch.usage.SearchUsageHolder;
2425

2526
import java.io.IOException;
@@ -82,6 +83,9 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
8283
"Fleet search API only supports searching a single index. Found: [" + Arrays.toString(indices1) + "]."
8384
);
8485
}
86+
if (RemoteClusterService.isRemoteIndexName(indices1[0])) {
87+
throw new IllegalArgumentException("Fleet search API does not support remote indices. Found: [" + indices1[0] + "].");
88+
}
8589
if (waitForCheckpoints.length != 0) {
8690
searchRequest.setWaitForCheckpoints(Collections.singletonMap(indices1[0], waitForCheckpoints));
8791
}

0 commit comments

Comments
 (0)