From 2ceb42dcf406a187f37ee9d51bb47f2b6213b4af Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Tue, 3 Jun 2025 16:56:10 -0600 Subject: [PATCH 1/3] 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. --- modules/dot-prefix-validation/build.gradle | 2 +- .../validation/AutoCreateDotValidator.java | 5 +++-- .../validation/CreateIndexDotValidator.java | 5 +++-- .../validation/DotPrefixValidationPlugin.java | 8 +++++--- .../validation/DotPrefixValidator.java | 9 ++++++++- .../validation/IndexTemplateDotValidator.java | 5 +++-- .../validation/DotPrefixValidatorTests.java | 3 ++- .../test/dot_prefix/10_basic.yml | 19 +++++++++++++++++++ 8 files changed, 44 insertions(+), 12 deletions(-) diff --git a/modules/dot-prefix-validation/build.gradle b/modules/dot-prefix-validation/build.gradle index 657ab3478512b..42500fd913917 100644 --- a/modules/dot-prefix-validation/build.gradle +++ b/modules/dot-prefix-validation/build.gradle @@ -16,7 +16,7 @@ esplugin { restResources { restApi { - include '_common', 'indices', 'index', 'cluster', 'nodes', 'get', 'ingest', 'bulk', 'reindex' + include '_common', 'indices', 'index', 'cluster', 'nodes', 'get', 'ingest', 'bulk', 'reindex', 'async_search' } } diff --git a/modules/dot-prefix-validation/src/main/java/org/elasticsearch/validation/AutoCreateDotValidator.java b/modules/dot-prefix-validation/src/main/java/org/elasticsearch/validation/AutoCreateDotValidator.java index ec3c22620ca46..28ff6c26a8489 100644 --- a/modules/dot-prefix-validation/src/main/java/org/elasticsearch/validation/AutoCreateDotValidator.java +++ b/modules/dot-prefix-validation/src/main/java/org/elasticsearch/validation/AutoCreateDotValidator.java @@ -13,12 +13,13 @@ import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.indices.SystemIndices; import java.util.Set; public class AutoCreateDotValidator extends DotPrefixValidator { - public AutoCreateDotValidator(ThreadContext threadContext, ClusterService clusterService) { - super(threadContext, clusterService); + public AutoCreateDotValidator(ThreadContext threadContext, ClusterService clusterService, SystemIndices systemIndices) { + super(threadContext, clusterService, systemIndices); } @Override diff --git a/modules/dot-prefix-validation/src/main/java/org/elasticsearch/validation/CreateIndexDotValidator.java b/modules/dot-prefix-validation/src/main/java/org/elasticsearch/validation/CreateIndexDotValidator.java index f39a1d09fa07c..4902c71d66edf 100644 --- a/modules/dot-prefix-validation/src/main/java/org/elasticsearch/validation/CreateIndexDotValidator.java +++ b/modules/dot-prefix-validation/src/main/java/org/elasticsearch/validation/CreateIndexDotValidator.java @@ -13,12 +13,13 @@ import org.elasticsearch.action.admin.indices.create.TransportCreateIndexAction; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.indices.SystemIndices; import java.util.Set; public class CreateIndexDotValidator extends DotPrefixValidator { - public CreateIndexDotValidator(ThreadContext threadContext, ClusterService clusterService) { - super(threadContext, clusterService); + public CreateIndexDotValidator(ThreadContext threadContext, ClusterService clusterService, SystemIndices systemIndices) { + super(threadContext, clusterService, systemIndices); } @Override diff --git a/modules/dot-prefix-validation/src/main/java/org/elasticsearch/validation/DotPrefixValidationPlugin.java b/modules/dot-prefix-validation/src/main/java/org/elasticsearch/validation/DotPrefixValidationPlugin.java index c462dbdcf6c40..6e63ae9c65a10 100644 --- a/modules/dot-prefix-validation/src/main/java/org/elasticsearch/validation/DotPrefixValidationPlugin.java +++ b/modules/dot-prefix-validation/src/main/java/org/elasticsearch/validation/DotPrefixValidationPlugin.java @@ -13,6 +13,7 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.plugins.ActionPlugin; import org.elasticsearch.plugins.Plugin; @@ -30,12 +31,13 @@ public DotPrefixValidationPlugin() {} public Collection createComponents(PluginServices services) { ThreadContext context = services.threadPool().getThreadContext(); ClusterService clusterService = services.clusterService(); + SystemIndices systemIndices = services.systemIndices(); actionFilters.set( List.of( - new CreateIndexDotValidator(context, clusterService), - new AutoCreateDotValidator(context, clusterService), - new IndexTemplateDotValidator(context, clusterService) + new CreateIndexDotValidator(context, clusterService, systemIndices), + new AutoCreateDotValidator(context, clusterService, systemIndices), + new IndexTemplateDotValidator(context, clusterService, systemIndices) ) ); diff --git a/modules/dot-prefix-validation/src/main/java/org/elasticsearch/validation/DotPrefixValidator.java b/modules/dot-prefix-validation/src/main/java/org/elasticsearch/validation/DotPrefixValidator.java index 555d04e1c1a5d..20f7ce6ffa08e 100644 --- a/modules/dot-prefix-validation/src/main/java/org/elasticsearch/validation/DotPrefixValidator.java +++ b/modules/dot-prefix-validation/src/main/java/org/elasticsearch/validation/DotPrefixValidator.java @@ -21,6 +21,7 @@ import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.core.Nullable; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.tasks.Task; import java.util.List; @@ -94,11 +95,13 @@ public abstract class DotPrefixValidator implements MappedActionFil DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(DotPrefixValidator.class); private final ThreadContext threadContext; + private final SystemIndices systemIndices; private final boolean isEnabled; private volatile Set ignoredIndexPatterns; - public DotPrefixValidator(ThreadContext threadContext, ClusterService clusterService) { + public DotPrefixValidator(ThreadContext threadContext, ClusterService clusterService, SystemIndices systemIndices) { this.threadContext = threadContext; + this.systemIndices = systemIndices; this.isEnabled = VALIDATE_DOT_PREFIXES.get(clusterService.getSettings()); this.ignoredIndexPatterns = IGNORED_INDEX_PATTERNS_SETTING.get(clusterService.getSettings()) .stream() @@ -139,6 +142,10 @@ void validateIndices(@Nullable Set indices) { if (IGNORED_INDEX_NAMES.contains(strippedName)) { return; } + if (systemIndices.findMatchingDescriptor(strippedName) != null + || systemIndices.findMatchingDataStreamDescriptor(strippedName) != null) { + return; + } if (this.ignoredIndexPatterns.stream().anyMatch(p -> p.matcher(strippedName).matches())) { return; } diff --git a/modules/dot-prefix-validation/src/main/java/org/elasticsearch/validation/IndexTemplateDotValidator.java b/modules/dot-prefix-validation/src/main/java/org/elasticsearch/validation/IndexTemplateDotValidator.java index dd9b0feeab388..ecdaa6c73ea80 100644 --- a/modules/dot-prefix-validation/src/main/java/org/elasticsearch/validation/IndexTemplateDotValidator.java +++ b/modules/dot-prefix-validation/src/main/java/org/elasticsearch/validation/IndexTemplateDotValidator.java @@ -12,14 +12,15 @@ import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.indices.SystemIndices; import java.util.Arrays; import java.util.HashSet; import java.util.Set; public class IndexTemplateDotValidator extends DotPrefixValidator { - public IndexTemplateDotValidator(ThreadContext threadContext, ClusterService clusterService) { - super(threadContext, clusterService); + public IndexTemplateDotValidator(ThreadContext threadContext, ClusterService clusterService, SystemIndices systemIndices) { + super(threadContext, clusterService, systemIndices); } @Override diff --git a/modules/dot-prefix-validation/src/test/java/org/elasticsearch/validation/DotPrefixValidatorTests.java b/modules/dot-prefix-validation/src/test/java/org/elasticsearch/validation/DotPrefixValidatorTests.java index 7bf1fb3810790..c8ac42382894a 100644 --- a/modules/dot-prefix-validation/src/test/java/org/elasticsearch/validation/DotPrefixValidatorTests.java +++ b/modules/dot-prefix-validation/src/test/java/org/elasticsearch/validation/DotPrefixValidatorTests.java @@ -15,6 +15,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.util.set.Sets; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; import org.junit.BeforeClass; @@ -107,7 +108,7 @@ private void assertFails(Set indices) { private static class NonOperatorValidator extends DotPrefixValidator { private NonOperatorValidator() { - super(new ThreadContext(Settings.EMPTY), clusterService); + super(new ThreadContext(Settings.EMPTY), clusterService, new SystemIndices(List.of())); } @Override diff --git a/modules/dot-prefix-validation/src/yamlRestTest/resources/rest-api-spec/test/dot_prefix/10_basic.yml b/modules/dot-prefix-validation/src/yamlRestTest/resources/rest-api-spec/test/dot_prefix/10_basic.yml index 3ad7438b16b62..411e832718040 100644 --- a/modules/dot-prefix-validation/src/yamlRestTest/resources/rest-api-spec/test/dot_prefix/10_basic.yml +++ b/modules/dot-prefix-validation/src/yamlRestTest/resources/rest-api-spec/test/dot_prefix/10_basic.yml @@ -1,6 +1,11 @@ --- teardown: + - requires: + test_runner_features: ["allowed_warnings"] + - do: + allowed_warnings: + - "this request accesses system indices: [.async-search], but in a future major version, direct access to system indices will be prevented by default" indices.delete: index: .*,-.security-* @@ -194,3 +199,17 @@ teardown: - do: indices.delete_index_template: name: my-template2 + +--- +"System indices do not cause deprecation warnings": + - do: + index: + index: myindex + id: "1" + body: {foo: bar} + + - do: + async_search.submit: + index: myindex + keep_alive: 1m + keep_on_completion: true From 1b250e1d2bb6604a3657fd5e50c7012456bf3d58 Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Tue, 3 Jun 2025 17:02:09 -0600 Subject: [PATCH 2/3] Update docs/changelog/128868.yaml --- docs/changelog/128868.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/changelog/128868.yaml diff --git a/docs/changelog/128868.yaml b/docs/changelog/128868.yaml new file mode 100644 index 0000000000000..e5fa649268027 --- /dev/null +++ b/docs/changelog/128868.yaml @@ -0,0 +1,5 @@ +pr: 128868 +summary: Correctly ignore system indices when validationg dot-prefixed indices +area: Indices APIs +type: bug +issues: [] From 4127f6de6ac1caffead8002293978766e1878275 Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Wed, 4 Jun 2025 13:21:04 -0600 Subject: [PATCH 3/3] Fix changelog typo --- docs/changelog/128868.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog/128868.yaml b/docs/changelog/128868.yaml index e5fa649268027..51477e3496f8d 100644 --- a/docs/changelog/128868.yaml +++ b/docs/changelog/128868.yaml @@ -1,5 +1,5 @@ pr: 128868 -summary: Correctly ignore system indices when validationg dot-prefixed indices +summary: Correctly ignore system indices when validating dot-prefixed indices area: Indices APIs type: bug issues: []