diff --git a/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpDownloaderTaskExecutor.java b/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpDownloaderTaskExecutor.java index c6a1c3a87e606..cabcc04f1ca87 100644 --- a/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpDownloaderTaskExecutor.java +++ b/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpDownloaderTaskExecutor.java @@ -37,7 +37,7 @@ */ public final class GeoIpDownloaderTaskExecutor extends PersistentTasksExecutor implements ClusterStateListener { - static final boolean ENABLED_DEFAULT = "true".equals(System.getProperty("ingest.geoip.downloader.enabled.default")); + static final boolean ENABLED_DEFAULT = "true".equals(System.getProperty("ingest.geoip.downloader.enabled.default", "true")); public static final Setting ENABLED_SETTING = Setting.boolSetting("ingest.geoip.downloader.enabled", ENABLED_DEFAULT, Setting.Property.Dynamic, Setting.Property.NodeScope); diff --git a/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/IngestGeoIpPlugin.java b/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/IngestGeoIpPlugin.java index d04dcb999411e..35192be0c8167 100644 --- a/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/IngestGeoIpPlugin.java +++ b/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/IngestGeoIpPlugin.java @@ -182,6 +182,7 @@ public Collection getSystemIndexDescriptors(Settings sett .setOrigin("geoip") .setVersionMetaKey("version") .setPrimaryIndex(DATABASES_INDEX) + .setNetNew() .build(); return Collections.singleton(geoipDatabasesIndex); } diff --git a/qa/system-indices/build.gradle b/qa/system-indices/build.gradle new file mode 100644 index 0000000000000..b18ae1c687923 --- /dev/null +++ b/qa/system-indices/build.gradle @@ -0,0 +1,29 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +apply plugin: 'elasticsearch.internal-es-plugin' +apply plugin: 'elasticsearch.java-rest-test' + +esplugin { + name 'system-indices-qa' + description 'Plugin for performing QA of system indices' + classname 'org.elasticsearch.system.indices.SystemIndicesQA' + licenseFile rootProject.file('licenses/SSPL-1.0+ELASTIC-LICENSE-2.0.txt') + noticeFile rootProject.file('NOTICE.txt') +} + +tasks.named("test").configure { enabled = false } +tasks.named("javaRestTest").configure { + dependsOn "buildZip" +} + +testClusters.all { + testDistribution = 'DEFAULT' + setting 'xpack.security.enabled', 'true' + user username: 'rest_user', password: 'password', role: 'superuser' +} diff --git a/qa/system-indices/src/javaRestTest/java/org/elasticsearch/system/indices/NetNewSystemIndicesIT.java b/qa/system-indices/src/javaRestTest/java/org/elasticsearch/system/indices/NetNewSystemIndicesIT.java new file mode 100644 index 0000000000000..5fcbc2c3bbe8b --- /dev/null +++ b/qa/system-indices/src/javaRestTest/java/org/elasticsearch/system/indices/NetNewSystemIndicesIT.java @@ -0,0 +1,105 @@ + +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.system.indices; + +import org.apache.http.util.EntityUtils; +import org.elasticsearch.Version; +import org.elasticsearch.client.Request; +import org.elasticsearch.client.Response; +import org.elasticsearch.client.ResponseException; +import org.elasticsearch.common.settings.SecureString; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.test.rest.ESRestTestCase; +import org.junit.After; + +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; + +public class NetNewSystemIndicesIT extends ESRestTestCase { + + static final String BASIC_AUTH_VALUE = basicAuthHeaderValue("rest_user", new SecureString("password".toCharArray())); + + @Override + protected Settings restClientSettings() { + return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", BASIC_AUTH_VALUE).build(); + } + + public void testCreatingSystemIndex() throws Exception { + ResponseException e = expectThrows( + ResponseException.class, + () -> client().performRequest(new Request("PUT", "/.net-new-system-index-" + Version.CURRENT.major)) + ); + assertThat(EntityUtils.toString(e.getResponse().getEntity()), containsString("system")); + + Response response = client().performRequest(new Request("PUT", "/_net_new_sys_index/_create")); + assertThat(response.getStatusLine().getStatusCode(), is(200)); + } + + public void testIndexDoc() throws Exception { + String id = randomAlphaOfLength(4); + + ResponseException e = expectThrows(ResponseException.class, () -> { + Request request = new Request("PUT", "/.net-new-system-index-" + Version.CURRENT.major + "/_doc" + id); + request.setJsonEntity("{}"); + client().performRequest(request); + }); + assertThat(EntityUtils.toString(e.getResponse().getEntity()), containsString("system")); + + Request request = new Request("PUT", "/_net_new_sys_index/" + id); + request.setJsonEntity("{}"); + Response response = client().performRequest(request); + assertThat(response.getStatusLine().getStatusCode(), is(200)); + } + + public void testSearch() throws Exception { + // search before indexing doc + Request searchRequest = new Request("GET", "/_search"); + searchRequest.setJsonEntity("{ \"query\": { \"match_all\": {} } }"); + searchRequest.addParameter("size", "10000"); + Response searchResponse = client().performRequest(searchRequest); + assertThat(searchResponse.getStatusLine().getStatusCode(), is(200)); + assertThat(EntityUtils.toString(searchResponse.getEntity()), not(containsString(".net-new"))); + + // create a doc + String id = randomAlphaOfLength(4); + Request request = new Request("PUT", "/_net_new_sys_index/" + id); + request.setJsonEntity("{}"); + request.addParameter("refresh", "true"); + Response response = client().performRequest(request); + assertThat(response.getStatusLine().getStatusCode(), is(200)); + + // search again + searchResponse = client().performRequest(searchRequest); + assertThat(searchResponse.getStatusLine().getStatusCode(), is(200)); + assertThat(EntityUtils.toString(searchResponse.getEntity()), not(containsString(".net-new"))); + + // index wildcard search + searchRequest = new Request("GET", "/.net-new-system-index*/_search"); + searchRequest.setJsonEntity("{ \"query\": { \"match_all\": {} } }"); + searchRequest.addParameter("size", "10000"); + searchResponse = client().performRequest(searchRequest); + assertThat(searchResponse.getStatusLine().getStatusCode(), is(200)); + assertThat(EntityUtils.toString(searchResponse.getEntity()), not(containsString(".net-new"))); + + // direct index search + Request directRequest = new Request("GET", "/.net-new-system-index-" + Version.CURRENT.major + "/_search"); + directRequest.setJsonEntity("{ \"query\": { \"match_all\": {} } }"); + directRequest.addParameter("size", "10000"); + ResponseException e = expectThrows(ResponseException.class, () -> client().performRequest(directRequest)); + assertThat(EntityUtils.toString(e.getResponse().getEntity()), containsString("system")); + } + + @After + public void resetFeatures() throws Exception { + client().performRequest(new Request("POST", "/_features/_reset")); + } +} diff --git a/qa/system-indices/src/main/java/org/elasticsearch/system/indices/SystemIndicesQA.java b/qa/system-indices/src/main/java/org/elasticsearch/system/indices/SystemIndicesQA.java new file mode 100644 index 0000000000000..ce84d92f724ee --- /dev/null +++ b/qa/system-indices/src/main/java/org/elasticsearch/system/indices/SystemIndicesQA.java @@ -0,0 +1,164 @@ + +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.system.indices; + +import org.elasticsearch.Version; +import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; +import org.elasticsearch.action.index.IndexRequest; +import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.cluster.metadata.IndexMetadata; +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.settings.ClusterSettings; +import org.elasticsearch.common.settings.IndexScopedSettings; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsFilter; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.indices.SystemIndexDescriptor; +import org.elasticsearch.plugins.ActionPlugin; +import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.plugins.SystemIndexPlugin; +import org.elasticsearch.rest.BaseRestHandler; +import org.elasticsearch.rest.RestController; +import org.elasticsearch.rest.RestHandler; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestRequest.Method; +import org.elasticsearch.rest.action.RestToXContentListener; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.util.Collection; +import java.util.List; +import java.util.function.Supplier; + +import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; +import static org.elasticsearch.index.mapper.MapperService.SINGLE_MAPPING_NAME; +import static org.elasticsearch.rest.RestRequest.Method.POST; +import static org.elasticsearch.rest.RestRequest.Method.PUT; + +public class SystemIndicesQA extends Plugin implements SystemIndexPlugin, ActionPlugin { + + @Override + public String getFeatureName() { + return "system indices qa"; + } + + @Override + public String getFeatureDescription() { + return "plugin used to perform qa on system index behavior"; + } + + @Override + public Collection getSystemIndexDescriptors(Settings settings) { + return org.elasticsearch.core.List.of( + SystemIndexDescriptor.builder() + .setNetNew() + .setIndexPattern(".net-new-system-index*") + .setDescription("net new system index") + .setMappings(mappings()) + .setSettings( + Settings.builder() + .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) + .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) + .put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "0-1") + .build() + ) + .setOrigin("net-new") + .setVersionMetaKey("version") + .setPrimaryIndex(".net-new-system-index-" + Version.CURRENT.major) + .build() + ); + } + + private static XContentBuilder mappings() { + try { + return jsonBuilder().startObject() + .startObject(SINGLE_MAPPING_NAME) + .startObject("_meta") + .field("version", Version.CURRENT) + .endObject() + .field("dynamic", "strict") + .startObject("properties") + .startObject("name") + .field("type", "keyword") + .endObject() + .endObject() + .endObject() + .endObject(); + } catch (IOException e) { + throw new UncheckedIOException("Failed to build mappings for net new system index", e); + } + } + + @Override + public List getRestHandlers( + Settings settings, + RestController restController, + ClusterSettings clusterSettings, + IndexScopedSettings indexScopedSettings, + SettingsFilter settingsFilter, + IndexNameExpressionResolver indexNameExpressionResolver, + Supplier nodesInCluster + ) { + return org.elasticsearch.core.List.of(new CreateNetNewSystemIndexHandler(), new IndexDocHandler()); + } + + private static class CreateNetNewSystemIndexHandler extends BaseRestHandler { + + @Override + public String getName() { + return "create net new system index for qa"; + } + + @Override + public List routes() { + return org.elasticsearch.core.List.of(Route.builder(Method.PUT, "/_net_new_sys_index/_create").build()); + } + + @Override + protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { + return channel -> client.admin() + .indices() + .create(new CreateIndexRequest(".net-new-system-index-" + Version.CURRENT.major), new RestToXContentListener<>(channel)); + } + + @Override + public boolean allowSystemIndexAccessByDefault() { + return true; + } + } + + private static class IndexDocHandler extends BaseRestHandler { + @Override + public String getName() { + return "index doc into net new for qa"; + } + + @Override + public List routes() { + return org.elasticsearch.core.List.of(new Route(POST, "/_net_new_sys_index/{id}"), new Route(PUT, "/_net_new_sys_index/{id}")); + } + + @Override + protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { + IndexRequest indexRequest = new IndexRequest(".net-new-system-index-" + Version.CURRENT.major); + indexRequest.source(request.requiredContent(), request.getXContentType()); + indexRequest.id(request.param("id")); + indexRequest.setRefreshPolicy(request.param("refresh")); + + return channel -> client.index(indexRequest, new RestToXContentListener<>(channel)); + } + + @Override + public boolean allowSystemIndexAccessByDefault() { + return true; + } + } +} diff --git a/server/src/internalClusterTest/java/org/elasticsearch/indices/TestSystemIndexDescriptor.java b/server/src/internalClusterTest/java/org/elasticsearch/indices/TestSystemIndexDescriptor.java index 00a66fc30eba3..d3370dfc248b1 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/indices/TestSystemIndexDescriptor.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/indices/TestSystemIndexDescriptor.java @@ -41,7 +41,8 @@ public class TestSystemIndexDescriptor extends SystemIndexDescriptor { TestSystemIndexDescriptor() { super(INDEX_NAME + "*", PRIMARY_INDEX_NAME, "Test system index", getOldMappings(), SETTINGS, INDEX_NAME, 0, "version", "stack", - SINGLE_MAPPING_NAME, Version.CURRENT.minimumCompatibilityVersion(), Type.INTERNAL_MANAGED, emptyList(), emptyList(), null); + SINGLE_MAPPING_NAME, Version.CURRENT.minimumCompatibilityVersion(), Type.INTERNAL_MANAGED, emptyList(), emptyList(), null, + false); } @Override diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesAction.java index ba045f6f04edb..8d238ff289542 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesAction.java @@ -32,7 +32,6 @@ import org.elasticsearch.transport.Transports; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; @@ -134,13 +133,18 @@ private static void checkSystemIndexAccess(GetAliasesRequest request, SystemIndi throw new IllegalArgumentException("Unexpected system index access level: " + systemIndexAccessLevel); } + List netNewSystemIndices = new ArrayList<>(); List systemIndicesNames = new ArrayList<>(); for (Iterator it = aliasesMap.keysIt(); it.hasNext(); ) { String indexName = it.next(); IndexMetadata index = state.metadata().index(indexName); if (index != null && index.isSystem()) { if (systemIndexAccessAllowPredicate.test(index) == false) { - systemIndicesNames.add(indexName); + if (systemIndices.isNetNewSystemIndex(indexName)) { + netNewSystemIndices.add(indexName); + } else { + systemIndicesNames.add(indexName); + } } } } @@ -148,9 +152,11 @@ private static void checkSystemIndexAccess(GetAliasesRequest request, SystemIndi deprecationLogger.deprecate(DeprecationCategory.API, "open_system_index_access", "this request accesses system indices: {}, but in a future major version, direct access to system " + "indices will be prevented by default", systemIndicesNames); - } else { - checkSystemAliasAccess(request, systemIndices, systemIndexAccessLevel, threadContext); } + if (netNewSystemIndices.isEmpty() == false) { + throw systemIndices.netNewSystemIndexAccessException(threadContext, netNewSystemIndices); + } + checkSystemAliasAccess(request, systemIndices, systemIndexAccessLevel, threadContext); } private static void checkSystemAliasAccess(GetAliasesRequest request, SystemIndices systemIndices, @@ -164,14 +170,27 @@ private static void checkSystemAliasAccess(GetAliasesRequest request, SystemIndi throw new IllegalArgumentException("Unexpected system index access level: " + systemIndexAccessLevel); } - final List systemAliases = Arrays.stream(request.aliases()) - .filter(systemIndices::isSystemName) - .filter(systemIndexAccessAllowPredicate) - .collect(Collectors.toList()); + final List systemAliases = new ArrayList<>(); + final List netNewSystemAliases = new ArrayList<>(); + for (String alias : request.aliases()) { + if (systemIndices.isSystemName(alias)) { + if (systemIndexAccessAllowPredicate.test(alias)) { + if (systemIndices.isNetNewSystemIndex(alias)) { + netNewSystemAliases.add(alias); + } else { + systemAliases.add(alias); + } + } + } + } + if (systemAliases.isEmpty() == false) { deprecationLogger.deprecate(DeprecationCategory.API, "open_system_alias_access", - "this request accesses aliases with names reserved for system indices: {}, but in a future major version, direct" + + "this request accesses aliases with names reserved for system indices: {}, but in a future major version, direct " + "access to system indices and their aliases will not be allowed", systemAliases); } + if (netNewSystemAliases.isEmpty() == false) { + throw systemIndices.netNewSystemIndexAccessException(threadContext, netNewSystemAliases); + } } } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/create/TransportCreateIndexAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/create/TransportCreateIndexAction.java index e38046e52e8ca..63a9ba9b13f08 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/create/TransportCreateIndexAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/create/TransportCreateIndexAction.java @@ -24,8 +24,10 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.core.List; import org.elasticsearch.indices.SystemIndexDescriptor; import org.elasticsearch.indices.SystemIndices; +import org.elasticsearch.indices.SystemIndices.SystemIndexAccessLevel; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -73,6 +75,20 @@ protected void masterOperation(final CreateIndexRequest request, final ClusterSt final SystemIndexDescriptor mainDescriptor = systemIndices.findMatchingDescriptor(indexName); final boolean isSystemIndex = mainDescriptor != null && mainDescriptor.isAutomaticallyManaged(); + if (mainDescriptor != null && mainDescriptor.isNetNew()) { + final SystemIndexAccessLevel systemIndexAccessLevel = systemIndices.getSystemIndexAccessLevel(threadPool.getThreadContext()); + if (systemIndexAccessLevel != SystemIndexAccessLevel.ALL) { + if (systemIndexAccessLevel == SystemIndexAccessLevel.RESTRICTED) { + if (systemIndices.getProductSystemIndexNamePredicate(threadPool.getThreadContext()).test(indexName) == false) { + throw systemIndices.netNewSystemIndexAccessException(threadPool.getThreadContext(), List.of(indexName)); + } + } else { + assert systemIndexAccessLevel == SystemIndexAccessLevel.NONE : + "Expected no system index access but level is " + systemIndexAccessLevel; + throw systemIndices.netNewSystemIndexAccessException(threadPool.getThreadContext(), List.of(indexName)); + } + } + } final CreateIndexClusterStateUpdateRequest updateRequest; diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexAbstractionResolver.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexAbstractionResolver.java index d5e1919dc7139..a1ecc2c09d401 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexAbstractionResolver.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexAbstractionResolver.java @@ -133,7 +133,6 @@ public static boolean isIndexVisible(String expression, String index, IndicesOpt if (includeDataStreams == false) { return false; } - if (indexAbstraction.isSystem()) { final SystemIndexAccessLevel level = resolver.getSystemIndexAccessLevel(); if (level == SystemIndexAccessLevel.ALL) { @@ -158,9 +157,22 @@ public static boolean isIndexVisible(String expression, String index, IndicesOpt return false; } if (indexAbstraction.isSystem()) { - // system index that backs system data stream + // check if it is net new + if (resolver.getNetNewSystemIndexPredicate().test(indexAbstraction.getName())) { + final SystemIndexAccessLevel level = resolver.getSystemIndexAccessLevel(); + if (level == SystemIndexAccessLevel.ALL) { + return true; + } else if (level == SystemIndexAccessLevel.NONE) { + return false; + } else if (level == SystemIndexAccessLevel.RESTRICTED) { + return resolver.getSystemIndexAccessPredicate().test(indexAbstraction.getName()); + } + } + + // does the system index back a system data stream? if (indexAbstraction.getParentDataStream() != null) { if (indexAbstraction.getParentDataStream().isSystem() == false) { + assert false : "system index is part of a data stream that is not a system data stream"; throw new IllegalStateException("system index is part of a data stream that is not a system data stream"); } final SystemIndexAccessLevel level = resolver.getSystemIndexAccessLevel(); diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java index d82db821e4f82..64eb7c3820164 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java @@ -79,7 +79,7 @@ public IndexNameExpressionResolver(ThreadContext threadContext, SystemIndices sy */ public String[] concreteIndexNames(ClusterState state, IndicesRequest request) { Context context = new Context(state, request.indicesOptions(), false, false, request.includeDataStreams(), - getSystemIndexAccessPredicate()); + getSystemIndexAccessLevel(), getSystemIndexAccessPredicate(), getNetNewSystemIndexPredicate()); return concreteIndexNames(context, request.indices()); } @@ -88,7 +88,7 @@ public String[] concreteIndexNames(ClusterState state, IndicesRequest request) { */ public String[] concreteIndexNamesWithSystemIndexAccess(ClusterState state, IndicesRequest request) { Context context = new Context(state, request.indicesOptions(), false, false, request.includeDataStreams(), - name -> true); + SystemIndexAccessLevel.ALL, name -> true, name -> false); return concreteIndexNames(context, request.indices()); } @@ -98,7 +98,7 @@ public String[] concreteIndexNamesWithSystemIndexAccess(ClusterState state, Indi */ public Index[] concreteIndices(ClusterState state, IndicesRequest request) { Context context = new Context(state, request.indicesOptions(), false, false, request.includeDataStreams(), - getSystemIndexAccessPredicate()); + getSystemIndexAccessLevel(), getSystemIndexAccessPredicate(), getNetNewSystemIndexPredicate()); return concreteIndices(context, request.indices()); } @@ -116,27 +116,31 @@ public Index[] concreteIndices(ClusterState state, IndicesRequest request) { * indices options in the context don't allow such a case. */ public String[] concreteIndexNames(ClusterState state, IndicesOptions options, String... indexExpressions) { - Context context = new Context(state, options, getSystemIndexAccessPredicate()); + Context context = new Context(state, options, getSystemIndexAccessLevel(), + getSystemIndexAccessPredicate(), getNetNewSystemIndexPredicate()); return concreteIndexNames(context, indexExpressions); } public String[] concreteIndexNames(ClusterState state, IndicesOptions options, boolean includeDataStreams, String... indexExpressions) { - Context context = new Context(state, options, false, false, includeDataStreams, getSystemIndexAccessPredicate()); + Context context = new Context(state, options, false, false, includeDataStreams, getSystemIndexAccessLevel(), + getSystemIndexAccessPredicate(), getNetNewSystemIndexPredicate()); return concreteIndexNames(context, indexExpressions); } public String[] concreteIndexNames(ClusterState state, IndicesOptions options, IndicesRequest request) { - Context context = new Context(state, options, false, false, request.includeDataStreams(), getSystemIndexAccessPredicate()); + Context context = new Context(state, options, false, false, request.includeDataStreams(), + getSystemIndexAccessLevel(), getSystemIndexAccessPredicate(), getNetNewSystemIndexPredicate()); return concreteIndexNames(context, request.indices()); } public String[] concreteIndexNamesWithSystemIndexAccess(ClusterState state, IndicesOptions options, String... indexExpressions) { - Context context = new Context(state, options, name -> true); + Context context = new Context(state, options, SystemIndexAccessLevel.ALL, name -> true, name -> false); return concreteIndexNames(context, indexExpressions); } public List dataStreamNames(ClusterState state, IndicesOptions options, String... indexExpressions) { - Context context = new Context(state, options, false, false, true, true, getSystemIndexAccessPredicate()); + Context context = new Context(state, options, false, false, true, true, getSystemIndexAccessLevel(), + getSystemIndexAccessPredicate(), getNetNewSystemIndexPredicate()); if (indexExpressions == null || indexExpressions.length == 0) { indexExpressions = new String[]{"*"}; } @@ -172,7 +176,7 @@ public Index[] concreteIndices(ClusterState state, IndicesOptions options, Strin public Index[] concreteIndices(ClusterState state, IndicesOptions options, boolean includeDataStreams, String... indexExpressions) { Context context = new Context(state, options, false, false, includeDataStreams, - getSystemIndexAccessPredicate()); + getSystemIndexAccessLevel(), getSystemIndexAccessPredicate(), getNetNewSystemIndexPredicate()); return concreteIndices(context, indexExpressions); } @@ -190,7 +194,7 @@ public Index[] concreteIndices(ClusterState state, IndicesOptions options, boole */ public Index[] concreteIndices(ClusterState state, IndicesRequest request, long startTime) { Context context = new Context(state, request.indicesOptions(), startTime, false, false, request.includeDataStreams(), false, - getSystemIndexAccessPredicate()); + getSystemIndexAccessLevel(), getSystemIndexAccessPredicate(), getNetNewSystemIndexPredicate()); return concreteIndices(context, request.indices()); } @@ -328,12 +332,15 @@ private void checkSystemIndexAccess(Context context, Metadata metadata, Set resolvedSystemIndices = new ArrayList<>(); + final List resolvedNetNewSystemIndices = new ArrayList<>(); final Set resolvedSystemDataStreams = new HashSet<>(); final SortedMap indicesLookup = metadata.getIndicesLookup(); for (IndexMetadata idxMetadata : systemIndicesThatShouldNotBeAccessed) { IndexAbstraction abstraction = indicesLookup.get(idxMetadata.getIndex().getName()); if (abstraction.getParentDataStream() != null) { resolvedSystemDataStreams.add(abstraction.getParentDataStream().getName()); + } else if (systemIndices.isNetNewSystemIndex(idxMetadata.getIndex().getName())) { + resolvedNetNewSystemIndices.add(idxMetadata.getIndex().getName()); } else { resolvedSystemIndices.add(idxMetadata.getIndex().getName()); } @@ -348,6 +355,9 @@ private void checkSystemIndexAccess(Context context, Metadata metadata, Set resolveExpressions(ClusterState state, String... expressions) { - Context context = new Context(state, IndicesOptions.lenientExpandOpen(), true, false, true, getSystemIndexAccessPredicate()); + Context context = new Context(state, IndicesOptions.lenientExpandOpen(), true, false, true, getSystemIndexAccessLevel(), + getSystemIndexAccessPredicate(), getNetNewSystemIndexPredicate()); List resolvedExpressions = Arrays.asList(expressions); for (ExpressionResolver expressionResolver : expressionResolvers) { resolvedExpressions = expressionResolver.resolve(context, resolvedExpressions); @@ -571,7 +586,8 @@ public String[] indexAliases(ClusterState state, String index, Predicate> resolveSearchRouting(ClusterState state, @Nullable String routing, String... expressions) { List resolvedExpressions = expressions != null ? Arrays.asList(expressions) : Collections.emptyList(); - Context context = new Context(state, IndicesOptions.lenientExpandOpen(), false, false, true, getSystemIndexAccessPredicate()); + Context context = new Context(state, IndicesOptions.lenientExpandOpen(), false, false, true, getSystemIndexAccessLevel(), + getSystemIndexAccessPredicate(), getNetNewSystemIndexPredicate()); for (ExpressionResolver expressionResolver : expressionResolvers) { resolvedExpressions = expressionResolver.resolve(context, resolvedExpressions); } @@ -740,6 +756,10 @@ public Predicate getSystemIndexAccessPredicate() { return systemIndexAccessLevelPredicate; } + public Predicate getNetNewSystemIndexPredicate() { + return systemIndices::isNetNewSystemIndex; + } + public static class Context { private final ClusterState state; @@ -749,30 +769,44 @@ public static class Context { private final boolean resolveToWriteIndex; private final boolean includeDataStreams; private final boolean preserveDataStreams; + private final SystemIndexAccessLevel systemIndexAccessLevel; private final Predicate systemIndexAccessPredicate; + private final Predicate netNewSystemIndexPredicate; - Context(ClusterState state, IndicesOptions options, Predicate systemIndexAccessPredicate) { - this(state, options, System.currentTimeMillis(), systemIndexAccessPredicate); + Context(ClusterState state, IndicesOptions options, SystemIndexAccessLevel systemIndexAccessLevel) { + this(state, options, systemIndexAccessLevel, s -> true, s -> false); + } + + Context(ClusterState state, IndicesOptions options, SystemIndexAccessLevel systemIndexAccessLevel, + Predicate systemIndexAccessPredicate, Predicate netNewSystemIndexPredicate) { + this(state, options, System.currentTimeMillis(), systemIndexAccessLevel, systemIndexAccessPredicate, + netNewSystemIndexPredicate); } Context(ClusterState state, IndicesOptions options, boolean preserveAliases, boolean resolveToWriteIndex, - boolean includeDataStreams, Predicate systemIndexAccessPredicate) { + boolean includeDataStreams, SystemIndexAccessLevel systemIndexAccessLevel, Predicate systemIndexAccessPredicate, + Predicate netNewSystemIndexPredicate) { this(state, options, System.currentTimeMillis(), preserveAliases, resolveToWriteIndex, includeDataStreams, false, - systemIndexAccessPredicate); + systemIndexAccessLevel, systemIndexAccessPredicate, netNewSystemIndexPredicate); } Context(ClusterState state, IndicesOptions options, boolean preserveAliases, boolean resolveToWriteIndex, - boolean includeDataStreams, boolean preserveDataStreams, Predicate systemIndexAccessPredicate) { + boolean includeDataStreams, boolean preserveDataStreams, SystemIndexAccessLevel systemIndexAccessLevel, + Predicate systemIndexAccessPredicate, Predicate netNewSystemIndexPredicate) { this(state, options, System.currentTimeMillis(), preserveAliases, resolveToWriteIndex, includeDataStreams, preserveDataStreams, - systemIndexAccessPredicate); + systemIndexAccessLevel, systemIndexAccessPredicate, netNewSystemIndexPredicate); } - Context(ClusterState state, IndicesOptions options, long startTime, Predicate systemIndexAccessPredicate) { - this(state, options, startTime, false, false, false, false, systemIndexAccessPredicate); + Context(ClusterState state, IndicesOptions options, long startTime, SystemIndexAccessLevel systemIndexAccessLevel, + Predicate systemIndexAccessPredicate, Predicate netNewSystemIndexPredicate) { + this(state, options, startTime, false, false, false, false, systemIndexAccessLevel, systemIndexAccessPredicate, + netNewSystemIndexPredicate); } protected Context(ClusterState state, IndicesOptions options, long startTime, boolean preserveAliases, boolean resolveToWriteIndex, - boolean includeDataStreams, boolean preserveDataStreams, Predicate systemIndexAccessPredicate) { + boolean includeDataStreams, boolean preserveDataStreams, SystemIndexAccessLevel systemIndexAccessLevel, + Predicate systemIndexAccessPredicate, + Predicate netNewSystemIndexPredicate) { this.state = state; this.options = options; this.startTime = startTime; @@ -780,7 +814,9 @@ protected Context(ClusterState state, IndicesOptions options, long startTime, bo this.resolveToWriteIndex = resolveToWriteIndex; this.includeDataStreams = includeDataStreams; this.preserveDataStreams = preserveDataStreams; + this.systemIndexAccessLevel = systemIndexAccessLevel; this.systemIndexAccessPredicate = systemIndexAccessPredicate; + this.netNewSystemIndexPredicate = netNewSystemIndexPredicate; } public ClusterState getState() { @@ -856,20 +892,7 @@ public List resolve(Context context, List expressions) { } if (isEmptyOrTrivialWildcard(expressions)) { - List resolvedExpressions = resolveEmptyOrTrivialWildcard(options, metadata).stream() - .filter(expression -> { - IndexAbstraction abstraction = metadata.getIndicesLookup().get(expression); - if (abstraction != null && abstraction.isSystem()) { - if (abstraction.getType() == Type.DATA_STREAM || abstraction.getParentDataStream() != null) { - return context.systemIndexAccessPredicate.test(abstraction.getName()); - } else { - return true; - } - } else { - return true; - } - }) - .collect(Collectors.toList()); + List resolvedExpressions = resolveEmptyOrTrivialWildcard(context); if (context.includeDataStreams()) { final IndexMetadata.State excludeState = excludeState(options); final Map dataStreamsAbstractions = metadata.getIndicesLookup().entrySet() @@ -1069,11 +1092,16 @@ private static Set expand(Context context, IndexMetadata.State excludeSt String aliasOrIndexName = entry.getKey(); IndexAbstraction indexAbstraction = entry.getValue(); - if (indexAbstraction.isSystem() && - (indexAbstraction.getType() == Type.DATA_STREAM || indexAbstraction.getParentDataStream() != null)) { - if (context.systemIndexAccessPredicate.test(indexAbstraction.getName()) == false) { + if (indexAbstraction.isSystem()) { + if (context.netNewSystemIndexPredicate.test(indexAbstraction.getName()) && + context.systemIndexAccessPredicate.test(indexAbstraction.getName()) == false) { continue; } + if (indexAbstraction.getType() == Type.DATA_STREAM || indexAbstraction.getParentDataStream() != null) { + if (context.systemIndexAccessPredicate.test(indexAbstraction.getName()) == false) { + continue; + } + } } if (indexAbstraction.isHidden() == false || includeHidden || implicitHiddenMatch(aliasOrIndexName, expression)) { @@ -1103,21 +1131,52 @@ private boolean isEmptyOrTrivialWildcard(List expressions) { Regex.isMatchAllPattern(expressions.get(0)))); } - private static List resolveEmptyOrTrivialWildcard(IndicesOptions options, Metadata metadata) { + private static List resolveEmptyOrTrivialWildcard(Context context) { + final String[] allIndices = resolveEmptyOrTrivialWildcardToAllIndices(context.getOptions(), context.getState().metadata()); + if (context.systemIndexAccessLevel == SystemIndexAccessLevel.ALL) { + return org.elasticsearch.core.List.of(allIndices); + } else { + return resolveEmptyOrTrivialWildcardWithAllowedSystemIndices(context, allIndices); + } + } + + private static List resolveEmptyOrTrivialWildcardWithAllowedSystemIndices(Context context, String[] allIndices) { + return Arrays.stream(allIndices) + .filter(name -> { + if (name.startsWith(".")) { + IndexAbstraction abstraction = context.state.metadata().getIndicesLookup().get(name); + assert abstraction != null : "null abstraction for " + name + " but was in array of all indices"; + if (abstraction.isSystem()) { + if (context.netNewSystemIndexPredicate.test(name)) { + return context.systemIndexAccessPredicate.test(name); + } else if (abstraction.getType() == Type.DATA_STREAM || abstraction.getParentDataStream() != null) { + return context.systemIndexAccessPredicate.test(name); + } + } else { + return true; + } + } + return true; + } + ) + .collect(Collectors.toList()); + } + + private static String[] resolveEmptyOrTrivialWildcardToAllIndices(IndicesOptions options, Metadata metadata) { if (options.expandWildcardsOpen() && options.expandWildcardsClosed() && options.expandWildcardsHidden()) { - return Arrays.asList(metadata.getConcreteAllIndices()); + return metadata.getConcreteAllIndices(); } else if (options.expandWildcardsOpen() && options.expandWildcardsClosed()) { - return Arrays.asList(metadata.getConcreteVisibleIndices()); + return metadata.getConcreteVisibleIndices(); } else if (options.expandWildcardsOpen() && options.expandWildcardsHidden()) { - return Arrays.asList(metadata.getConcreteAllOpenIndices()); + return metadata.getConcreteAllOpenIndices(); } else if (options.expandWildcardsOpen()) { - return Arrays.asList(metadata.getConcreteVisibleOpenIndices()); + return metadata.getConcreteVisibleOpenIndices(); } else if (options.expandWildcardsClosed() && options.expandWildcardsHidden()) { - return Arrays.asList(metadata.getConcreteAllClosedIndices()); + return metadata.getConcreteAllClosedIndices(); } else if (options.expandWildcardsClosed()) { - return Arrays.asList(metadata.getConcreteVisibleClosedIndices()); + return metadata.getConcreteVisibleClosedIndices(); } else { - return Collections.emptyList(); + return Strings.EMPTY_ARRAY; } } } diff --git a/server/src/main/java/org/elasticsearch/indices/SystemDataStreamDescriptor.java b/server/src/main/java/org/elasticsearch/indices/SystemDataStreamDescriptor.java index 17b6ab2617951..e4d8ba5cc0781 100644 --- a/server/src/main/java/org/elasticsearch/indices/SystemDataStreamDescriptor.java +++ b/server/src/main/java/org/elasticsearch/indices/SystemDataStreamDescriptor.java @@ -50,6 +50,16 @@ public SystemDataStreamDescriptor(String dataStreamName, String description, Typ List allowedElasticProductOrigins, ExecutorNames executorNames) { this.dataStreamName = Objects.requireNonNull(dataStreamName, "dataStreamName must be specified"); + if (dataStreamName.length() < 2) { + throw new IllegalArgumentException( + "system data stream name [" + dataStreamName + "] but must at least 2 characters in length" + ); + } + if (dataStreamName.charAt(0) != '.') { + throw new IllegalArgumentException( + "system data stream name [" + dataStreamName + "] but must start with the character [.]" + ); + } this.description = Objects.requireNonNull(description, "description must be specified"); this.type = Objects.requireNonNull(type, "type must be specified"); this.composableIndexTemplate = Objects.requireNonNull(composableIndexTemplate, "composableIndexTemplate must be provided"); diff --git a/server/src/main/java/org/elasticsearch/indices/SystemIndexDescriptor.java b/server/src/main/java/org/elasticsearch/indices/SystemIndexDescriptor.java index 315b275f17c22..40d277dcabc57 100644 --- a/server/src/main/java/org/elasticsearch/indices/SystemIndexDescriptor.java +++ b/server/src/main/java/org/elasticsearch/indices/SystemIndexDescriptor.java @@ -104,6 +104,8 @@ public class SystemIndexDescriptor implements IndexPatternMatcher, Comparable priorSystemIndexDescriptors; + private final boolean isNetNew; + /** * The thread pools that actions will use to operate on this descriptor's system indices */ @@ -117,7 +119,7 @@ public class SystemIndexDescriptor implements IndexPatternMatcher, Comparable allowedElasticProductOrigins) { this(indexPattern, null, description, null, null, null, 0, null, null, MapperService.SINGLE_MAPPING_NAME, - Version.CURRENT.minimumCompatibilityVersion(), type, allowedElasticProductOrigins, emptyList(), null); + Version.CURRENT.minimumCompatibilityVersion(), type, allowedElasticProductOrigins, emptyList(), null, false); } /** @@ -171,7 +173,8 @@ public SystemIndexDescriptor(String indexPattern, String description, Type type, Type type, List allowedElasticProductOrigins, List priorSystemIndexDescriptors, - ExecutorNames executorNames + ExecutorNames executorNames, + boolean isNetNew ) { Objects.requireNonNull(indexPattern, "system index pattern must not be null"); if (indexPattern.length() < 2) { @@ -320,6 +323,7 @@ public SystemIndexDescriptor(String indexPattern, String description, Type type, this.executorNames = Objects.nonNull(executorNames) ? executorNames : ExecutorNames.DEFAULT_SYSTEM_INDEX_THREAD_POOLS; + this.isNetNew = isNetNew; } @@ -433,6 +437,10 @@ public List getAllowedElasticProductOrigins() { return allowedElasticProductOrigins; } + public boolean isNetNew() { + return isNetNew; + } + public Version getMappingVersion() { if (type.isManaged() == false) { throw new IllegalStateException(this + " is not managed so there are no mappings or version"); @@ -557,6 +565,7 @@ public static class Builder { private List allowedElasticProductOrigins = emptyList(); private List priorSystemIndexDescriptors = emptyList(); private ExecutorNames executorNames; + private boolean isNetNew = false; private Builder() {} @@ -645,6 +654,11 @@ public Builder setThreadPools(ExecutorNames executorNames) { return this; } + public Builder setNetNew() { + this.isNetNew = true; + return this; + } + /** * Builds a {@link SystemIndexDescriptor} using the fields supplied to this builder. * @return a populated descriptor. @@ -666,7 +680,8 @@ public SystemIndexDescriptor build() { type, allowedElasticProductOrigins, priorSystemIndexDescriptors, - executorNames + executorNames, + isNetNew ); } } diff --git a/server/src/main/java/org/elasticsearch/indices/SystemIndices.java b/server/src/main/java/org/elasticsearch/indices/SystemIndices.java index bad82d88016ba..4d29e3e3e15a6 100644 --- a/server/src/main/java/org/elasticsearch/indices/SystemIndices.java +++ b/server/src/main/java/org/elasticsearch/indices/SystemIndices.java @@ -70,6 +70,7 @@ TASKS_FEATURE_NAME, new Feature(TASKS_FEATURE_NAME, "Manages task results", sing private final CharacterRunAutomaton systemIndexAutomaton; private final CharacterRunAutomaton systemDataStreamIndicesAutomaton; + private final CharacterRunAutomaton netNewSystemIndexAutomaton; private final Predicate systemDataStreamAutomaton; private final Map featureDescriptors; private final Map productToSystemIndicesMatcher; @@ -85,6 +86,7 @@ public SystemIndices(Map pluginAndModulesDescriptors) { checkForOverlappingPatterns(featureDescriptors); checkForDuplicateAliases(this.getSystemIndexDescriptors()); this.systemIndexAutomaton = buildIndexCharacterRunAutomaton(featureDescriptors); + this.netNewSystemIndexAutomaton = buildNetNewIndexCharacterRunAutomaton(featureDescriptors); this.systemDataStreamIndicesAutomaton = buildDataStreamBackingIndicesAutomaton(featureDescriptors); this.systemDataStreamAutomaton = buildDataStreamNamePredicate(featureDescriptors); this.productToSystemIndicesMatcher = getProductToSystemIndicesMap(featureDescriptors); @@ -187,6 +189,10 @@ public boolean isSystemIndexBackingDataStream(String name) { return systemDataStreamIndicesAutomaton.run(name); } + public boolean isNetNewSystemIndex(String indexName) { + return netNewSystemIndexAutomaton.run(indexName); + } + /** * Finds a single matching {@link SystemIndexDescriptor}, if any, for the given index name. * @param name the name of the index @@ -296,6 +302,15 @@ private static CharacterRunAutomaton buildIndexCharacterRunAutomaton(Map featureDescriptors) { + Optional automaton = featureDescriptors.values().stream() + .flatMap(feature -> feature.getIndexDescriptors().stream()) + .filter(SystemIndexDescriptor::isNetNew) + .map(descriptor -> SystemIndexDescriptor.buildAutomaton(descriptor.getIndexPattern(), descriptor.getAliasName())) + .reduce(Operations::union); + return new CharacterRunAutomaton(MinimizationOperations.minimize(automaton.orElse(EMPTY), Integer.MAX_VALUE)); + } + private static Automaton featureToIndexAutomaton(Feature feature) { Optional systemIndexAutomaton = feature.getIndexDescriptors().stream() .map(descriptor -> SystemIndexDescriptor.buildAutomaton(descriptor.getIndexPattern(), descriptor.getAliasName())) @@ -367,6 +382,17 @@ public IllegalArgumentException dataStreamAccessException(ThreadContext threadCo ); } + public IllegalArgumentException netNewSystemIndexAccessException(ThreadContext threadContext, Collection names) { + final String product = threadContext.getHeader(EXTERNAL_SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY); + if (product == null) { + return new IllegalArgumentException("Indices " + Arrays.toString(names.toArray(Strings.EMPTY_ARRAY)) + + " use and access is reserved for system operations"); + } else { + return new IllegalArgumentException("Indices " + Arrays.toString(names.toArray(Strings.EMPTY_ARRAY)) + + " use and access is reserved for system operations"); + } + } + IllegalArgumentException dataStreamAccessException(@Nullable String product, String... dataStreamNames) { if (product == null) { return new IllegalArgumentException("Data stream(s) " + Arrays.toString(dataStreamNames) + diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesActionTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesActionTests.java index 3f7c0754a0427..3feab1306bb72 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesActionTests.java @@ -190,7 +190,7 @@ public void testDeprecationWarningEmittedWhenRequestingNonExistingAliasInSystemP SystemIndexAccessLevel.NONE, null, systemIndices); assertThat(result.size(), equalTo(0)); assertWarnings("this request accesses aliases with names reserved for system indices: [.y], but in a future major version, direct" + - "access to system indices and their aliases will not be allowed"); + " access to system indices and their aliases will not be allowed"); } public void testPostProcessDataStreamAliases() { diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/DateMathExpressionResolverTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/DateMathExpressionResolverTests.java index b594eb31fe844..af53179b8475c 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/DateMathExpressionResolverTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/DateMathExpressionResolverTests.java @@ -14,6 +14,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.Context; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.DateMathExpressionResolver; +import org.elasticsearch.indices.SystemIndices.SystemIndexAccessLevel; import org.elasticsearch.test.ESTestCase; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; @@ -33,7 +34,7 @@ public class DateMathExpressionResolverTests extends ESTestCase { private final DateMathExpressionResolver expressionResolver = new DateMathExpressionResolver(); private final Context context = new Context( ClusterState.builder(new ClusterName("_name")).build(), IndicesOptions.strictExpand(), - name -> false + SystemIndexAccessLevel.NONE ); public void testNormal() throws Exception { @@ -136,7 +137,8 @@ public void testExpression_CustomTimeZoneInIndexName() throws Exception { // rounding to today 00:00 now = DateTime.now(UTC).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0); } - Context context = new Context(this.context.getState(), this.context.getOptions(), now.getMillis(), name -> false); + Context context = new Context(this.context.getState(), this.context.getOptions(), now.getMillis(), + SystemIndexAccessLevel.NONE, name -> false, name -> false); List results = expressionResolver.resolve(context, Arrays.asList("<.marvel-{now/d{yyyy.MM.dd|" + timeZone.getID() + "}}>")); assertThat(results.size(), equalTo(1)); logger.info("timezone: [{}], now [{}], name: [{}]", timeZone, now, results.get(0)); diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverTests.java index aa1ffc080bfa0..67fab9db471a7 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverTests.java @@ -34,6 +34,7 @@ import org.elasticsearch.indices.SystemIndexDescriptor.Type; import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.indices.SystemIndices.Feature; +import org.elasticsearch.indices.SystemIndices.SystemIndexAccessLevel; import org.elasticsearch.indices.TestIndexNameExpressionResolver; import org.elasticsearch.test.ESTestCase; @@ -48,7 +49,6 @@ import java.util.List; import java.util.Set; import java.util.function.Function; -import java.util.function.Predicate; import java.util.stream.Collectors; import static org.elasticsearch.cluster.metadata.DataStreamTestHelper.backingIndexEqualTo; @@ -73,8 +73,6 @@ public class IndexNameExpressionResolverTests extends ESTestCase { - private static final Predicate NONE = name -> false; - private IndexNameExpressionResolver indexNameExpressionResolver; private ThreadContext threadContext; private long epochMillis; @@ -106,7 +104,8 @@ public void testIndexOptionsStrict() { IndicesOptions[] indicesOptions = new IndicesOptions[]{ IndicesOptions.strictExpandOpen(), IndicesOptions.strictExpand()}; for (IndicesOptions options : indicesOptions) { - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options, NONE); + IndexNameExpressionResolver.Context context = + new IndexNameExpressionResolver.Context(state, options, SystemIndexAccessLevel.NONE); String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo"); assertEquals(1, results.length); assertEquals("foo", results[0]); @@ -156,26 +155,26 @@ public void testIndexOptionsStrict() { } IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen(), NONE); + new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen(), SystemIndexAccessLevel.NONE); String[] results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(3, results.length); results = indexNameExpressionResolver.concreteIndexNames(context, (String[])null); assertEquals(3, results.length); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpand(), NONE); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpand(), SystemIndexAccessLevel.NONE); results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(4, results.length); results = indexNameExpressionResolver.concreteIndexNames(context, (String[])null); assertEquals(4, results.length); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen(), NONE); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen(), SystemIndexAccessLevel.NONE); results = indexNameExpressionResolver.concreteIndexNames(context, "foofoo*"); assertEquals(3, results.length); assertThat(results, arrayContainingInAnyOrder("foo", "foobar", "foofoo")); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpand(), NONE); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpand(), SystemIndexAccessLevel.NONE); results = indexNameExpressionResolver.concreteIndexNames(context, "foofoo*"); assertEquals(4, results.length); assertThat(results, arrayContainingInAnyOrder("foo", "foobar", "foofoo", "foofoo-closed")); @@ -191,7 +190,8 @@ public void testIndexOptionsLenient() { IndicesOptions[] indicesOptions = new IndicesOptions[]{IndicesOptions.lenientExpandOpen(), IndicesOptions.lenientExpand()}; for (IndicesOptions options : indicesOptions) { - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options, NONE); + IndexNameExpressionResolver.Context context = + new IndexNameExpressionResolver.Context(state, options, SystemIndexAccessLevel.NONE); String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo"); assertEquals(1, results.length); assertEquals("foo", results[0]); @@ -229,20 +229,20 @@ public void testIndexOptionsLenient() { } IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); + new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), SystemIndexAccessLevel.NONE); String[] results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(3, results.length); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpand(), NONE); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpand(), SystemIndexAccessLevel.NONE); results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(Arrays.toString(results), 4, results.length); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), SystemIndexAccessLevel.NONE); results = indexNameExpressionResolver.concreteIndexNames(context, "foofoo*"); assertEquals(3, results.length); assertThat(results, arrayContainingInAnyOrder("foo", "foobar", "foofoo")); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpand(), NONE); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpand(), SystemIndexAccessLevel.NONE); results = indexNameExpressionResolver.concreteIndexNames(context, "foofoo*"); assertEquals(4, results.length); assertThat(results, arrayContainingInAnyOrder("foo", "foobar", "foofoo", "foofoo-closed")); @@ -261,7 +261,8 @@ public void testIndexOptionsAllowUnavailableDisallowEmpty() { IndicesOptions[] indicesOptions = new IndicesOptions[]{expandOpen, expand}; for (IndicesOptions options : indicesOptions) { - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options, NONE); + IndexNameExpressionResolver.Context context = + new IndexNameExpressionResolver.Context(state, options, SystemIndexAccessLevel.NONE); String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo"); assertEquals(1, results.length); assertEquals("foo", results[0]); @@ -283,11 +284,12 @@ public void testIndexOptionsAllowUnavailableDisallowEmpty() { } } - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, expandOpen, NONE); + IndexNameExpressionResolver.Context context = + new IndexNameExpressionResolver.Context(state, expandOpen, SystemIndexAccessLevel.NONE); String[] results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(3, results.length); - context = new IndexNameExpressionResolver.Context(state, expand, NONE); + context = new IndexNameExpressionResolver.Context(state, expand, SystemIndexAccessLevel.NONE); results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(4, results.length); } @@ -305,7 +307,7 @@ public void testIndexOptionsWildcardExpansion() { // Only closed IndicesOptions options = IndicesOptions.fromOptions(false, true, false, true, false); - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options, NONE); + IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options, SystemIndexAccessLevel.NONE); String[] results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(1, results.length); assertEquals("foo", results[0]); @@ -330,7 +332,7 @@ public void testIndexOptionsWildcardExpansion() { // Only open options = IndicesOptions.fromOptions(false, true, true, false, false); - context = new IndexNameExpressionResolver.Context(state, options, NONE); + context = new IndexNameExpressionResolver.Context(state, options, SystemIndexAccessLevel.NONE); results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(2, results.length); assertThat(results, arrayContainingInAnyOrder("bar", "foobar")); @@ -354,7 +356,7 @@ public void testIndexOptionsWildcardExpansion() { // Open and closed options = IndicesOptions.fromOptions(false, true, true, true, false); - context = new IndexNameExpressionResolver.Context(state, options, NONE); + context = new IndexNameExpressionResolver.Context(state, options, SystemIndexAccessLevel.NONE); results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(3, results.length); assertThat(results, arrayContainingInAnyOrder("bar", "foobar", "foo")); @@ -393,7 +395,7 @@ public void testIndexOptionsWildcardExpansion() { // open closed and hidden options = IndicesOptions.fromOptions(false, true, true, true, true); - context = new IndexNameExpressionResolver.Context(state, options, NONE); + context = new IndexNameExpressionResolver.Context(state, options, SystemIndexAccessLevel.NONE); results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(7, results.length); assertThat(results, arrayContainingInAnyOrder("bar", "foobar", "foo", "hidden", "hidden-closed", ".hidden", ".hidden-closed")); @@ -435,7 +437,7 @@ public void testIndexOptionsWildcardExpansion() { // open and hidden options = IndicesOptions.fromOptions(false, true, true, false, true); - context = new IndexNameExpressionResolver.Context(state, options, NONE); + context = new IndexNameExpressionResolver.Context(state, options, SystemIndexAccessLevel.NONE); results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(4, results.length); assertThat(results, arrayContainingInAnyOrder("bar", "foobar", "hidden", ".hidden")); @@ -454,7 +456,7 @@ public void testIndexOptionsWildcardExpansion() { // closed and hidden options = IndicesOptions.fromOptions(false, true, false, true, true); - context = new IndexNameExpressionResolver.Context(state, options, NONE); + context = new IndexNameExpressionResolver.Context(state, options, SystemIndexAccessLevel.NONE); results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(3, results.length); assertThat(results, arrayContainingInAnyOrder("foo", "hidden-closed", ".hidden-closed")); @@ -473,7 +475,7 @@ public void testIndexOptionsWildcardExpansion() { // only hidden options = IndicesOptions.fromOptions(false, true, false, false, true); - context = new IndexNameExpressionResolver.Context(state, options, NONE); + context = new IndexNameExpressionResolver.Context(state, options, SystemIndexAccessLevel.NONE); results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertThat(results, emptyArray()); @@ -487,7 +489,7 @@ public void testIndexOptionsWildcardExpansion() { assertThat(results, arrayContainingInAnyOrder("hidden-closed")); options = IndicesOptions.fromOptions(false, false, true, true, true); - IndexNameExpressionResolver.Context context2 = new IndexNameExpressionResolver.Context(state, options, NONE); + IndexNameExpressionResolver.Context context2 = new IndexNameExpressionResolver.Context(state, options, SystemIndexAccessLevel.NONE); IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context2, "-*")); assertThat(infe.getResourceId().toString(), equalTo("[-*]")); @@ -504,7 +506,8 @@ public void testIndexOptionsNoExpandWildcards() { //ignore unavailable and allow no indices { IndicesOptions noExpandLenient = IndicesOptions.fromOptions(true, true, false, false, randomBoolean()); - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandLenient, NONE); + IndexNameExpressionResolver.Context context = + new IndexNameExpressionResolver.Context(state, noExpandLenient, SystemIndexAccessLevel.NONE); String[] results = indexNameExpressionResolver.concreteIndexNames(context, "baz*"); assertThat(results, emptyArray()); @@ -526,7 +529,8 @@ public void testIndexOptionsNoExpandWildcards() { //ignore unavailable but don't allow no indices { IndicesOptions noExpandDisallowEmpty = IndicesOptions.fromOptions(true, false, false, false, randomBoolean()); - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandDisallowEmpty, NONE); + IndexNameExpressionResolver.Context context = + new IndexNameExpressionResolver.Context(state, noExpandDisallowEmpty, SystemIndexAccessLevel.NONE); { IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, @@ -551,7 +555,8 @@ public void testIndexOptionsNoExpandWildcards() { //error on unavailable but allow no indices { IndicesOptions noExpandErrorUnavailable = IndicesOptions.fromOptions(false, true, false, false, randomBoolean()); - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandErrorUnavailable, NONE); + IndexNameExpressionResolver.Context context = + new IndexNameExpressionResolver.Context(state, noExpandErrorUnavailable, SystemIndexAccessLevel.NONE); { String[] results = indexNameExpressionResolver.concreteIndexNames(context, "baz*"); assertThat(results, emptyArray()); @@ -577,7 +582,8 @@ public void testIndexOptionsNoExpandWildcards() { //error on both unavailable and no indices { IndicesOptions noExpandStrict = IndicesOptions.fromOptions(false, false, false, false, randomBoolean()); - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandStrict, NONE); + IndexNameExpressionResolver.Context context = + new IndexNameExpressionResolver.Context(state, noExpandStrict, SystemIndexAccessLevel.NONE); IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "baz*")); assertThat(infe.getIndex().getName(), equalTo("baz*")); @@ -603,48 +609,48 @@ public void testIndexOptionsSingleIndexNoExpandWildcards() { //error on both unavailable and no indices + every alias needs to expand to a single index { - IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed(), NONE); + IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, + IndicesOptions.strictSingleIndexNoExpandForbidClosed(), SystemIndexAccessLevel.NONE); IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "baz*")); assertThat(infe.getIndex().getName(), equalTo("baz*")); } { - IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed(), NONE); + IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, + IndicesOptions.strictSingleIndexNoExpandForbidClosed(), SystemIndexAccessLevel.NONE); IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*")); assertThat(infe.getIndex().getName(), equalTo("baz*")); } { - IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed(), NONE); + IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, + IndicesOptions.strictSingleIndexNoExpandForbidClosed(), SystemIndexAccessLevel.NONE); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "foofoobar")); assertThat(e.getMessage(), containsString("alias [foofoobar] has more than one index associated with it")); } { - IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed(), NONE); + IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, + IndicesOptions.strictSingleIndexNoExpandForbidClosed(), SystemIndexAccessLevel.NONE); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "foo", "foofoobar")); assertThat(e.getMessage(), containsString("alias [foofoobar] has more than one index associated with it")); } { - IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed(), NONE); + IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, + IndicesOptions.strictSingleIndexNoExpandForbidClosed(), SystemIndexAccessLevel.NONE); IndexClosedException ince = expectThrows(IndexClosedException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "foofoo-closed", "foofoobar")); assertThat(ince.getMessage(), equalTo("closed")); assertEquals(ince.getIndex().getName(), "foofoo-closed"); } - IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed(), NONE); + IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, + IndicesOptions.strictSingleIndexNoExpandForbidClosed(), SystemIndexAccessLevel.NONE); String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo", "barbaz"); assertEquals(2, results.length); assertThat(results, arrayContainingInAnyOrder("foo", "foofoo")); @@ -654,7 +660,8 @@ public void testIndexOptionsEmptyCluster() { ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(Metadata.builder().build()).build(); IndicesOptions options = IndicesOptions.strictExpandOpen(); - final IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options, NONE); + final IndexNameExpressionResolver.Context context = + new IndexNameExpressionResolver.Context(state, options, SystemIndexAccessLevel.NONE); String[] results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertThat(results, emptyArray()); @@ -675,7 +682,7 @@ public void testIndexOptionsEmptyCluster() { final IndexNameExpressionResolver.Context context2 = - new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); + new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), SystemIndexAccessLevel.NONE); results = indexNameExpressionResolver.concreteIndexNames(context2, Strings.EMPTY_ARRAY); assertThat(results, emptyArray()); results = indexNameExpressionResolver.concreteIndexNames(context2, "foo"); @@ -686,7 +693,8 @@ public void testIndexOptionsEmptyCluster() { assertThat(results, emptyArray()); final IndexNameExpressionResolver.Context context3 = - new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, false, true, false), NONE); + new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, false, true, false), + SystemIndexAccessLevel.NONE); IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context3, Strings.EMPTY_ARRAY)); assertThat(infe.getResourceId().toString(), equalTo("[_all]")); @@ -712,7 +720,7 @@ public void testConcreteIndicesIgnoreIndicesOneMissingIndex() { .put(indexBuilder("kuku")); ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen(), NONE); + new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen(), SystemIndexAccessLevel.NONE); IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "testZZZ")); @@ -725,7 +733,7 @@ public void testConcreteIndicesIgnoreIndicesOneMissingIndexOtherFound() { .put(indexBuilder("kuku")); ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); + new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), SystemIndexAccessLevel.NONE); assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "testXXX", "testZZZ")), equalTo(newHashSet("testXXX"))); @@ -737,7 +745,7 @@ public void testConcreteIndicesIgnoreIndicesAllMissing() { .put(indexBuilder("kuku")); ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen(), NONE); + new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen(), SystemIndexAccessLevel.NONE); IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "testMo", "testMahdy")); @@ -750,7 +758,7 @@ public void testConcreteIndicesIgnoreIndicesEmptyRequest() { .put(indexBuilder("kuku")); ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); + new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), SystemIndexAccessLevel.NONE); assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, new String[]{})), equalTo(newHashSet("kuku", "testXXX"))); } @@ -758,7 +766,7 @@ public void testConcreteIndicesNoIndicesErrorMessage() { Metadata.Builder mdBuilder = Metadata.builder(); ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, - IndicesOptions.fromOptions(false, false, true, true), NONE); + IndicesOptions.fromOptions(false, false, true, true), SystemIndexAccessLevel.NONE); IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndices(context, new String[]{})); assertThat(infe.getMessage(), is("no such index [null] and no indices exist")); @@ -768,7 +776,7 @@ public void testConcreteIndicesNoIndicesErrorMessageNoExpand() { Metadata.Builder mdBuilder = Metadata.builder(); ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, - IndicesOptions.fromOptions(false, false, false, false), NONE); + IndicesOptions.fromOptions(false, false, false, false), SystemIndexAccessLevel.NONE); IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndices(context, new String[]{})); assertThat(infe.getMessage(), is("no such index [_all] and no indices exist")); @@ -784,16 +792,20 @@ public void testConcreteIndicesWildcardExpansion() { ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, false, false), NONE); + new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, false, false), + SystemIndexAccessLevel.NONE); assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "testX*")), equalTo(new HashSet())); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, true, false), NONE); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, true, false), + SystemIndexAccessLevel.NONE); assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "testX*")), equalTo(newHashSet("testXXX", "testXXY"))); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, false, true), NONE); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, false, true), + SystemIndexAccessLevel.NONE); assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "testX*")), equalTo(newHashSet("testXYY"))); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, true, true), NONE); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, true, true), + SystemIndexAccessLevel.NONE); assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "testX*")), equalTo(newHashSet("testXXX", "testXXY", "testXYY"))); } @@ -811,7 +823,7 @@ public void testConcreteIndicesWildcardWithNegation() { ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, - IndicesOptions.fromOptions(true, true, true, true), NONE); + IndicesOptions.fromOptions(true, true, true, true), SystemIndexAccessLevel.NONE); assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "testX*")), equalTo(newHashSet("testXXX", "testXXY", "testXYY"))); @@ -1099,7 +1111,8 @@ public void testConcreteIndicesAllPatternRandom() { { ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(Metadata.builder().build()).build(); - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, indicesOptions, NONE); + IndexNameExpressionResolver.Context context = + new IndexNameExpressionResolver.Context(state, indicesOptions, SystemIndexAccessLevel.NONE); // with no indices, asking for all indices should return empty list or exception, depending on indices options if (indicesOptions.allowNoIndices()) { @@ -1118,7 +1131,8 @@ public void testConcreteIndicesAllPatternRandom() { .put(indexBuilder("bbb").state(State.OPEN).putAlias(AliasMetadata.builder("bbb_alias1"))) .put(indexBuilder("ccc").state(State.CLOSE).putAlias(AliasMetadata.builder("ccc_alias1"))); ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, indicesOptions, NONE); + IndexNameExpressionResolver.Context context = + new IndexNameExpressionResolver.Context(state, indicesOptions, SystemIndexAccessLevel.NONE); if (indicesOptions.expandWildcardsOpen() || indicesOptions.expandWildcardsClosed() || indicesOptions.allowNoIndices()) { String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(context, allIndices); assertThat(concreteIndices, notNullValue()); @@ -1148,7 +1162,8 @@ public void testConcreteIndicesWildcardNoMatch() { .put(indexBuilder("bbb").state(State.OPEN).putAlias(AliasMetadata.builder("bbb_alias1"))) .put(indexBuilder("ccc").state(State.CLOSE).putAlias(AliasMetadata.builder("ccc_alias1"))); ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, indicesOptions, NONE); + IndexNameExpressionResolver.Context context = + new IndexNameExpressionResolver.Context(state, indicesOptions, SystemIndexAccessLevel.NONE); // asking for non existing wildcard pattern should return empty list or exception if (indicesOptions.allowNoIndices()) { @@ -1277,20 +1292,20 @@ public void testIndexOptionsFailClosedIndicesAndAliases() { ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); IndexNameExpressionResolver.Context contextICE = - new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpenAndForbidClosed(), NONE); + new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpenAndForbidClosed(), SystemIndexAccessLevel.NONE); expectThrows(IndexClosedException.class, () -> indexNameExpressionResolver.concreteIndexNames(contextICE, "foo1-closed")); expectThrows(IndexClosedException.class, () -> indexNameExpressionResolver.concreteIndexNames(contextICE, "foobar1-closed")); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, contextICE.getOptions().allowNoIndices(), contextICE.getOptions().expandWildcardsOpen(), - contextICE.getOptions().expandWildcardsClosed(), contextICE.getOptions()), NONE); + contextICE.getOptions().expandWildcardsClosed(), contextICE.getOptions()), SystemIndexAccessLevel.NONE); String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo1-closed"); assertThat(results, emptyArray()); results = indexNameExpressionResolver.concreteIndexNames(context, "foobar1-closed"); assertThat(results, emptyArray()); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), SystemIndexAccessLevel.NONE); results = indexNameExpressionResolver.concreteIndexNames(context, "foo1-closed"); assertThat(results, arrayWithSize(1)); assertThat(results, arrayContaining("foo1-closed")); @@ -1300,7 +1315,8 @@ public void testIndexOptionsFailClosedIndicesAndAliases() { assertThat(results, arrayContaining("foo1-closed")); // testing an alias pointing to three indices: - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpenAndForbidClosed(), NONE); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpenAndForbidClosed(), + SystemIndexAccessLevel.NONE); try { indexNameExpressionResolver.concreteIndexNames(context, "foobar2-closed"); fail("foo2-closed should be closed, but it is open"); @@ -1310,12 +1326,12 @@ public void testIndexOptionsFailClosedIndicesAndAliases() { context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, context.getOptions().allowNoIndices(), context.getOptions().expandWildcardsOpen(), - context.getOptions().expandWildcardsClosed(), context.getOptions()), NONE); + context.getOptions().expandWildcardsClosed(), context.getOptions()), SystemIndexAccessLevel.NONE); results = indexNameExpressionResolver.concreteIndexNames(context, "foobar2-closed"); assertThat(results, arrayWithSize(1)); assertThat(results, arrayContaining("foo3")); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), SystemIndexAccessLevel.NONE); results = indexNameExpressionResolver.concreteIndexNames(context, "foobar2-closed"); assertThat(results, arrayWithSize(3)); assertThat(results, arrayContainingInAnyOrder("foo1-closed", "foo2-closed", "foo3")); @@ -1328,7 +1344,8 @@ public void testDedupConcreteIndices() { IndicesOptions[] indicesOptions = new IndicesOptions[]{ IndicesOptions.strictExpandOpen(), IndicesOptions.strictExpand(), IndicesOptions.lenientExpandOpen(), IndicesOptions.strictExpandOpenAndForbidClosed()}; for (IndicesOptions options : indicesOptions) { - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options, NONE); + IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options, + SystemIndexAccessLevel.NONE); String[] results = indexNameExpressionResolver.concreteIndexNames(context, "index1", "index1", "alias1"); assertThat(results, equalTo(new String[]{"index1"})); } @@ -1349,11 +1366,11 @@ public void testFilterClosedIndicesOnAliases() { ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); + new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), SystemIndexAccessLevel.NONE); String[] strings = indexNameExpressionResolver.concreteIndexNames(context, "alias-*"); assertArrayEquals(new String[] {"test-0"}, strings); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen(), NONE); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen(), SystemIndexAccessLevel.NONE); strings = indexNameExpressionResolver.concreteIndexNames(context, "alias-*"); assertArrayEquals(new String[] {"test-0"}, strings); @@ -1765,7 +1782,7 @@ public void testInvalidIndex() { Metadata.Builder mdBuilder = Metadata.builder().put(indexBuilder("test")); ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); + new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), SystemIndexAccessLevel.NONE); InvalidIndexNameException iine = expectThrows(InvalidIndexNameException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "_foo")); diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/WildcardExpressionResolverTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/WildcardExpressionResolverTests.java index 9ac12a8d39b09..cb6960044ce0d 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/WildcardExpressionResolverTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/WildcardExpressionResolverTests.java @@ -14,6 +14,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata.State; import org.elasticsearch.index.IndexNotFoundException; +import org.elasticsearch.indices.SystemIndices.SystemIndexAccessLevel; import org.elasticsearch.test.ESTestCase; import java.util.Arrays; @@ -42,7 +43,7 @@ public void testConvertWildcardsJustIndicesTests() { IndexNameExpressionResolver.WildcardExpressionResolver resolver = new IndexNameExpressionResolver.WildcardExpressionResolver(); IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); + new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), SystemIndexAccessLevel.NONE); assertThat(newHashSet(resolver.resolve(context, Collections.singletonList("testXXX"))), equalTo(newHashSet("testXXX"))); assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testXXX", "testYYY"))), equalTo(newHashSet("testXXX", "testYYY"))); assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testXXX", "ku*"))), equalTo(newHashSet("testXXX", "kuku"))); @@ -71,7 +72,7 @@ public void testConvertWildcardsTests() { IndexNameExpressionResolver.WildcardExpressionResolver resolver = new IndexNameExpressionResolver.WildcardExpressionResolver(); IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); + new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), SystemIndexAccessLevel.NONE); assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testYY*", "alias*"))), equalTo(newHashSet("testXXX", "testXYY", "testYYY"))); assertThat(newHashSet(resolver.resolve(context, Collections.singletonList("-kuku"))), equalTo(newHashSet("-kuku"))); @@ -94,12 +95,14 @@ public void testConvertWildcardsOpenClosedIndicesTests() { IndexNameExpressionResolver.WildcardExpressionResolver resolver = new IndexNameExpressionResolver.WildcardExpressionResolver(); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, - IndicesOptions.fromOptions(true, true, true, true), NONE); + IndicesOptions.fromOptions(true, true, true, true), SystemIndexAccessLevel.NONE); assertThat(newHashSet(resolver.resolve(context, Collections.singletonList("testX*"))), equalTo(newHashSet("testXXX", "testXXY", "testXYY"))); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, false, true), NONE); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, false, true), + SystemIndexAccessLevel.NONE); assertThat(newHashSet(resolver.resolve(context, Collections.singletonList("testX*"))), equalTo(newHashSet("testXYY"))); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, true, false), NONE); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, true, false), + SystemIndexAccessLevel.NONE); assertThat(newHashSet(resolver.resolve(context, Collections.singletonList("testX*"))), equalTo(newHashSet("testXXX", "testXXY"))); } @@ -117,7 +120,7 @@ public void testMultipleWildcards() { IndexNameExpressionResolver.WildcardExpressionResolver resolver = new IndexNameExpressionResolver.WildcardExpressionResolver(); IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); + new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), SystemIndexAccessLevel.NONE); assertThat(newHashSet(resolver.resolve(context, Collections.singletonList("test*X*"))), equalTo(newHashSet("testXXX", "testXXY", "testXYY"))); assertThat(newHashSet(resolver.resolve(context, Collections.singletonList("test*X*Y"))), equalTo(newHashSet("testXXY", "testXYY"))); @@ -137,7 +140,7 @@ public void testAll() { IndexNameExpressionResolver.WildcardExpressionResolver resolver = new IndexNameExpressionResolver.WildcardExpressionResolver(); IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); + new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), SystemIndexAccessLevel.NONE); assertThat(newHashSet(resolver.resolve(context, Collections.singletonList("_all"))), equalTo(newHashSet("testXXX", "testXYY", "testYYY"))); } @@ -155,15 +158,15 @@ public void testResolveAliases() { IndicesOptions indicesAndAliasesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), true, false, true, false, false, false); IndexNameExpressionResolver.Context indicesAndAliasesContext = - new IndexNameExpressionResolver.Context(state, indicesAndAliasesOptions, NONE); + new IndexNameExpressionResolver.Context(state, indicesAndAliasesOptions, SystemIndexAccessLevel.NONE); // ignoreAliases option is set, WildcardExpressionResolver throws error when IndicesOptions skipAliasesIndicesOptions = IndicesOptions.fromOptions(true, true, true, false, true, false, true, false); IndexNameExpressionResolver.Context skipAliasesLenientContext = - new IndexNameExpressionResolver.Context(state, skipAliasesIndicesOptions, NONE); + new IndexNameExpressionResolver.Context(state, skipAliasesIndicesOptions, SystemIndexAccessLevel.NONE); // ignoreAliases option is set, WildcardExpressionResolver resolves the provided expressions only against the defined indices IndicesOptions errorOnAliasIndicesOptions = IndicesOptions.fromOptions(false, false, true, false, true, false, true, false); IndexNameExpressionResolver.Context skipAliasesStrictContext = - new IndexNameExpressionResolver.Context(state, errorOnAliasIndicesOptions, NONE); + new IndexNameExpressionResolver.Context(state, errorOnAliasIndicesOptions, SystemIndexAccessLevel.NONE); { List indices = resolver.resolve(indicesAndAliasesContext, Collections.singletonList("foo_a*")); @@ -230,7 +233,7 @@ public void testResolveDataStreams() { IndicesOptions indicesAndAliasesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), true, false, true, false, false, false); IndexNameExpressionResolver.Context indicesAndAliasesContext = - new IndexNameExpressionResolver.Context(state, indicesAndAliasesOptions, NONE); + new IndexNameExpressionResolver.Context(state, indicesAndAliasesOptions, SystemIndexAccessLevel.NONE); // data streams are not included but expression matches the data stream List indices = resolver.resolve(indicesAndAliasesContext, Collections.singletonList("foo_*")); @@ -245,7 +248,7 @@ public void testResolveDataStreams() { IndicesOptions indicesAndAliasesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), true, false, true, false, false, false); IndexNameExpressionResolver.Context indicesAliasesAndDataStreamsContext = new IndexNameExpressionResolver.Context(state, - indicesAndAliasesOptions, false, false, true, NONE); + indicesAndAliasesOptions, false, false, true, SystemIndexAccessLevel.NONE, NONE, NONE); // data stream's corresponding backing indices are resolved List indices = resolver.resolve(indicesAliasesAndDataStreamsContext, Collections.singletonList("foo_*")); @@ -264,7 +267,7 @@ public void testResolveDataStreams() { IndicesOptions indicesAliasesAndExpandHiddenOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), true, false, true, true, false, false, false); IndexNameExpressionResolver.Context indicesAliasesDataStreamsAndHiddenIndices = new IndexNameExpressionResolver.Context(state, - indicesAliasesAndExpandHiddenOptions, false, false, true, NONE); + indicesAliasesAndExpandHiddenOptions, false, false, true, SystemIndexAccessLevel.NONE, NONE, NONE); // data stream's corresponding backing indices are resolved List indices = resolver.resolve(indicesAliasesDataStreamsAndHiddenIndices, Collections.singletonList("foo_*")); @@ -292,12 +295,13 @@ public void testMatchesConcreteIndicesWildcardAndAliases() { // expressions against the defined indices and aliases IndicesOptions indicesAndAliasesOptions = IndicesOptions.fromOptions(false, false, true, false, true, false, false, false); IndexNameExpressionResolver.Context indicesAndAliasesContext = - new IndexNameExpressionResolver.Context(state, indicesAndAliasesOptions, NONE); + new IndexNameExpressionResolver.Context(state, indicesAndAliasesOptions, SystemIndexAccessLevel.NONE); // ignoreAliases option is set, WildcardExpressionResolver resolves the provided expressions // only against the defined indices IndicesOptions onlyIndicesOptions = IndicesOptions.fromOptions(false, false, true, false, true, false, true, false); - IndexNameExpressionResolver.Context onlyIndicesContext = new IndexNameExpressionResolver.Context(state, onlyIndicesOptions, NONE); + IndexNameExpressionResolver.Context onlyIndicesContext = + new IndexNameExpressionResolver.Context(state, onlyIndicesOptions, SystemIndexAccessLevel.NONE); { Set matches = IndexNameExpressionResolver.WildcardExpressionResolver.matches(indicesAndAliasesContext, diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStep.java index 03cadcceaaebb..d05a77d980e91 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStep.java @@ -18,6 +18,7 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.UUIDs; import org.elasticsearch.index.Index; +import org.elasticsearch.indices.SystemIndices.SystemIndexAccessLevel; import java.util.Collections; import java.util.List; @@ -139,7 +140,7 @@ public ResolverContext() { } public ResolverContext(long startTime) { - super(null, null, startTime, false, false, false, false, name -> false); + super(null, null, startTime, false, false, false, false, SystemIndexAccessLevel.ALL, name -> false, name -> false); } @Override diff --git a/x-pack/plugin/fleet/src/javaRestTest/java/org/elasticsearch/xpack/fleet/FleetDataStreamIT.java b/x-pack/plugin/fleet/src/javaRestTest/java/org/elasticsearch/xpack/fleet/FleetDataStreamIT.java index 66df3744e25fa..5cf3034ea14c3 100644 --- a/x-pack/plugin/fleet/src/javaRestTest/java/org/elasticsearch/xpack/fleet/FleetDataStreamIT.java +++ b/x-pack/plugin/fleet/src/javaRestTest/java/org/elasticsearch/xpack/fleet/FleetDataStreamIT.java @@ -17,7 +17,6 @@ import org.elasticsearch.test.SecuritySettingsSourceField; import org.elasticsearch.test.rest.ESRestTestCase; -import java.util.Collections; import java.util.List; import static java.util.Collections.emptyList; @@ -110,9 +109,11 @@ private void assertGetAliasAPIBehavesAsExpected(String regularIndex, String regu // The rest of these produce a warning RequestOptions consumeWarningsOptions = RequestOptions.DEFAULT.toBuilder() .setWarningsHandler( - warnings -> Collections.singletonList( + warnings -> org.elasticsearch.core.List.of( "this request accesses system indices: [.fleet-artifacts-7], but " - + "in a future major version, direct access to system indices will be prevented by default" + + "in a future major version, direct access to system indices will be prevented by default", + "this request accesses aliases with names reserved for system indices: [.fleet-artifacts], but in a future major " + + "version, direct access to system indices and their aliases will not be allowed" ).equals(warnings) == false ) .build(); diff --git a/x-pack/plugin/sql/qa/server/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/RestSqlSecurityIT.java b/x-pack/plugin/sql/qa/server/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/RestSqlSecurityIT.java index ecff51e9e7ec3..52e4a5876eb99 100644 --- a/x-pack/plugin/sql/qa/server/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/RestSqlSecurityIT.java +++ b/x-pack/plugin/sql/qa/server/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/RestSqlSecurityIT.java @@ -231,11 +231,16 @@ private static Map runSql( if (warnings.isEmpty()) { // No warnings is OK return false; - } else if (warnings.size() > 1) { + } else if (warnings.size() > 2) { return true; } else { - String warning = warnings.get(0); - return warning.startsWith("this request accesses system indices: ") == false; + for (String warning : warnings) { + if (warning.startsWith("this request accesses system indices: ") == false + && warning.startsWith("this request accesses aliases with names reserved for system indices: ") == false) { + return true; + } + } + return false; } }); }