Skip to content

Commit 2ceb42d

Browse files
committed
Correctly ignore system indices when validationg dot-prefixed indices
Prior to this change, the (incorrect) assumption was that `threadContext.isSystemContext()` returned true when dealing with system indices. This was eventually revealed to be false (though there is a separate issue where we aren't emitting deprecation warnings when running locally, but that is a separate thing). To fix this, the `DotPrefixValidator` now correctly receives a `SystemIndices` instance and uses the `findMatchingDescriptor` and `findMatchingDataStreamDescriptor` methods to determine whether a system index is being referenced. When a matching descriptor is found, the warning emission is skipped.
1 parent 637c7e7 commit 2ceb42d

File tree

8 files changed

+44
-12
lines changed

8 files changed

+44
-12
lines changed

modules/dot-prefix-validation/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ esplugin {
1616

1717
restResources {
1818
restApi {
19-
include '_common', 'indices', 'index', 'cluster', 'nodes', 'get', 'ingest', 'bulk', 'reindex'
19+
include '_common', 'indices', 'index', 'cluster', 'nodes', 'get', 'ingest', 'bulk', 'reindex', 'async_search'
2020
}
2121
}
2222

modules/dot-prefix-validation/src/main/java/org/elasticsearch/validation/AutoCreateDotValidator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
1414
import org.elasticsearch.cluster.service.ClusterService;
1515
import org.elasticsearch.common.util.concurrent.ThreadContext;
16+
import org.elasticsearch.indices.SystemIndices;
1617

1718
import java.util.Set;
1819

1920
public class AutoCreateDotValidator extends DotPrefixValidator<CreateIndexRequest> {
20-
public AutoCreateDotValidator(ThreadContext threadContext, ClusterService clusterService) {
21-
super(threadContext, clusterService);
21+
public AutoCreateDotValidator(ThreadContext threadContext, ClusterService clusterService, SystemIndices systemIndices) {
22+
super(threadContext, clusterService, systemIndices);
2223
}
2324

2425
@Override

modules/dot-prefix-validation/src/main/java/org/elasticsearch/validation/CreateIndexDotValidator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
import org.elasticsearch.action.admin.indices.create.TransportCreateIndexAction;
1414
import org.elasticsearch.cluster.service.ClusterService;
1515
import org.elasticsearch.common.util.concurrent.ThreadContext;
16+
import org.elasticsearch.indices.SystemIndices;
1617

1718
import java.util.Set;
1819

1920
public class CreateIndexDotValidator extends DotPrefixValidator<CreateIndexRequest> {
20-
public CreateIndexDotValidator(ThreadContext threadContext, ClusterService clusterService) {
21-
super(threadContext, clusterService);
21+
public CreateIndexDotValidator(ThreadContext threadContext, ClusterService clusterService, SystemIndices systemIndices) {
22+
super(threadContext, clusterService, systemIndices);
2223
}
2324

2425
@Override

modules/dot-prefix-validation/src/main/java/org/elasticsearch/validation/DotPrefixValidationPlugin.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.elasticsearch.cluster.service.ClusterService;
1414
import org.elasticsearch.common.settings.Setting;
1515
import org.elasticsearch.common.util.concurrent.ThreadContext;
16+
import org.elasticsearch.indices.SystemIndices;
1617
import org.elasticsearch.plugins.ActionPlugin;
1718
import org.elasticsearch.plugins.Plugin;
1819

@@ -30,12 +31,13 @@ public DotPrefixValidationPlugin() {}
3031
public Collection<?> createComponents(PluginServices services) {
3132
ThreadContext context = services.threadPool().getThreadContext();
3233
ClusterService clusterService = services.clusterService();
34+
SystemIndices systemIndices = services.systemIndices();
3335

3436
actionFilters.set(
3537
List.of(
36-
new CreateIndexDotValidator(context, clusterService),
37-
new AutoCreateDotValidator(context, clusterService),
38-
new IndexTemplateDotValidator(context, clusterService)
38+
new CreateIndexDotValidator(context, clusterService, systemIndices),
39+
new AutoCreateDotValidator(context, clusterService, systemIndices),
40+
new IndexTemplateDotValidator(context, clusterService, systemIndices)
3941
)
4042
);
4143

modules/dot-prefix-validation/src/main/java/org/elasticsearch/validation/DotPrefixValidator.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.elasticsearch.common.settings.Setting;
2222
import org.elasticsearch.common.util.concurrent.ThreadContext;
2323
import org.elasticsearch.core.Nullable;
24+
import org.elasticsearch.indices.SystemIndices;
2425
import org.elasticsearch.tasks.Task;
2526

2627
import java.util.List;
@@ -94,11 +95,13 @@ public abstract class DotPrefixValidator<RequestType> implements MappedActionFil
9495
DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(DotPrefixValidator.class);
9596

9697
private final ThreadContext threadContext;
98+
private final SystemIndices systemIndices;
9799
private final boolean isEnabled;
98100
private volatile Set<Pattern> ignoredIndexPatterns;
99101

100-
public DotPrefixValidator(ThreadContext threadContext, ClusterService clusterService) {
102+
public DotPrefixValidator(ThreadContext threadContext, ClusterService clusterService, SystemIndices systemIndices) {
101103
this.threadContext = threadContext;
104+
this.systemIndices = systemIndices;
102105
this.isEnabled = VALIDATE_DOT_PREFIXES.get(clusterService.getSettings());
103106
this.ignoredIndexPatterns = IGNORED_INDEX_PATTERNS_SETTING.get(clusterService.getSettings())
104107
.stream()
@@ -139,6 +142,10 @@ void validateIndices(@Nullable Set<String> indices) {
139142
if (IGNORED_INDEX_NAMES.contains(strippedName)) {
140143
return;
141144
}
145+
if (systemIndices.findMatchingDescriptor(strippedName) != null
146+
|| systemIndices.findMatchingDataStreamDescriptor(strippedName) != null) {
147+
return;
148+
}
142149
if (this.ignoredIndexPatterns.stream().anyMatch(p -> p.matcher(strippedName).matches())) {
143150
return;
144151
}

modules/dot-prefix-validation/src/main/java/org/elasticsearch/validation/IndexTemplateDotValidator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
1313
import org.elasticsearch.cluster.service.ClusterService;
1414
import org.elasticsearch.common.util.concurrent.ThreadContext;
15+
import org.elasticsearch.indices.SystemIndices;
1516

1617
import java.util.Arrays;
1718
import java.util.HashSet;
1819
import java.util.Set;
1920

2021
public class IndexTemplateDotValidator extends DotPrefixValidator<TransportPutComposableIndexTemplateAction.Request> {
21-
public IndexTemplateDotValidator(ThreadContext threadContext, ClusterService clusterService) {
22-
super(threadContext, clusterService);
22+
public IndexTemplateDotValidator(ThreadContext threadContext, ClusterService clusterService, SystemIndices systemIndices) {
23+
super(threadContext, clusterService, systemIndices);
2324
}
2425

2526
@Override

modules/dot-prefix-validation/src/test/java/org/elasticsearch/validation/DotPrefixValidatorTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.common.settings.Settings;
1616
import org.elasticsearch.common.util.concurrent.ThreadContext;
1717
import org.elasticsearch.common.util.set.Sets;
18+
import org.elasticsearch.indices.SystemIndices;
1819
import org.elasticsearch.test.ESTestCase;
1920
import org.elasticsearch.threadpool.ThreadPool;
2021
import org.junit.BeforeClass;
@@ -107,7 +108,7 @@ private void assertFails(Set<String> indices) {
107108
private static class NonOperatorValidator<R> extends DotPrefixValidator<R> {
108109

109110
private NonOperatorValidator() {
110-
super(new ThreadContext(Settings.EMPTY), clusterService);
111+
super(new ThreadContext(Settings.EMPTY), clusterService, new SystemIndices(List.of()));
111112
}
112113

113114
@Override

modules/dot-prefix-validation/src/yamlRestTest/resources/rest-api-spec/test/dot_prefix/10_basic.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
---
22
teardown:
3+
- requires:
4+
test_runner_features: ["allowed_warnings"]
5+
36
- do:
7+
allowed_warnings:
8+
- "this request accesses system indices: [.async-search], but in a future major version, direct access to system indices will be prevented by default"
49
indices.delete:
510
index: .*,-.security-*
611

@@ -194,3 +199,17 @@ teardown:
194199
- do:
195200
indices.delete_index_template:
196201
name: my-template2
202+
203+
---
204+
"System indices do not cause deprecation warnings":
205+
- do:
206+
index:
207+
index: myindex
208+
id: "1"
209+
body: {foo: bar}
210+
211+
- do:
212+
async_search.submit:
213+
index: myindex
214+
keep_alive: 1m
215+
keep_on_completion: true

0 commit comments

Comments
 (0)