Skip to content

Correctly ignore system indices when validationg dot-prefixed indices #128868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/128868.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 128868
summary: Correctly ignore system indices when validating dot-prefixed indices
area: Indices APIs
type: bug
issues: []
2 changes: 1 addition & 1 deletion modules/dot-prefix-validation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CreateIndexRequest> {
public AutoCreateDotValidator(ThreadContext threadContext, ClusterService clusterService) {
super(threadContext, clusterService);
public AutoCreateDotValidator(ThreadContext threadContext, ClusterService clusterService, SystemIndices systemIndices) {
super(threadContext, clusterService, systemIndices);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CreateIndexRequest> {
public CreateIndexDotValidator(ThreadContext threadContext, ClusterService clusterService) {
super(threadContext, clusterService);
public CreateIndexDotValidator(ThreadContext threadContext, ClusterService clusterService, SystemIndices systemIndices) {
super(threadContext, clusterService, systemIndices);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,11 +95,13 @@ public abstract class DotPrefixValidator<RequestType> implements MappedActionFil
DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(DotPrefixValidator.class);

private final ThreadContext threadContext;
private final SystemIndices systemIndices;
private final boolean isEnabled;
private volatile Set<Pattern> 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()
Expand Down Expand Up @@ -139,6 +142,10 @@ void validateIndices(@Nullable Set<String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TransportPutComposableIndexTemplateAction.Request> {
public IndexTemplateDotValidator(ThreadContext threadContext, ClusterService clusterService) {
super(threadContext, clusterService);
public IndexTemplateDotValidator(ThreadContext threadContext, ClusterService clusterService, SystemIndices systemIndices) {
super(threadContext, clusterService, systemIndices);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -107,7 +108,7 @@ private void assertFails(Set<String> indices) {
private static class NonOperatorValidator<R> extends DotPrefixValidator<R> {

private NonOperatorValidator() {
super(new ThreadContext(Settings.EMPTY), clusterService);
super(new ThreadContext(Settings.EMPTY), clusterService, new SystemIndices(List.of()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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-*

Expand Down Expand Up @@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this test fails before the addition to DotPrefixValidator?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm… I thought that it would, but it doesn't appear to work. So I can remove this test. I'm not sure how to test this right now other than manual testing. I'll do some more digging to see how best to test this.

index: myindex
keep_alive: 1m
keep_on_completion: true
Loading