Skip to content

All system indices are hidden indices #79512

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 64 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
8920c6c
Force system indices to be hidden in IndexMetadata
williamrandolph Oct 19, 2021
4c1925d
Hide system data streams
williamrandolph Oct 19, 2021
90790f8
Fix some tests
williamrandolph Oct 19, 2021
21a4958
Merge branch 'master' into si/hide-them-all
williamrandolph Oct 19, 2021
9813241
Merge branch 'master' into si/hide-them-all
williamrandolph Oct 20, 2021
63ebe5d
Merge branch 'master' into si/hide-them-all
williamrandolph Oct 20, 2021
e7c100b
Update feature migration tests
williamrandolph Oct 20, 2021
9909b95
Roll back unintended change
williamrandolph Oct 20, 2021
f193d83
ML datafeed config defaults to searching hidden indices
williamrandolph Oct 21, 2021
d376412
Merge branch 'master' into si/hide-them-all
williamrandolph Oct 21, 2021
00de706
Prevent unmanaged system indices from becoming visible
williamrandolph Oct 21, 2021
b4a3ab9
Fix watcher test
williamrandolph Oct 21, 2021
7758928
checkstyle
williamrandolph Oct 22, 2021
f00c70e
Use expectThrows instead of try/catch
williamrandolph Oct 22, 2021
a09d572
Change validation in TransportUpdateSettingsAction
williamrandolph Oct 22, 2021
1c99c35
Remove change to data stream index abstraction
williamrandolph Oct 22, 2021
e0c85b2
Back out bad assertion in IndexMetadata
williamrandolph Oct 22, 2021
a47f12f
Remove validation from service in favor of transport action
williamrandolph Oct 22, 2021
a978c38
Fix logic in tests
williamrandolph Oct 22, 2021
be652fa
Validate index creation settings in transport action
williamrandolph Oct 22, 2021
e2432d3
Remove metadata create index service validation
williamrandolph Oct 22, 2021
dd9ea2f
Fix cluster info service test
williamrandolph Oct 22, 2021
5489fa5
Formatting and renaming
williamrandolph Oct 22, 2021
9cee8a1
Fix test
williamrandolph Oct 22, 2021
067e63f
Fix test setup issue for index name expression resolver
williamrandolph Oct 22, 2021
d8291ca
Make sure system data stream backing indices are hidden
williamrandolph Oct 22, 2021
6d552a2
Make sure transport request adds hidden index setting if missing
williamrandolph Oct 22, 2021
c8d8c93
Validate and set default for autocreated system indices
williamrandolph Oct 22, 2021
813a8aa
Don't test 'non-hidden' system indices
williamrandolph Oct 23, 2021
8dac8c5
Skip some reindex rest compat tests
williamrandolph Oct 23, 2021
1084036
Merge branch 'master' into si/hide-them-all
williamrandolph Oct 23, 2021
a5890ae
Apply spotless everywhere
williamrandolph Nov 3, 2021
17e6f23
Merge branch 'master' into si/hide-them-all
williamrandolph Nov 3, 2021
45d5911
Checkstyle and spotless
williamrandolph Nov 3, 2021
4217651
Merge branch 'master' into si/hide-them-all
williamrandolph Nov 4, 2021
c47de88
Add some code to hide system aliases
williamrandolph Nov 9, 2021
2f5b5fc
Add failing tests and do spotless cleanup
williamrandolph Nov 10, 2021
2be29e8
Merge branch 'master' into si/hide-them-all
williamrandolph Nov 10, 2021
48ef4f6
Fix up some tests where behavior changed
williamrandolph Nov 10, 2021
fcbab57
Hide system aliases in create index service
williamrandolph Nov 10, 2021
bd1edae
Watch out for null Booleans
williamrandolph Nov 11, 2021
b3b272a
Handle the null Boolean take 2
williamrandolph Nov 11, 2021
7b6d3f9
Merge branch 'master' into si/hide-them-all
williamrandolph Nov 11, 2021
2141100
Expand hidden indices in snapshot test
williamrandolph Nov 11, 2021
514ea37
Merge branch 'master' into si/hide-them-all
williamrandolph Nov 11, 2021
c1a249c
Fix up tests for v1 aliases
williamrandolph Nov 11, 2021
ac7897c
Add composable v2 template create test
williamrandolph Nov 11, 2021
cd0146c
Clean up tests, add autocreate v2 alias test
williamrandolph Nov 11, 2021
680667e
Hide system aliases when adding them via alias endpoints
williamrandolph Nov 12, 2021
8650426
Refactoring and cleanup
williamrandolph Nov 16, 2021
dc85975
Merge branch 'master' into si/hide-them-all
williamrandolph Nov 16, 2021
a9af5d7
remove todos
williamrandolph Nov 16, 2021
178b456
Merge branch 'master' into si/hide-them-all
williamrandolph Nov 30, 2021
5b95212
Check system indices when simulating and validating templates
williamrandolph Nov 30, 2021
6f93f86
Restore test coverage for hidden indices
williamrandolph Nov 30, 2021
62744ca
Handle non normalized strings
williamrandolph Nov 30, 2021
33fa6fc
Fix typo, remove unneeded header
williamrandolph Nov 30, 2021
6dd476d
Use system index default settings in tests
williamrandolph Nov 30, 2021
65dea59
Rename method for clarity
williamrandolph Nov 30, 2021
adfd04f
apply spotless
williamrandolph Nov 30, 2021
841ffd4
Add known issue for reenabling tests
williamrandolph Nov 30, 2021
5dfdade
Merge branch 'master' into si/hide-them-all
williamrandolph Dec 1, 2021
e20b545
Merge branch 'master' into si/hide-them-all
williamrandolph Dec 6, 2021
d62a275
Update docs/changelog/79512.yaml
williamrandolph Dec 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.apache.http.util.EntityUtils;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.xcontent.json.JsonXContent;
Expand All @@ -23,6 +24,7 @@
import java.util.Map;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;

