Skip to content

Commit e88cb33

Browse files
Disable cross-cluster functionality for _fleet/_fleet_msearch (elastic#136703)
Disable cross-cluster functionality for `_fleet/_fleet_msearch`
1 parent 9013e0d commit e88cb33

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

docs/changelog/136703.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
pr: 136703
2+
summary: Disable cross-cluster functionality for `_fleet/_fleet_msearch`
3+
area: Search
4+
type: breaking
5+
issues: []
6+
breaking:
7+
title: Disable cross-cluster functionality for `_fleet/_fleet_msearch`
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

x-pack/plugin/fleet/src/internalClusterTest/java/org/elasticsearch/xpack/fleet/action/FleetSearchRemoteIndicesDisallowedIT.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,56 @@ public void testEndpointsShouldRejectRemoteIndices() {
4141
Matchers.containsString("Fleet search API does not support remote indices. Found: [" + remoteIndex + "]")
4242
);
4343
}
44+
45+
{
46+
Request request = new Request("POST", "/" + remoteIndex + "/_fleet/_fleet_msearch");
47+
request.setJsonEntity("{}\n{}\n");
48+
ResponseException responseException = expectThrows(ResponseException.class, () -> getRestClient().performRequest(request));
49+
assertThat(
50+
responseException.getMessage(),
51+
Matchers.containsString("Fleet search API does not support remote indices. Found: [" + remoteIndex + "]")
52+
);
53+
}
54+
55+
{
56+
/*
57+
* It is possible, however, to sneak in multiple indices and a remote index if checkpoints are not specified.
58+
* Unfortunately, that's the current behaviour and the Fleet team does not want us to touch it.
59+
*/
60+
Request request = new Request("POST", "/foo,bar:baz/_fleet/_fleet_msearch");
61+
request.setJsonEntity("{}\n{}\n");
62+
try {
63+
getRestClient().performRequest(request);
64+
} catch (Exception e) {
65+
throw new AssertionError(e);
66+
}
67+
}
68+
69+
{
70+
// This is fine, there are no remote indices.
71+
Request request = new Request("POST", "/foo/_fleet/_fleet_msearch");
72+
request.setJsonEntity("{\"index\": \"bar*\"}\n{}\n");
73+
try {
74+
getRestClient().performRequest(request);
75+
} catch (Exception e) {
76+
throw new AssertionError(e);
77+
}
78+
}
79+
80+
{
81+
// This is not valid. We shouldn't be passing multiple indices.
82+
Request request = new Request("POST", "/foo/_fleet/_fleet_msearch");
83+
request.setJsonEntity("{\"index\": \"bar,baz\", \"wait_for_checkpoints\": 1 }\n{}\n");
84+
ResponseException responseException = expectThrows(ResponseException.class, () -> getRestClient().performRequest(request));
85+
assertThat(responseException.getMessage(), Matchers.containsString("Fleet search API only supports searching a single index."));
86+
}
87+
88+
{
89+
// This is not valid. We shouldn't be passing remote indices.
90+
Request request = new Request("POST", "/foo/_fleet/_fleet_msearch");
91+
request.setJsonEntity("{\"index\": \"bar:baz\", \"wait_for_checkpoints\": 1 }\n{}\n");
92+
ResponseException responseException = expectThrows(ResponseException.class, () -> getRestClient().performRequest(request));
93+
assertThat(responseException.getMessage(), Matchers.containsString("Fleet search API does not support remote indices. Found:"));
94+
}
4495
}
4596
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.elasticsearch.rest.action.RestRefCountedChunkedToXContentListener;
2323
import org.elasticsearch.rest.action.search.RestMultiSearchAction;
2424
import org.elasticsearch.rest.action.search.RestSearchAction;
25+
import org.elasticsearch.transport.RemoteClusterService;
2526
import org.elasticsearch.usage.SearchUsageHolder;
2627

2728
import java.io.IOException;
@@ -112,6 +113,10 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
112113
);
113114
}
114115
}
116+
117+
if (indices.length == 1 && RemoteClusterService.isRemoteIndexName(indices[0])) {
118+
throw new IllegalArgumentException("Fleet search API does not support remote indices. Found: [" + indices[0] + "].");
119+
}
115120
long[] checkpoints = searchRequest.getWaitForCheckpoints().get("*");
116121
if (checkpoints != null) {
117122
searchRequest.setWaitForCheckpoints(Collections.singletonMap(indices[0], checkpoints));

0 commit comments

Comments
 (0)