Skip to content

Commit b4d8e1b

Browse files
Disable cross-cluster functionality for _fleet/_fleet_msearch
1 parent d9405fb commit b4d8e1b

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,43 @@ 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+
// This is fine, there are no remote indices.
57+
Request request = new Request("POST", "/foo/_fleet/_fleet_msearch");
58+
request.setJsonEntity("{\"index\": \"bar*\"}\n{}\n");
59+
try {
60+
getRestClient().performRequest(request);
61+
} catch (Exception r) {
62+
throw new AssertionError(r);
63+
}
64+
}
65+
66+
{
67+
// This is not valid. We shouldn't be passing multiple indices.
68+
Request request = new Request("POST", "/foo/_fleet/_fleet_msearch");
69+
request.setJsonEntity("{\"index\": \"bar*,baz\"}\n{}\n");
70+
71+
ResponseException responseException = expectThrows(ResponseException.class, () -> getRestClient().performRequest(request));
72+
assertThat(responseException.getMessage(), Matchers.containsString("Fleet search API only supports searching a single index."));
73+
}
74+
75+
{
76+
// This is not valid. We shouldn't be passing remote indices.
77+
Request request = new Request("POST", "/foo/_fleet/_fleet_msearch");
78+
request.setJsonEntity("{\"index\": \"bar*\"}\n{}\n{\"index\": \"remote:index\"}\n{}\n");
79+
ResponseException responseException = expectThrows(ResponseException.class, () -> getRestClient().performRequest(request));
80+
assertThat(responseException.getMessage(), Matchers.containsString("Fleet search API does not support remote indices. Found:"));
81+
}
4482
}
4583
}

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

Lines changed: 10 additions & 4 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;
@@ -106,12 +107,17 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
106107
"Fleet search API param wait_for_checkpoints is only supported with an index to search specified. "
107108
+ "No index specified."
108109
);
109-
} else if (indices.length > 1) {
110-
throw new IllegalArgumentException(
111-
"Fleet search API only supports searching a single index. Found: [" + Arrays.toString(indices) + "]."
112-
);
113110
}
114111
}
112+
if (indices.length > 1) {
113+
throw new IllegalArgumentException(
114+
"Fleet search API only supports searching a single index. Found: [" + Arrays.toString(indices) + "]."
115+
);
116+
}
117+
118+
if (RemoteClusterService.isRemoteIndexName(indices[0])) {
119+
throw new IllegalArgumentException("Fleet search API does not support remote indices. Found: [" + indices[0] + "].");
120+
}
115121
long[] checkpoints = searchRequest.getWaitForCheckpoints().get("*");
116122
if (checkpoints != null) {
117123
searchRequest.setWaitForCheckpoints(Collections.singletonMap(indices[0], checkpoints));

0 commit comments

Comments
 (0)