public class KibanaSystemIndexIT extends ESRestTestCase {
Expand Down Expand Up @@ -218,6 +220,26 @@ public void testUpdateIndexSettings() throws IOException {
assertThat(response.getStatusLine().getStatusCode(), is(200));
}

public void testCannotCreateVisibleSystemIndex() {
Request request = request("PUT", "/" + indexName);
request.setJsonEntity("{\"settings\": {\"index.hidden\":\"false\"}}");
ResponseException exception = expectThrows(ResponseException.class, () -> client().performRequest(request));
assertThat(exception.getResponse().getStatusLine().getStatusCode(), is(400));
assertThat(exception.getMessage(), containsString("System indices must have index.hidden set to true."));
}

public void testCannotSetVisible() throws IOException {
Request putIndexRequest = request("PUT", "/" + indexName);
Response response = client().performRequest(putIndexRequest);
assertThat(response.getStatusLine().getStatusCode(), is(200));

Request putSettingsRequest = request("PUT", "/" + indexName + "/_settings");
putSettingsRequest.setJsonEntity("{ \"index.hidden\" : false }");
ResponseException exception = expectThrows(ResponseException.class, () -> client().performRequest(putSettingsRequest));
assertThat(exception.getResponse().getStatusLine().getStatusCode(), is(400));
assertThat(exception.getMessage(), containsString("System indices must have index.hidden set to true."));
}

public void testGetIndex() throws IOException {
Request request = request("PUT", "/" + indexName);
Response response = client().performRequest(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,17 @@ public void createSystemIndexForDescriptor(SystemIndexDescriptor descriptor) thr
String indexName = Optional.ofNullable(descriptor.getPrimaryIndex()).orElse(descriptor.getIndexPattern().replace("*", "old"));
CreateIndexRequestBuilder createRequest = prepareCreate(indexName);
createRequest.setWaitForActiveShards(ActiveShardCount.ALL);
if (descriptor.getSettings() != null) {
createRequest.setSettings(Settings.builder().put("index.version.created", Version.CURRENT).build());
} else {
if (SystemIndexDescriptor.DEFAULT_SETTINGS.equals(descriptor.getSettings())) {
// unmanaged
createRequest.setSettings(
createSimpleSettings(
Version.V_7_0_0,
descriptor.isInternal() ? INTERNAL_UNMANAGED_FLAG_VALUE : EXTERNAL_UNMANAGED_FLAG_VALUE
)
);
} else {
// managed
createRequest.setSettings(Settings.builder().put("index.version.created", Version.CURRENT).build());
}
if (descriptor.getMappings() == null) {
createRequest.setMapping(createSimpleMapping(false, descriptor.isInternal()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@
- do:
warnings:
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"
indices.refresh: {}
indices.refresh:
expand_wildcards: "open,hidden"

- do:
count:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@
- do:
warnings:
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"
indices.refresh: {}
indices.refresh:
expand_wildcards: "open,hidden"
- do:
warnings:
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"
Expand Down Expand Up @@ -270,7 +271,8 @@
- do:
warnings:
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"
indices.refresh: {}
indices.refresh:
expand_wildcards: "open,hidden"
- do:
warnings:
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@
- do:
warnings:
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"
indices.refresh: {}
indices.refresh:
expand_wildcards: "open,hidden"
- do:
warnings:
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"
Expand Down Expand Up @@ -282,7 +283,8 @@
- do:
warnings:
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"
indices.refresh: {}
indices.refresh:
expand_wildcards: "open,hidden"
- do:
warnings:
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@
- do:
warnings:
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"
indices.refresh: {}
indices.refresh:
expand_wildcards: "open,hidden"
- do:
warnings:
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"
Expand Down Expand Up @@ -256,7 +257,8 @@
- do:
warnings:
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"
indices.refresh: {}
indices.refresh:
expand_wildcards: "open,hidden"
- do:
warnings:
- "this request accesses system indices: [.tasks], but in a future major version, direct access to system indices will be prevented by default"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.elasticsearch.client.Request;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
Expand Down Expand Up @@ -45,6 +46,7 @@
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.rest.RestRequest.Method.POST;
import static org.elasticsearch.test.rest.ESRestTestCase.entityAsMap;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -88,6 +90,20 @@ public void testSystemIndexAccessBlockedByDefault() throws Exception {
// And with a total wildcard
assertDeprecationWarningOnAccess(randomFrom("*", "_all"), SystemIndexTestPlugin.SYSTEM_INDEX_NAME);

// If we're not expanding wildcards, we don't get anything
{
Request searchRequest = new Request("GET", "/" + randomFrom("*", "_all") + randomFrom("/_count", "/_search"));
searchRequest.setJsonEntity("{\"query\": {\"match\": {\"some_field\": \"some_value\"}}}");
searchRequest.addParameter("allow_no_indices", "false");

try {
getRestClient().performRequest(searchRequest);
} catch (ResponseException e) {
assertThat(e.getResponse().getStatusLine().getStatusCode(), equalTo(404));
assertThat(e.getMessage(), containsString("no such index"));
}
}

// Try to index a doc directly
{
String expectedWarning = "this request accesses system indices: [" + SystemIndexTestPlugin.SYSTEM_INDEX_NAME + "], but in a " +
Expand All @@ -107,6 +123,7 @@ private void assertDeprecationWarningOnAccess(String queryPattern, String warnin
searchRequest.setJsonEntity("{\"query\": {\"match\": {\"some_field\": \"some_value\"}}}");
// Disallow no indices to cause an exception if this resolves to zero indices, so that we're sure it resolved the index
searchRequest.addParameter("allow_no_indices", "false");
searchRequest.addParameter("expand_wildcards", "open,hidden");
searchRequest.setOptions(expectWarnings(expectedWarning));

Response response = getRestClient().performRequest(searchRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ private Map<String, List<String>> checkForSystemIndexViolations(Index[] concrete
}

/**
* Checks that the request isn't trying to add the "hidden" setting to a system
* Checks that the request isn't trying to remove the "hidden" setting on a system
* index
*
* @param concreteIndices the indices being updated
* @param request the update request
* @return a list of system indexes that this request would set to hidden
* @return a list of system indexes that this request would make visible
*/
private List<String> checkForHidingSystemIndex(Index[] concreteIndices, UpdateSettingsRequest request) {
// Requests that a cluster generates itself are permitted to have a difference in settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public DataStream(String name, TimestampField timeStampField, List<Index> indice
this.indices = Collections.unmodifiableList(indices);
this.generation = generation;
this.metadata = metadata;
assert system == false || hidden; // system indices must be hidden
this.hidden = hidden;
this.replicated = replicated;
this.timeProvider = timeProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ public Alias(AliasMetadata aliasMetadata, List<IndexMetadata> indices) {
Strings.collectionToCommaDelimitedString(writeIndicesStrings) + "]");
}

// TODO[wrb]: how do we handle system alias visibility?
this.isHidden = aliasMetadata.isHidden() == null ? false : aliasMetadata.isHidden();
this.isSystem = indices.stream().allMatch(IndexMetadata::isSystem);
dataStreamAlias = false;
Expand Down Expand Up @@ -362,7 +363,7 @@ public DataStream getParentDataStream() {

@Override
public boolean isHidden() {
return dataStream.isHidden();
return isSystem() || dataStream.isHidden();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ private IndexMetadata(
this.rolloverInfos = rolloverInfos;
this.isSystem = isSystem;
assert isHidden == INDEX_HIDDEN_SETTING.get(settings);
assert isSystem == false || isHidden; // system indices must be hidden indices
this.isHidden = isHidden;
this.timestampRange = timestampRange;
this.priority = priority;
Expand Down Expand Up @@ -1356,6 +1357,10 @@ public IndexMetadata build() {
tierPreference = null;
}

if (isSystem) {
settings = Settings.builder().put(settings).put(INDEX_HIDDEN_SETTING.getKey(), true).build();
}

return new IndexMetadata(
new Index(index, uuid),
version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ static ClusterState createDataStream(MetadataCreateIndexService metadataCreateIn
DataStream.TimestampField timestampField = new DataStream.TimestampField(fieldName);
List<Index> dsBackingIndices = backingIndices.stream().map(IndexMetadata::getIndex).collect(Collectors.toList());
dsBackingIndices.add(writeIndex.getIndex());
boolean hidden = isSystem ? false : template.getDataStreamTemplate().isHidden();
boolean hidden = isSystem || template.getDataStreamTemplate().isHidden();
DataStream newDataStream = new DataStream(
dataStreamName,
timestampField,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING;
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS;
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_CREATION_DATE;
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_INDEX_HIDDEN;
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_INDEX_UUID;
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS;
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS;
Expand Down Expand Up @@ -356,6 +357,13 @@ public ClusterState applyCreateIndexRequest(ClusterState currentState, CreateInd
return applyCreateIndexRequestForSystemDataStream(currentState, request, silent, metadataTransformer);
}

if (systemIndices.isSystemIndex(request.index())
&& request.settings().hasValue(SETTING_INDEX_HIDDEN)
&& "false".equals(request.settings().get(SETTING_INDEX_HIDDEN))) {
throw new IllegalArgumentException("System indices must have " + IndexMetadata.SETTING_INDEX_HIDDEN +
" set to true.");
}

// Hidden indices apply templates slightly differently (ignoring wildcard '*'
// templates), so we need to check to see if the request is creating a hidden index
// prior to resolving which templates it matches
Expand Down Expand Up @@ -575,7 +583,7 @@ private ClusterState applyCreateIndexRequestForSystemDataStream(final ClusterSta
final List<Map<String, Object>> mappings =
collectSystemV2Mappings(template, componentTemplates, xContentRegistry, request.index());

final Settings aggregatedIndexSettings = aggregateIndexSettings(
final Settings aggregatedIndexSettings = Settings.builder().put(aggregateIndexSettings(
currentState,
request,
resolveSettings(template, componentTemplates),
Expand All @@ -585,7 +593,9 @@ private ClusterState applyCreateIndexRequestForSystemDataStream(final ClusterSta
shardLimitValidator,
indexSettingProviders,
this.enforceDefaultTierPreference
);
))
.put(SETTING_INDEX_HIDDEN, true)
.build();
final int routingNumShards = getIndexNumberOfRoutingShards(aggregatedIndexSettings, null);
final IndexMetadata tmpImd = buildAndValidateTemporaryIndexMetadata(aggregatedIndexSettings, request, routingNumShards);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.indices.ShardLimitValidator;
import org.elasticsearch.indices.SystemIndices;
import org.elasticsearch.threadpool.ThreadPool;

import java.io.IOException;
Expand All @@ -39,6 +40,7 @@
import java.util.Set;

import static org.elasticsearch.action.support.ContextPreservingActionListener.wrapPreservingContext;
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_INDEX_HIDDEN;
import static org.elasticsearch.index.IndexSettings.same;

/**
Expand All @@ -55,16 +57,18 @@ public class MetadataUpdateSettingsService {
private final IndicesService indicesService;
private final ShardLimitValidator shardLimitValidator;
private final ThreadPool threadPool;
private final SystemIndices systemIndices;

public MetadataUpdateSettingsService(ClusterService clusterService, AllocationService allocationService,
IndexScopedSettings indexScopedSettings, IndicesService indicesService,
ShardLimitValidator shardLimitValidator, ThreadPool threadPool) {
ShardLimitValidator shardLimitValidator, ThreadPool threadPool, SystemIndices systemIndices) {
this.clusterService = clusterService;
this.threadPool = threadPool;
this.allocationService = allocationService;
this.indexScopedSettings = indexScopedSettings;
this.indicesService = indicesService;
this.shardLimitValidator = shardLimitValidator;
this.systemIndices = systemIndices;
}

public void updateSettings(final UpdateSettingsClusterStateUpdateRequest request,
Expand Down Expand Up @@ -110,6 +114,7 @@ public ClusterState execute(ClusterState currentState) {
// on an open index
Set<Index> openIndices = new HashSet<>();
Set<Index> closeIndices = new HashSet<>();
Set<Index> systemIndicesInRequest = new HashSet<>();
final String[] actualIndices = new String[request.indices().length];
for (int i = 0; i < request.indices().length; i++) {
Index index = request.indices()[i];
Expand All @@ -120,6 +125,16 @@ public ClusterState execute(ClusterState currentState) {
} else {
closeIndices.add(index);
}
if (systemIndices.isSystemIndex(index)) {
systemIndicesInRequest.add(index);
}
}

if (systemIndicesInRequest.size() > 0
&& normalizedSettings.hasValue(SETTING_INDEX_HIDDEN)
&& "false".equals(normalizedSettings.get(SETTING_INDEX_HIDDEN))) {
throw new IllegalArgumentException("System indices must have " + IndexMetadata.SETTING_INDEX_HIDDEN +
" set to true.");
}

if (skippedSettings.isEmpty() == false && openIndices.isEmpty() == false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ public ClusterState execute(ClusterState currentState) throws Exception {
builder.system(cursor.value.isSystem() == false);
updated = true;
}
if (isSystem && cursor.value.getSettings().getAsBoolean(IndexMetadata.SETTING_INDEX_HIDDEN, false)) {
boolean isHidden = cursor.value.getSettings().getAsBoolean(IndexMetadata.SETTING_INDEX_HIDDEN, false);
if (isSystem && isHidden == false) {
builder.settings(Settings.builder()
.put(cursor.value.getSettings())
.put(IndexMetadata.SETTING_INDEX_HIDDEN, false));
.put(IndexMetadata.SETTING_INDEX_HIDDEN, true));
updated = true;
}
if (updated) {
Expand Down
Loading