Skip to content

Commit 83173fe

Browse files
All system indices are hidden indices (#79512) (#81388)
System indices should be hidden from users. Since they are already restricted indices, a users that can't view restricted indices already can't see or access them, but they should also be hidden for superusers or users that are otherwise granted advanced privileges. To the greatest degree possible, we apply hidden settings in the transport layer, so that the system can create an index or alias that is set to visible, for example, when operating in a mixed cluster mode. However, in the case of aliases created by templates, we hide the alias in the service layer. This change has broken a number of tests that were relaying unnecessarily on wildcard searches. In general, the fix for these issues was to apply expand_wildcards=open,hidden to the request. * Force system indices to be hidden in IndexMetadata * Hide system data streams * Update feature migration tests * ML datafeed config defaults to searching hidden indices * Prevent unmanaged system indices from becoming visible * Change validation in TransportUpdateSettingsAction * Validate index creation settings in transport action * Make sure system data stream backing indices are hidden * Make sure transport request adds hidden index setting if missing * Validate and set default for autocreated system indices * Add some code to hide system aliases * Hide system aliases in create index service * Hide system aliases when adding them via alias endpoints * Check system indices when simulating and validating templates * Add known issue for reenabling tests * Update docs/changelog/79512.yaml
1 parent e443c7e commit 83173fe

File tree

43 files changed

+1069
-116
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1069
-116
lines changed

docs/changelog/79512.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 79512
2+
summary: All system indices are hidden indices
3+
area: Infra/Core
4+
type: enhancement
5+
issues: []

modules/kibana/src/javaRestTest/java/org/elasticsearch/kibana/KibanaSystemIndexIT.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.apache.http.util.EntityUtils;
1515
import org.elasticsearch.client.Request;
1616
import org.elasticsearch.client.Response;
17+
import org.elasticsearch.client.ResponseException;
1718
import org.elasticsearch.common.xcontent.XContentHelper;
1819
import org.elasticsearch.test.rest.ESRestTestCase;
1920
import org.elasticsearch.xcontent.json.JsonXContent;
@@ -218,6 +219,27 @@ public void testUpdateIndexSettings() throws IOException {
218219
assertThat(response.getStatusLine().getStatusCode(), is(200));
219220
}
220221

222+
public void testCannotCreateVisibleSystemIndex() {
223+
Request request = request("PUT", "/" + indexName);
224+
request.setJsonEntity("{\"settings\": {\"index.hidden\":\"false\"}}");
225+
ResponseException exception = expectThrows(ResponseException.class, () -> client().performRequest(request));
226+
assertThat(
227+
exception.getMessage(),
228+
containsString("Cannot create system index [" + indexName + "] with [index.hidden] set to 'false'")
229+
);
230+
}
231+
232+
public void testCannotSetVisible() throws IOException {
233+
Request putIndexRequest = request("PUT", "/" + indexName);
234+
Response response = client().performRequest(putIndexRequest);
235+
assertThat(response.getStatusLine().getStatusCode(), is(200));
236+
237+
Request putSettingsRequest = request("PUT", "/" + indexName + "/_settings");
238+
putSettingsRequest.setJsonEntity("{ \"index.hidden\" : false }");
239+
ResponseException exception = expectThrows(ResponseException.class, () -> client().performRequest(putSettingsRequest));
240+
assertThat(exception.getMessage(), containsString("Cannot set [index.hidden] to 'false' on system indices: [" + indexName + "]"));
241+
}
242+
221243
public void testGetIndex() throws IOException {
222244
Request request = request("PUT", "/" + indexName);
223245
Response response = client().performRequest(request);

modules/reindex/build.gradle

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,18 @@ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
159159
tasks.named("yamlRestTestV7CompatTransform").configure { task ->
160160
task.skipTest("reindex/20_validation/reindex without source gives useful error message", "exception with a type. Not much benefit adding _doc there.")
161161
task.skipTest("update_by_query/20_validation/update_by_query without source gives useful error message", "exception with a type. Not much benefit adding _doc there.")
162+
163+
// these tests are all relying on a call to refresh all indices, when they could easily be changed
164+
// in 7.x to call the specific index they want to refresh.
165+
// See https://github.com/elastic/elasticsearch/issues/81188
166+
task.skipTest("delete_by_query/70_throttle/Rethrottle to -1 which turns off throttling", "test relies on system index being non-hidden")
167+
task.skipTest("delete_by_query/80_slices/Multiple slices with rethrottle", "test relies on system index being non-hidden")
168+
task.skipTest("delete_by_query/80_slices/Multiple slices with wait_for_completion=false", "test relies on system index being non-hidden")
169+
task.skipTest("reindex/80_slices/Multiple slices with rethrottle", "test relies on system index being non-hidden")
170+
task.skipTest("reindex/80_slices/Multiple slices with wait_for_completion=false", "test relies on system index being non-hidden")
171+
task.skipTest("update_by_query/70_slices/Multiple slices with rethrottle", "test relies on system index being non-hidden")
172+
task.skipTest("update_by_query/70_slices/Multiple slices with wait_for_completion=false", "test relies on system index being non-hidden")
173+
162174
task.addAllowedWarningRegex("\\[types removal\\].*")
163175
}
164176

modules/reindex/src/internalClusterTest/java/org/elasticsearch/migration/FeatureMigrationIT.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,20 +299,22 @@ public void createSystemIndexForDescriptor(SystemIndexDescriptor descriptor) thr
299299
String indexName = Optional.ofNullable(descriptor.getPrimaryIndex()).orElse(descriptor.getIndexPattern().replace("*", "old"));
300300
CreateIndexRequestBuilder createRequest = prepareCreate(indexName);
301301
createRequest.setWaitForActiveShards(ActiveShardCount.ALL);
302-
if (descriptor.getSettings() != null) {
303-
createRequest.setSettings(
304-
Settings.builder()
305-
.put("index.version.created", Version.CURRENT)
306-
.put(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0)
307-
.build()
308-
);
309-
} else {
302+
if (SystemIndexDescriptor.DEFAULT_SETTINGS.equals(descriptor.getSettings())) {
303+
// unmanaged
310304
createRequest.setSettings(
311305
createSimpleSettings(
312306
NEEDS_UPGRADE_VERSION,
313307
descriptor.isInternal() ? INTERNAL_UNMANAGED_FLAG_VALUE : EXTERNAL_UNMANAGED_FLAG_VALUE
314308
)
315309
);
310+
} else {
311+
// managed
312+
createRequest.setSettings(
313+
Settings.builder()
314+
.put("index.version.created", Version.CURRENT)
315+
.put(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0)
316+
.build()
317+
);
316318
}
317319
if (descriptor.getMappings() == null) {
318320
createRequest.setMapping(createSimpleMapping(false, descriptor.isInternal()));

modules/reindex/src/yamlRestTest/resources/rest-api-spec/test/delete_by_query/70_throttle.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@
124124
task_id: $task
125125

126126
- do:
127-
warnings:
128-
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"
129127
indices.refresh: {}
130128

131129
- do:

modules/reindex/src/yamlRestTest/resources/rest-api-spec/test/delete_by_query/80_slices.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@
155155
- do:
156156
warnings:
157157
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"
158-
indices.refresh: {}
158+
indices.refresh:
159+
expand_wildcards: "open,hidden"
159160
- do:
160161
warnings:
161162
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"
@@ -270,7 +271,8 @@
270271
- do:
271272
warnings:
272273
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"
273-
indices.refresh: {}
274+
indices.refresh:
275+
expand_wildcards: "open,hidden"
274276
- do:
275277
warnings:
276278
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"

modules/reindex/src/yamlRestTest/resources/rest-api-spec/test/reindex/80_slices.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@
164164
- do:
165165
warnings:
166166
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"
167-
indices.refresh: {}
167+
indices.refresh:
168+
expand_wildcards: "open,hidden"
168169
- do:
169170
warnings:
170171
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"
@@ -282,7 +283,8 @@
282283
- do:
283284
warnings:
284285
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"
285-
indices.refresh: {}
286+
indices.refresh:
287+
expand_wildcards: "open,hidden"
286288
- do:
287289
warnings:
288290
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"

modules/reindex/src/yamlRestTest/resources/rest-api-spec/test/update_by_query/70_slices.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@
147147
- do:
148148
warnings:
149149
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"
150-
indices.refresh: {}
150+
indices.refresh:
151+
expand_wildcards: "open,hidden"
151152
- do:
152153
warnings:
153154
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"
@@ -256,7 +257,8 @@
256257
- do:
257258
warnings:
258259
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"
259-
indices.refresh: {}
260+
indices.refresh:
261+
expand_wildcards: "open,hidden"
260262
- do:
261263
warnings:
262264
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"

qa/smoke-test-http/src/test/java/org/elasticsearch/http/SystemIndexRestIT.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.elasticsearch.client.Request;
1515
import org.elasticsearch.client.RequestOptions;
1616
import org.elasticsearch.client.Response;
17+
import org.elasticsearch.client.ResponseException;
1718
import org.elasticsearch.client.node.NodeClient;
1819
import org.elasticsearch.cluster.metadata.IndexMetadata;
1920
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
@@ -45,6 +46,7 @@
4546
import static org.elasticsearch.rest.RestRequest.Method.POST;
4647
import static org.elasticsearch.test.rest.ESRestTestCase.entityAsMap;
4748
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
49+
import static org.hamcrest.Matchers.containsString;
4850
import static org.hamcrest.Matchers.equalTo;
4951
import static org.hamcrest.Matchers.hasKey;
5052
import static org.hamcrest.Matchers.is;
@@ -92,6 +94,17 @@ public void testSystemIndexAccessBlockedByDefault() throws Exception {
9294
// And with a total wildcard
9395
assertDeprecationWarningOnAccess(randomFrom("*", "_all"), SystemIndexTestPlugin.SYSTEM_INDEX_NAME);
9496

97+
// If we're not expanding wildcards, we don't get anything
98+
{
99+
Request searchRequest = new Request("GET", "/" + randomFrom("*", "_all") + randomFrom("/_count", "/_search"));
100+
searchRequest.setJsonEntity("{\"query\": {\"match\": {\"some_field\": \"some_value\"}}}");
101+
searchRequest.addParameter("allow_no_indices", "false");
102+
103+
ResponseException exception = expectThrows(ResponseException.class, () -> getRestClient().performRequest(searchRequest));
104+
assertThat(exception.getResponse().getStatusLine().getStatusCode(), equalTo(404));
105+
assertThat(exception.getMessage(), containsString("no such index"));
106+
}
107+
95108
// Try to index a doc directly
96109
{
97110
String expectedWarning = "this request accesses system indices: ["
@@ -115,6 +128,7 @@ private void assertDeprecationWarningOnAccess(String queryPattern, String warnin
115128
searchRequest.setJsonEntity("{\"query\": {\"match\": {\"some_field\": \"some_value\"}}}");
116129
// Disallow no indices to cause an exception if this resolves to zero indices, so that we're sure it resolved the index
117130
searchRequest.addParameter("allow_no_indices", "false");
131+
searchRequest.addParameter("expand_wildcards", "open,hidden");
118132
searchRequest.setOptions(expectWarnings(expectedWarning));
119133

120134
Response response = getRestClient().performRequest(searchRequest);

0 commit comments

Comments
 (0)