From 01cfe20c015c52c3b4078ce4528c2ff0877c4581 Mon Sep 17 00:00:00 2001 From: Dan Hermann Date: Thu, 2 Jul 2020 23:53:31 -0500 Subject: [PATCH] Add include_data_streams flag for authorization (#58154) --- .../index/reindex/ReindexValidator.java | 4 +- .../20_unsupported_apis.yml | 11 +++ .../elasticsearch/action/IndicesRequest.java | 2 +- .../elasticsearch/action/OriginalIndices.java | 5 + .../cluster/health/ClusterHealthRequest.java | 5 + .../health/TransportClusterHealthAction.java | 4 +- .../TransportClusterSearchShardsAction.java | 4 +- .../create/CreateSnapshotRequest.java | 4 + .../cluster/state/ClusterStateRequest.java | 5 + .../state/TransportClusterStateAction.java | 4 +- .../mapping/get/GetFieldMappingsRequest.java | 5 + .../get/TransportGetFieldMappingsAction.java | 2 +- .../mapping/put/PutMappingRequest.java | 5 + .../put/TransportPutMappingAction.java | 4 +- .../admin/indices/open/OpenIndexRequest.java | 5 + .../open/TransportOpenIndexAction.java | 4 +- .../indices/resolve/ResolveIndexAction.java | 5 + .../indices/rollover/RolloverRequest.java | 5 + .../rollover/TransportRolloverAction.java | 2 +- .../settings/get/GetSettingsRequest.java | 6 +- .../get/TransportGetSettingsAction.java | 4 +- .../put/TransportUpdateSettingsAction.java | 4 +- .../settings/put/UpdateSettingsRequest.java | 5 + .../action/bulk/TransportBulkAction.java | 3 +- .../TransportFieldCapabilitiesAction.java | 2 +- .../action/index/IndexRequest.java | 4 + .../action/search/TransportSearchAction.java | 6 +- .../support/broadcast/BroadcastRequest.java | 5 + .../node/TransportBroadcastByNodeAction.java | 6 +- .../master/info/ClusterInfoRequest.java | 5 + .../info/TransportClusterInfoAction.java | 4 +- .../TransportBroadcastReplicationAction.java | 6 +- ...ransportInstanceSingleOperationAction.java | 2 +- .../metadata/IndexNameExpressionResolver.java | 45 ++++----- .../snapshots/SnapshotsService.java | 3 +- .../indices/get/GetIndexActionTests.java | 4 +- .../settings/get/GetSettingsActionTests.java | 4 +- .../IndexNameExpressionResolverTests.java | 47 +++++---- .../action/TransportForgetFollowerAction.java | 5 - .../core/ccr/action/ForgetFollowerAction.java | 5 + .../validation/SourceDestValidator.java | 2 +- .../deprecation/DeprecationInfoAction.java | 13 ++- .../action/GetRollupIndexCapsAction.java | 5 + .../DeprecationInfoActionResponseTests.java | 3 +- .../TransportDeprecationInfoAction.java | 3 +- .../TransportGetRollupIndexCapsAction.java | 2 +- .../authz/AuthorizedIndicesTests.java | 95 +++++++++++++++++++ 47 files changed, 279 insertions(+), 104 deletions(-) diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/ReindexValidator.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/ReindexValidator.java index f4e339d613718..64e7fd3194456 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/ReindexValidator.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/ReindexValidator.java @@ -120,9 +120,9 @@ static void validateAgainstAliases(SearchRequest source, IndexRequest destinatio * it. This is the same sort of dance that TransportIndexRequest * uses to decide to autocreate the index. */ - target = indexNameExpressionResolver.concreteWriteIndex(clusterState, destination, true).getName(); + target = indexNameExpressionResolver.concreteWriteIndex(clusterState, destination).getName(); } - for (String sourceIndex : indexNameExpressionResolver.concreteIndexNames(clusterState, source, true)) { + for (String sourceIndex : indexNameExpressionResolver.concreteIndexNames(clusterState, source)) { if (sourceIndex.equals(target)) { ActionRequestValidationException e = new ActionRequestValidationException(); e.addValidationError("reindex cannot write into an index its reading from [" + target + ']'); diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.data_stream/20_unsupported_apis.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.data_stream/20_unsupported_apis.yml index b97d36e70c54d..31aa47c7c5922 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.data_stream/20_unsupported_apis.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.data_stream/20_unsupported_apis.yml @@ -49,3 +49,14 @@ indices.delete_data_stream: name: logs-foobar - is_true: acknowledged + +--- +"APIs temporarily muted": + - skip: + version: "all" + reason: "restore to above test after data stream resolution PRs have been merged" + + - do: + catch: bad_request + indices.close: + index: logs-* diff --git a/server/src/main/java/org/elasticsearch/action/IndicesRequest.java b/server/src/main/java/org/elasticsearch/action/IndicesRequest.java index bd6421ad0fc0b..de11bb875e264 100644 --- a/server/src/main/java/org/elasticsearch/action/IndicesRequest.java +++ b/server/src/main/java/org/elasticsearch/action/IndicesRequest.java @@ -24,7 +24,7 @@ /** * Needs to be implemented by all {@link org.elasticsearch.action.ActionRequest} subclasses that relate to * one or more indices. Allows to retrieve which indices the action relates to. - * In case of internal requests originated during the distributed execution of an external request, + * In case of internal requests originated during the distributed execution of an external request, * they will still return the indices that the original request related to. */ public interface IndicesRequest { diff --git a/server/src/main/java/org/elasticsearch/action/OriginalIndices.java b/server/src/main/java/org/elasticsearch/action/OriginalIndices.java index 0642326d2b48e..5cb02f32fe78d 100644 --- a/server/src/main/java/org/elasticsearch/action/OriginalIndices.java +++ b/server/src/main/java/org/elasticsearch/action/OriginalIndices.java @@ -56,6 +56,11 @@ public IndicesOptions indicesOptions() { return indicesOptions; } + @Override + public boolean includeDataStreams() { + return true; + } + public static OriginalIndices readOriginalIndices(StreamInput in) throws IOException { return new OriginalIndices(in.readStringArray(), IndicesOptions.readIndicesOptions(in)); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthRequest.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthRequest.java index 2350548a230b5..7267719fcc522 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthRequest.java @@ -147,6 +147,11 @@ public ClusterHealthRequest indicesOptions(final IndicesOptions indicesOptions) return this; } + @Override + public boolean includeDataStreams() { + return true; + } + public TimeValue timeout() { return timeout; } diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java index 12bcde035882a..999a9b2122fdc 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java @@ -300,7 +300,7 @@ static int prepareResponse(final ClusterHealthRequest request, final ClusterHeal } if (CollectionUtils.isEmpty(request.indices()) == false) { try { - indexNameExpressionResolver.concreteIndexNames(clusterState, IndicesOptions.strictExpand(), true, request.indices()); + indexNameExpressionResolver.concreteIndexNames(clusterState, IndicesOptions.strictExpand(), request); waitForCounter++; } catch (IndexNotFoundException e) { response.setStatus(ClusterHealthStatus.RED); // no indices, make sure its RED @@ -367,7 +367,7 @@ private ClusterHealthResponse clusterHealth(ClusterHealthRequest request, Cluste String[] concreteIndices; try { - concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request, true); + concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request); } catch (IndexNotFoundException e) { // one of the specified indices is not there - treat it as RED. ClusterHealthResponse response = new ClusterHealthResponse(clusterState.getClusterName().value(), Strings.EMPTY_ARRAY, diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/shards/TransportClusterSearchShardsAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/shards/TransportClusterSearchShardsAction.java index 8a42c16eb9961..44cae03b28978 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/shards/TransportClusterSearchShardsAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/shards/TransportClusterSearchShardsAction.java @@ -68,7 +68,7 @@ protected String executor() { @Override protected ClusterBlockException checkBlock(ClusterSearchShardsRequest request, ClusterState state) { return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, - indexNameExpressionResolver.concreteIndexNames(state, request, true)); + indexNameExpressionResolver.concreteIndexNames(state, request)); } @Override @@ -80,7 +80,7 @@ protected ClusterSearchShardsResponse read(StreamInput in) throws IOException { protected void masterOperation(final ClusterSearchShardsRequest request, final ClusterState state, final ActionListener listener) { ClusterState clusterState = clusterService.state(); - String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request, true); + String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request); Map> routingMap = indexNameExpressionResolver.resolveSearchRouting(state, request.routing(), request.indices()); Map indicesAndFilters = new HashMap<>(); Set indicesAndAliases = indexNameExpressionResolver.resolveExpressions(clusterState, request.indices()); diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java index 392e3fc6c6db1..6a93d5e753221 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java @@ -275,6 +275,10 @@ public CreateSnapshotRequest indicesOptions(IndicesOptions indicesOptions) { return this; } + @Override + public boolean includeDataStreams() { + return true; + } /** * Returns true if indices with unavailable shards should be be partially snapshotted. diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequest.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequest.java index ddc2f33315938..d9396682b7134 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequest.java @@ -161,6 +161,11 @@ public final ClusterStateRequest indicesOptions(IndicesOptions indicesOptions) { return this; } + @Override + public boolean includeDataStreams() { + return true; + } + public ClusterStateRequest customs(boolean customs) { this.customs = customs; return this; diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java index 9a08fdbb298e3..11f5a39da8291 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java @@ -144,7 +144,7 @@ private ClusterStateResponse buildResponse(final ClusterStateRequest request, if (request.routingTable()) { if (request.indices().length > 0) { RoutingTable.Builder routingTableBuilder = RoutingTable.builder(); - String[] indices = indexNameExpressionResolver.concreteIndexNames(currentState, request, true); + String[] indices = indexNameExpressionResolver.concreteIndexNames(currentState, request); for (String filteredIndex : indices) { if (currentState.routingTable().getIndicesRouting().containsKey(filteredIndex)) { routingTableBuilder.add(currentState.routingTable().getIndicesRouting().get(filteredIndex)); @@ -166,7 +166,7 @@ private ClusterStateResponse buildResponse(final ClusterStateRequest request, if (request.metadata()) { if (request.indices().length > 0) { mdBuilder.version(currentState.metadata().version()); - String[] indices = indexNameExpressionResolver.concreteIndexNames(currentState, request, true); + String[] indices = indexNameExpressionResolver.concreteIndexNames(currentState, request); for (String filteredIndex : indices) { IndexMetadata indexMetadata = currentState.metadata().index(filteredIndex); if (indexMetadata != null) { diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsRequest.java index 7442fe2dd3597..63d7bab1637eb 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsRequest.java @@ -103,6 +103,11 @@ public IndicesOptions indicesOptions() { return indicesOptions; } + @Override + public boolean includeDataStreams() { + return true; + } + /** @param fields a list of fields to retrieve the mapping for */ public GetFieldMappingsRequest fields(String... fields) { this.fields = fields; diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetFieldMappingsAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetFieldMappingsAction.java index 57579cf8d9235..79df765480f7b 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetFieldMappingsAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetFieldMappingsAction.java @@ -56,7 +56,7 @@ public TransportGetFieldMappingsAction(TransportService transportService, Cluste @Override protected void doExecute(Task task, GetFieldMappingsRequest request, final ActionListener listener) { ClusterState clusterState = clusterService.state(); - String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request, true); + String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request); final AtomicInteger indexCounter = new AtomicInteger(); final AtomicInteger completionCounter = new AtomicInteger(concreteIndices.length); final AtomicReferenceArray indexResponses = new AtomicReferenceArray<>(concreteIndices.length); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java index a86dd57e7dabd..fc7677d0eef55 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java @@ -169,6 +169,11 @@ public PutMappingRequest indicesOptions(IndicesOptions indicesOptions) { return this; } + @Override + public boolean includeDataStreams() { + return true; + } + /** * The mapping type. */ diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/TransportPutMappingAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/TransportPutMappingAction.java index 9ea779924af1e..9858303d1799d 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/TransportPutMappingAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/TransportPutMappingAction.java @@ -86,7 +86,7 @@ protected AcknowledgedResponse read(StreamInput in) throws IOException { protected ClusterBlockException checkBlock(PutMappingRequest request, ClusterState state) { String[] indices; if (request.getConcreteIndex() == null) { - indices = indexNameExpressionResolver.concreteIndexNames(state, request, true); + indices = indexNameExpressionResolver.concreteIndexNames(state, request); } else { indices = new String[] {request.getConcreteIndex().getName()}; } @@ -98,7 +98,7 @@ protected void masterOperation(final PutMappingRequest request, final ClusterSta final ActionListener listener) { try { final Index[] concreteIndices = request.getConcreteIndex() == null ? - indexNameExpressionResolver.concreteIndices(state, request, true) + indexNameExpressionResolver.concreteIndices(state, request) : new Index[] {request.getConcreteIndex()}; final Optional maybeValidationException = requestValidators.validateRequest(request, state, concreteIndices); if (maybeValidationException.isPresent()) { diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexRequest.java index 958e5b78b7469..cdb675baa77fb 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexRequest.java @@ -113,6 +113,11 @@ public OpenIndexRequest indicesOptions(IndicesOptions indicesOptions) { return this; } + @Override + public boolean includeDataStreams() { + return true; + } + public ActiveShardCount waitForActiveShards() { return waitForActiveShards; } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/open/TransportOpenIndexAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/open/TransportOpenIndexAction.java index 1778ecf71904d..c30a56c7fe85c 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/open/TransportOpenIndexAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/open/TransportOpenIndexAction.java @@ -83,13 +83,13 @@ protected void doExecute(Task task, OpenIndexRequest request, ActionListener listener) { - final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request, true); + final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); if (concreteIndices == null || concreteIndices.length == 0) { listener.onResponse(new OpenIndexResponse(true, true)); return; diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/resolve/ResolveIndexAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/resolve/ResolveIndexAction.java index f88e188de3880..8aa56437bc7bb 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/resolve/ResolveIndexAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/resolve/ResolveIndexAction.java @@ -140,6 +140,11 @@ public IndicesRequest indices(String... indices) { this.names = indices; return this; } + + @Override + public boolean includeDataStreams() { + return true; + } } public static class ResolvedIndexAbstraction { diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java index 7b07f6563a6f7..bf07fa3f6ef60 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java @@ -151,6 +151,11 @@ public IndicesOptions indicesOptions() { return IndicesOptions.strictSingleIndexNoExpandForbidClosed(); } + @Override + public boolean includeDataStreams() { + return true; + } + /** * Sets the rollover target to rollover to another index */ diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java index 169c1f98ece29..8d8fa2dd79d26 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java @@ -91,7 +91,7 @@ protected ClusterBlockException checkBlock(RolloverRequest request, ClusterState request.indicesOptions().expandWildcardsOpen(), request.indicesOptions().expandWildcardsClosed()); return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, - indexNameExpressionResolver.concreteIndexNames(state, indicesOptions, true, request.indices())); + indexNameExpressionResolver.concreteIndexNames(state, indicesOptions, request)); } @Override diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsRequest.java index e3fd95779cb6e..8b255dffb44ca 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsRequest.java @@ -61,7 +61,6 @@ public GetSettingsRequest includeDefaults(boolean includeDefaults) { return this; } - public GetSettingsRequest() { } @@ -98,6 +97,11 @@ public IndicesOptions indicesOptions() { return indicesOptions; } + @Override + public boolean includeDataStreams() { + return true; + } + public String[] names() { return names; } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/settings/get/TransportGetSettingsAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/settings/get/TransportGetSettingsAction.java index 7e731b9d79713..f48ad2771e01c 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/settings/get/TransportGetSettingsAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/settings/get/TransportGetSettingsAction.java @@ -68,7 +68,7 @@ protected String executor() { @Override protected ClusterBlockException checkBlock(GetSettingsRequest request, ClusterState state) { return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, - indexNameExpressionResolver.concreteIndexNames(state, request, true)); + indexNameExpressionResolver.concreteIndexNames(state, request)); } @@ -83,7 +83,7 @@ private static boolean isFilteredRequest(GetSettingsRequest request) { @Override protected void masterOperation(GetSettingsRequest request, ClusterState state, ActionListener listener) { - Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request, true); + Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); ImmutableOpenMap.Builder indexToSettingsBuilder = ImmutableOpenMap.builder(); ImmutableOpenMap.Builder indexToDefaultSettingsBuilder = ImmutableOpenMap.builder(); for (Index concreteIndex : concreteIndices) { diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/settings/put/TransportUpdateSettingsAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/settings/put/TransportUpdateSettingsAction.java index e327f54df7960..b8981b4b73c59 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/settings/put/TransportUpdateSettingsAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/settings/put/TransportUpdateSettingsAction.java @@ -77,7 +77,7 @@ protected ClusterBlockException checkBlock(UpdateSettingsRequest request, Cluste return null; } return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, - indexNameExpressionResolver.concreteIndexNames(state, request, true)); + indexNameExpressionResolver.concreteIndexNames(state, request)); } @Override @@ -88,7 +88,7 @@ protected AcknowledgedResponse read(StreamInput in) throws IOException { @Override protected void masterOperation(final UpdateSettingsRequest request, final ClusterState state, final ActionListener listener) { - final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request, true); + final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); UpdateSettingsClusterStateUpdateRequest clusterStateUpdateRequest = new UpdateSettingsClusterStateUpdateRequest() .indices(concreteIndices) .settings(request.settings()) diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequest.java index 7a9c6db04bc0d..d5144bfbb7862 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequest.java @@ -119,6 +119,11 @@ public UpdateSettingsRequest indicesOptions(IndicesOptions indicesOptions) { return this; } + @Override + public boolean includeDataStreams() { + return true; + } + /** * Sets the settings to be updated */ diff --git a/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java b/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java index 425c8e36d8371..fe780c00301db 100644 --- a/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java +++ b/server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java @@ -726,7 +726,8 @@ Index resolveIfAbsent(DocWriteRequest request) { Index concreteIndex = indices.get(request.index()); if (concreteIndex == null) { boolean includeDataStreams = request.opType() == DocWriteRequest.OpType.CREATE; - concreteIndex = indexNameExpressionResolver.concreteWriteIndex(state, request, includeDataStreams); + concreteIndex = indexNameExpressionResolver.concreteWriteIndex(state, request.indicesOptions(), request.indices()[0], + false, includeDataStreams); indices.put(request.index(), concreteIndex); } return concreteIndex; diff --git a/server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesAction.java b/server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesAction.java index cc1cdc7ddaad9..3b45850287ca2 100644 --- a/server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesAction.java +++ b/server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesAction.java @@ -78,7 +78,7 @@ protected void doExecute(Task task, FieldCapabilitiesRequest request, final Acti // in the case we have one or more remote indices but no local we don't expand to all local indices and just do remote indices concreteIndices = Strings.EMPTY_ARRAY; } else { - concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, localIndices, true); + concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, localIndices); } final int totalNumRequest = concreteIndices.length + remoteClusterIndices.size(); final CountDown completionCounter = new CountDown(totalNumRequest); diff --git a/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java b/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java index 0b9ba3de6eae9..d63abe205a474 100644 --- a/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java +++ b/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java @@ -778,6 +778,10 @@ public String toString() { return "index {[" + index + "][" + type() + "][" + id + "], source[" + sSource + "]}"; } + @Override + public boolean includeDataStreams() { + return true; + } /** * Returns true if this request has been sent to a shard copy more than once. diff --git a/server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java b/server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java index 2f45e92c228d1..a0b07ce421278 100644 --- a/server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java +++ b/server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java @@ -451,14 +451,12 @@ static BiFunction processRemoteShards(Map aliasFilter = buildPerIndexAliasFilter(searchRequest, clusterState, indices, remoteAliasMap); Map> routingMap = indexNameExpressionResolver.resolveSearchRouting(clusterState, searchRequest.routing(), searchRequest.indices()); diff --git a/server/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastRequest.java b/server/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastRequest.java index e39301b4a6ff1..96f38c7b23451 100644 --- a/server/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastRequest.java +++ b/server/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastRequest.java @@ -76,6 +76,11 @@ public final Request indicesOptions(IndicesOptions indicesOptions) { return (Request) this; } + @Override + public boolean includeDataStreams() { + return true; + } + @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); diff --git a/server/src/main/java/org/elasticsearch/action/support/broadcast/node/TransportBroadcastByNodeAction.java b/server/src/main/java/org/elasticsearch/action/support/broadcast/node/TransportBroadcastByNodeAction.java index b29cb92252524..b5fc85d6234e5 100644 --- a/server/src/main/java/org/elasticsearch/action/support/broadcast/node/TransportBroadcastByNodeAction.java +++ b/server/src/main/java/org/elasticsearch/action/support/broadcast/node/TransportBroadcastByNodeAction.java @@ -225,10 +225,6 @@ protected void doExecute(Task task, Request request, ActionListener li new AsyncAction(task, request, listener).start(); } - protected boolean shouldIncludeDataStreams() { - return true; - } - protected class AsyncAction { private final Task task; private final Request request; @@ -253,7 +249,7 @@ protected AsyncAction(Task task, Request request, ActionListener liste throw globalBlockException; } - String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request, shouldIncludeDataStreams()); + String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request); ClusterBlockException requestBlockException = checkRequestBlock(clusterState, request, concreteIndices); if (requestBlockException != null) { throw requestBlockException; diff --git a/server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequest.java b/server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequest.java index d41d9dcec926f..56675857ea3b3 100644 --- a/server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequest.java +++ b/server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequest.java @@ -86,4 +86,9 @@ public String[] types() { public IndicesOptions indicesOptions() { return indicesOptions; } + + @Override + public boolean includeDataStreams() { + return true; + } } diff --git a/server/src/main/java/org/elasticsearch/action/support/master/info/TransportClusterInfoAction.java b/server/src/main/java/org/elasticsearch/action/support/master/info/TransportClusterInfoAction.java index e2a2462eca5d7..5e44ba9345302 100644 --- a/server/src/main/java/org/elasticsearch/action/support/master/info/TransportClusterInfoAction.java +++ b/server/src/main/java/org/elasticsearch/action/support/master/info/TransportClusterInfoAction.java @@ -49,12 +49,12 @@ protected String executor() { @Override protected ClusterBlockException checkBlock(Request request, ClusterState state) { return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, - indexNameExpressionResolver.concreteIndexNames(state, request, true)); + indexNameExpressionResolver.concreteIndexNames(state, request)); } @Override protected final void masterOperation(final Request request, final ClusterState state, final ActionListener listener) { - String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request, true); + String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request); doMasterOperation(request, concreteIndices, state, listener); } diff --git a/server/src/main/java/org/elasticsearch/action/support/replication/TransportBroadcastReplicationAction.java b/server/src/main/java/org/elasticsearch/action/support/replication/TransportBroadcastReplicationAction.java index d9234be59b2d5..b9d83d4299e73 100644 --- a/server/src/main/java/org/elasticsearch/action/support/replication/TransportBroadcastReplicationAction.java +++ b/server/src/main/java/org/elasticsearch/action/support/replication/TransportBroadcastReplicationAction.java @@ -123,7 +123,7 @@ protected void shardExecute(Task task, Request request, ShardId shardId, ActionL */ protected List shards(Request request, ClusterState clusterState) { List shardIds = new ArrayList<>(); - String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request, shouldIncludeDataStreams()); + String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request); for (String index : concreteIndices) { IndexMetadata indexMetadata = clusterState.metadata().getIndices().get(index); if (indexMetadata != null) { @@ -136,10 +136,6 @@ protected List shards(Request request, ClusterState clusterState) { return shardIds; } - protected boolean shouldIncludeDataStreams() { - return true; - } - protected abstract ShardResponse newShardResponse(); protected abstract ShardRequest newShardRequest(Request request, ShardId shardId); diff --git a/server/src/main/java/org/elasticsearch/action/support/single/instance/TransportInstanceSingleOperationAction.java b/server/src/main/java/org/elasticsearch/action/support/single/instance/TransportInstanceSingleOperationAction.java index 2d1f5236bd070..75b9402cd1342 100644 --- a/server/src/main/java/org/elasticsearch/action/support/single/instance/TransportInstanceSingleOperationAction.java +++ b/server/src/main/java/org/elasticsearch/action/support/single/instance/TransportInstanceSingleOperationAction.java @@ -143,7 +143,7 @@ protected void doStart(ClusterState clusterState) { throw blockException; } } - request.concreteIndex(indexNameExpressionResolver.concreteWriteIndex(clusterState, request, false).getName()); + request.concreteIndex(indexNameExpressionResolver.concreteWriteIndex(clusterState, request).getName()); resolveRequest(clusterState, request); blockException = checkRequestBlock(clusterState, request); if (blockException != null) { 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 deb885ceac232..10dd7a3ce9eab 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java @@ -72,28 +72,16 @@ public class IndexNameExpressionResolver { * are encapsulated in the specified request. */ public String[] concreteIndexNames(ClusterState state, IndicesRequest request) { - return concreteIndexNames(state, request, false); - } - - public String[] concreteIndexNames(ClusterState state, IndicesRequest request, boolean includeDataStreams) { - Context context = new Context(state, request.indicesOptions(), false, false, includeDataStreams); + Context context = new Context(state, request.indicesOptions(), false, false, request.includeDataStreams()); return concreteIndexNames(context, request.indices()); } - /** - * Same as {@link #concreteIndices(ClusterState, IndicesOptions, String...)}, but the index expressions and options - * are encapsulated in the specified request. - */ - public Index[] concreteIndices(ClusterState state, IndicesRequest request) { - return concreteIndices(state, request, false); - } - /** * Same as {@link #concreteIndices(ClusterState, IndicesOptions, String...)}, but the index expressions and options * are encapsulated in the specified request and resolves data streams. */ - public Index[] concreteIndices(ClusterState state, IndicesRequest request, boolean includeDataStreams) { - Context context = new Context(state, request.indicesOptions(), false, false, includeDataStreams); + public Index[] concreteIndices(ClusterState state, IndicesRequest request) { + Context context = new Context(state, request.indicesOptions(), false, false, request.includeDataStreams()); return concreteIndices(context, request.indices()); } @@ -115,12 +103,16 @@ public String[] concreteIndexNames(ClusterState state, IndicesOptions options, S return concreteIndexNames(context, indexExpressions); } - public String[] concreteIndexNames(ClusterState state, IndicesOptions options, boolean includeDataStreams, - String... indexExpressions) { + public String[] concreteIndexNames(ClusterState state, IndicesOptions options, boolean includeDataStreams, String... indexExpressions) { Context context = new Context(state, options, false, false, includeDataStreams); return concreteIndexNames(context, indexExpressions); } + public String[] concreteIndexNames(ClusterState state, IndicesOptions options, IndicesRequest request) { + Context context = new Context(state, options, false, false, request.includeDataStreams()); + return concreteIndexNames(context, request.indices()); + } + public List dataStreamNames(ClusterState state, IndicesOptions options, String... indexExpressions) { Context context = new Context(state, options, false, false, true); return Arrays.stream(indexExpressions) @@ -155,20 +147,18 @@ public Index[] concreteIndices(ClusterState state, IndicesOptions options, boole /** * Translates the provided index expression into actual concrete indices, properly deduplicated. * - * @param state the cluster state containing all the data to resolve to expressions to concrete indices - * @param options defines how the aliases or indices need to be resolved to concrete indices - * @param startTime The start of the request where concrete indices is being invoked for - * @param indexExpressions expressions that can be resolved to alias or index names. + * @param state the cluster state containing all the data to resolve to expressions to concrete indices + * @param startTime The start of the request where concrete indices is being invoked for + * @param request request containing expressions that can be resolved to alias, index, or data stream names. * @return the resolved concrete indices based on the cluster state, indices options and index expressions * provided indices options in the context don't allow such a case, or if the final result of the indices resolution * contains no indices and the indices options in the context don't allow such a case. * @throws IllegalArgumentException if one of the aliases resolve to multiple indices and the provided * indices options in the context don't allow such a case. */ - public Index[] concreteIndices(ClusterState state, IndicesOptions options, boolean includeDataStreams, long startTime, - String... indexExpressions) { - Context context = new Context(state, options, startTime, false, false, includeDataStreams); - return concreteIndices(context, indexExpressions); + public Index[] concreteIndices(ClusterState state, IndicesRequest request, long startTime) { + Context context = new Context(state, request.indicesOptions(), startTime, false, false, request.includeDataStreams()); + return concreteIndices(context, request.indices()); } String[] concreteIndexNames(Context context, String... indexExpressions) { @@ -344,15 +334,14 @@ public Index concreteSingleIndex(ClusterState state, IndicesRequest request) { * @param state the cluster state containing all the data to resolve to expression to a concrete index * @param request The request that defines how the an alias or an index need to be resolved to a concrete index * and the expression that can be resolved to an alias or an index name. - * @param includeDataStreams Whether data streams should be included in the evaluation. * @throws IllegalArgumentException if the index resolution does not lead to an index, or leads to more than one index * @return the write index obtained as a result of the index resolution */ - public Index concreteWriteIndex(ClusterState state, IndicesRequest request, boolean includeDataStreams) { + public Index concreteWriteIndex(ClusterState state, IndicesRequest request) { if (request.indices() == null || (request.indices() != null && request.indices().length != 1)) { throw new IllegalArgumentException("indices request must specify a single index expression"); } - return concreteWriteIndex(state, request.indicesOptions(), request.indices()[0], false, includeDataStreams); + return concreteWriteIndex(state, request.indicesOptions(), request.indices()[0], false, request.includeDataStreams()); } /** diff --git a/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java b/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java index 2e0d19329dabd..bd2ca1ef75b8f 100644 --- a/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java +++ b/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java @@ -207,8 +207,7 @@ public ClusterState execute(ClusterState currentState) { throw new ConcurrentSnapshotExecutionException(repositoryName, snapshotName, " a snapshot is already running"); } // Store newSnapshot here to be processed in clusterStateProcessed - indices = Arrays.asList(indexNameExpressionResolver.concreteIndexNames(currentState, - request.indicesOptions(), true, request.indices())); + List indices = Arrays.asList(indexNameExpressionResolver.concreteIndexNames(currentState, request)); final List dataStreams = indexNameExpressionResolver.dataStreamNames(currentState, request.indicesOptions(), request.indices()); diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexActionTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexActionTests.java index 1e7f3387464b2..75dbc0783d6b1 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexActionTests.java @@ -122,12 +122,12 @@ protected void doMasterOperation(GetIndexRequest request, String[] concreteIndic static class Resolver extends IndexNameExpressionResolver { @Override - public String[] concreteIndexNames(ClusterState state, IndicesRequest request, boolean includeDataStreams) { + public String[] concreteIndexNames(ClusterState state, IndicesRequest request) { return request.indices(); } @Override - public Index[] concreteIndices(ClusterState state, IndicesRequest request, boolean includeDataStreams) { + public Index[] concreteIndices(ClusterState state, IndicesRequest request) { Index[] out = new Index[request.indices().length]; for (int x = 0; x < out.length; x++) { out[x] = new Index(request.indices()[x], "_na_"); diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsActionTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsActionTests.java index e28dcf30b63fd..9ec3daba19bc4 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsActionTests.java @@ -130,12 +130,12 @@ public void testIncludeDefaultsWithFiltering() { static class Resolver extends IndexNameExpressionResolver { @Override - public String[] concreteIndexNames(ClusterState state, IndicesRequest request, boolean includeDataStreams) { + public String[] concreteIndexNames(ClusterState state, IndicesRequest request) { return request.indices(); } @Override - public Index[] concreteIndices(ClusterState state, IndicesRequest request, boolean includeDataStreams) { + public Index[] concreteIndices(ClusterState state, IndicesRequest request) { Index[] out = new Index[request.indices().length]; for (int x = 0; x < out.length; x++) { out[x] = new Index(request.indices()[x], "_na_"); 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 cf9e408a195c5..e98a1528ecf12 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverTests.java @@ -1432,14 +1432,19 @@ public String[] indices() { public IndicesOptions indicesOptions() { return IndicesOptions.strictSingleIndexNoExpandForbidClosed(); } + + @Override + public boolean includeDataStreams() { + return false; + } }; - Index writeIndex = indexNameExpressionResolver.concreteWriteIndex(state, request, false); + Index writeIndex = indexNameExpressionResolver.concreteWriteIndex(state, request); assertThat(writeIndex.getName(), equalTo("test-0")); state = ClusterState.builder(state).metadata(Metadata.builder(state.metadata()) .put(indexBuilder("test-1").putAlias(AliasMetadata.builder("test-alias") .writeIndex(testZeroWriteIndex ? randomFrom(false, null) : true)))).build(); - writeIndex = indexNameExpressionResolver.concreteWriteIndex(state, request, false); + writeIndex = indexNameExpressionResolver.concreteWriteIndex(state, request); assertThat(writeIndex.getName(), equalTo(testZeroWriteIndex ? "test-0" : "test-1")); } @@ -1459,12 +1464,17 @@ public String[] indices() { public IndicesOptions indicesOptions() { return IndicesOptions.strictSingleIndexNoExpandForbidClosed(); } + + @Override + public boolean includeDataStreams() { + return false; + } }; IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, - () -> indexNameExpressionResolver.concreteWriteIndex(state, requestGen.apply(null), false)); + () -> indexNameExpressionResolver.concreteWriteIndex(state, requestGen.apply(null))); assertThat(exception.getMessage(), equalTo("indices request must specify a single index expression")); exception = expectThrows(IllegalArgumentException.class, - () -> indexNameExpressionResolver.concreteWriteIndex(state, requestGen.apply(new String[] {"too", "many"}), false)); + () -> indexNameExpressionResolver.concreteWriteIndex(state, requestGen.apply(new String[] {"too", "many"}))); assertThat(exception.getMessage(), equalTo("indices request must specify a single index expression")); @@ -1493,10 +1503,15 @@ public String[] indices() { public IndicesOptions indicesOptions() { return IndicesOptions.strictExpandOpenAndForbidClosed(); } + + @Override + public boolean includeDataStreams() { + return false; + } }; IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, - () -> indexNameExpressionResolver.concreteWriteIndex(state, request, false)); + () -> indexNameExpressionResolver.concreteWriteIndex(state, request)); assertThat(exception.getMessage(), equalTo("The index expression [test-*] and options provided did not point to a single write-index")); } @@ -1513,7 +1528,7 @@ public void testConcreteWriteIndexWithNoWriteIndexWithSingleIndex() { DocWriteRequest request = randomFrom(new IndexRequest("test-alias"), new UpdateRequest("test-alias", "_type", "_id"), new DeleteRequest("test-alias")); IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, - () -> indexNameExpressionResolver.concreteWriteIndex(state, request, false)); + () -> indexNameExpressionResolver.concreteWriteIndex(state, request.indicesOptions(), request.indices()[0], false, false)); assertThat(exception.getMessage(), equalTo("no write index is defined for alias [test-alias]." + " The write index may be explicitly disabled using is_write_index=false or the alias points to multiple" + " indices without one being designated as a write index")); @@ -1533,7 +1548,7 @@ public void testConcreteWriteIndexWithNoWriteIndexWithMultipleIndices() { DocWriteRequest request = randomFrom(new IndexRequest("test-alias"), new UpdateRequest("test-alias", "_type", "_id"), new DeleteRequest("test-alias")); IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, - () -> indexNameExpressionResolver.concreteWriteIndex(state, request, false)); + () -> indexNameExpressionResolver.concreteWriteIndex(state, request.indicesOptions(), request.indices()[0], false, false)); assertThat(exception.getMessage(), equalTo("no write index is defined for alias [test-alias]." + " The write index may be explicitly disabled using is_write_index=false or the alias points to multiple" + " indices without one being designated as a write index")); @@ -1702,7 +1717,7 @@ public void testIndicesAliasesRequestTargetDataStreams() { { IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.add().index(dataStreamName); IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, - () -> indexNameExpressionResolver.concreteIndexNames(state, aliasActions, false)); + () -> indexNameExpressionResolver.concreteIndexNames(state, aliasActions)); assertEquals("The provided expression [" + dataStreamName + "] matches a data stream, specify the corresponding " + "concrete indices instead.", iae.getMessage()); } @@ -1710,18 +1725,18 @@ public void testIndicesAliasesRequestTargetDataStreams() { { IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.add().index("my-data-*").alias("my-data"); IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, - () -> indexNameExpressionResolver.concreteIndexNames(state, aliasActions, false)); + () -> indexNameExpressionResolver.concreteIndexNames(state, aliasActions)); assertEquals("The provided expression [my-data-*] matches a data stream, specify the corresponding concrete indices instead.", iae.getMessage()); } - { - IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.add().index(dataStreamName) - .alias("my-data"); - String[] indices = indexNameExpressionResolver.concreteIndexNames(state, aliasActions, true); - assertEquals(1, indices.length); - assertEquals(backingIndex.getIndex().getName(), indices[0]); - } + //{ + // IndicesAliasesRequest.AliasActions aliasActions = IndicesAliasesRequest.AliasActions.add().index(dataStreamName) + // .alias("my-data"); + // String[] indices = indexNameExpressionResolver.concreteIndexNames(state, aliasActions); + // assertEquals(1, indices.length); + // assertEquals(backingIndex.getIndex().getName(), indices[0]); + //} } public void testInvalidIndex() { diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportForgetFollowerAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportForgetFollowerAction.java index 81c9d18f79b07..5a150a3029991 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportForgetFollowerAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportForgetFollowerAction.java @@ -147,9 +147,4 @@ protected ClusterBlockException checkRequestBlock( final String[] concreteIndices) { return null; } - - @Override - protected boolean shouldIncludeDataStreams() { - return false; - } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/ForgetFollowerAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/ForgetFollowerAction.java index 1d4792aa44778..19f1173d984fb 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/ForgetFollowerAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/ForgetFollowerAction.java @@ -157,6 +157,11 @@ public ActionRequestValidationException validate() { return null; } + @Override + public boolean includeDataStreams() { + return false; + } + } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/common/validation/SourceDestValidator.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/common/validation/SourceDestValidator.java index 4aaef4a25bd3b..fd17efab10864 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/common/validation/SourceDestValidator.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/common/validation/SourceDestValidator.java @@ -215,7 +215,7 @@ private void resolveLocalAndRemoteSource() { state, DEFAULT_INDICES_OPTIONS_FOR_VALIDATION, true, - resolvedSource.toArray(new String[0]) + resolvedSource.toArray(Strings.EMPTY_ARRAY) ) ) ); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/deprecation/DeprecationInfoAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/deprecation/DeprecationInfoAction.java index f8ad32c9e046f..25a53c6985f8b 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/deprecation/DeprecationInfoAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/deprecation/DeprecationInfoAction.java @@ -168,8 +168,7 @@ public int hashCode() { * * @param state The cluster state * @param indexNameExpressionResolver Used to resolve indices into their concrete names - * @param indices The list of index expressions to evaluate using `indexNameExpressionResolver` - * @param indicesOptions The options to use when resolving and filtering which indices to check + * @param request The originating request containing the index expressions to evaluate * @param datafeeds The ml datafeed configurations * @param nodeDeprecationResponse The response containing the deprecation issues found on each node * @param indexSettingsChecks The list of index-level checks that will be run across all specified @@ -181,8 +180,7 @@ public int hashCode() { public static DeprecationInfoAction.Response from(ClusterState state, NamedXContentRegistry xContentRegistry, IndexNameExpressionResolver indexNameExpressionResolver, - String[] indices, IndicesOptions indicesOptions, - List datafeeds, + Request request, List datafeeds, NodesDeprecationCheckResponse nodeDeprecationResponse, List> indexSettingsChecks, List> clusterSettingsChecks, @@ -196,7 +194,7 @@ public static DeprecationInfoAction.Response from(ClusterState state, mlSettingsIssues.addAll(filterChecks(mlSettingsCheck, (c) -> c.apply(config, xContentRegistry))); } - String[] concreteIndexNames = indexNameExpressionResolver.concreteIndexNames(state, indicesOptions, true, indices); + String[] concreteIndexNames = indexNameExpressionResolver.concreteIndexNames(state, request); Map> indexSettingsIssues = new HashMap<>(); for (String concreteIndex : concreteIndexNames) { @@ -252,6 +250,11 @@ public IndicesOptions indicesOptions() { return INDICES_OPTIONS; } + @Override + public boolean includeDataStreams() { + return true; + } + @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupIndexCapsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupIndexCapsAction.java index d9f069dc300fb..fe95342da0561 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupIndexCapsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupIndexCapsAction.java @@ -83,6 +83,11 @@ public IndicesRequest indices(String... indices) { return this; } + @Override + public boolean includeDataStreams() { + return true; + } + @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/deprecation/DeprecationInfoActionResponseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/deprecation/DeprecationInfoActionResponseTests.java index 079d7e97caa8a..13935e717f4ae 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/deprecation/DeprecationInfoActionResponseTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/deprecation/DeprecationInfoActionResponseTests.java @@ -108,8 +108,9 @@ public void testFrom() throws IOException { : emptyList(), emptyList()); + DeprecationInfoAction.Request request = new DeprecationInfoAction.Request(Strings.EMPTY_ARRAY); DeprecationInfoAction.Response response = DeprecationInfoAction.Response.from(state, NamedXContentRegistry.EMPTY, - resolver, Strings.EMPTY_ARRAY, indicesOptions, datafeeds, + resolver, request, datafeeds, nodeDeprecationIssues, indexSettingsChecks, clusterSettingsChecks, mlSettingsChecks); if (clusterIssueFound) { diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoAction.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoAction.java index 7e75d6db53da1..abe9f7bb8a31a 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoAction.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoAction.java @@ -105,8 +105,7 @@ protected final void masterOperation(final DeprecationInfoAction.Request request datafeeds -> { listener.onResponse( DeprecationInfoAction.Response.from(state, xContentRegistry, indexNameExpressionResolver, - request.indices(), request.indicesOptions(), datafeeds, - response, INDEX_SETTINGS_CHECKS, CLUSTER_SETTINGS_CHECKS, + request, datafeeds, response, INDEX_SETTINGS_CHECKS, CLUSTER_SETTINGS_CHECKS, ML_SETTINGS_CHECKS)); }, listener::onFailure diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupIndexCapsAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupIndexCapsAction.java index e352c9f26f18a..119744ae192c5 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupIndexCapsAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupIndexCapsAction.java @@ -46,7 +46,7 @@ protected void doExecute(Task task, GetRollupIndexCapsAction.Request request, ActionListener listener) { String[] indices = resolver.concreteIndexNames(clusterService.state(), - request.indicesOptions(), true, request.indices()); + request.indicesOptions(), request); Map allCaps = getCapsByRollupIndex(Arrays.asList(indices), clusterService.state().getMetadata().indices()); listener.onResponse(new GetRollupIndexCapsAction.Response(allCaps)); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizedIndicesTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizedIndicesTests.java index b44c7f8e1778c..7a4cc55783de2 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizedIndicesTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizedIndicesTests.java @@ -6,13 +6,16 @@ package org.elasticsearch.xpack.security.authz; import org.elasticsearch.Version; +import org.elasticsearch.action.admin.indices.resolve.ResolveIndexAction; import org.elasticsearch.action.search.SearchAction; import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.cluster.metadata.AliasMetadata; +import org.elasticsearch.cluster.metadata.DataStream; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.set.Sets; +import org.elasticsearch.index.Index; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.transport.TransportRequest; import org.elasticsearch.xpack.core.security.authz.AuthorizationEngine; @@ -30,6 +33,7 @@ import java.util.List; import java.util.Set; +import static org.elasticsearch.cluster.DataStreamTestHelper.createTimestampField; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.not; @@ -156,6 +160,97 @@ public void testSecurityIndicesAreNotRemovedFromUnrestrictedRole() { "an-index", "another-index", RestrictedIndicesNames.SECURITY_MAIN_ALIAS, internalSecurityIndex)); } + public void testDataStreamsAreNotIncludedInAuthorizedIndices() { + RoleDescriptor aStarRole = new RoleDescriptor("a_star", null, + new IndicesPrivileges[] { IndicesPrivileges.builder().indices("a*").privileges("all").build() }, null); + RoleDescriptor bRole = new RoleDescriptor("b", null, + new IndicesPrivileges[] { IndicesPrivileges.builder().indices("b").privileges("READ").build() }, null); + Settings indexSettings = Settings.builder().put("index.version.created", Version.CURRENT).build(); + final String internalSecurityIndex = randomFrom(RestrictedIndicesNames.INTERNAL_SECURITY_MAIN_INDEX_6, + RestrictedIndicesNames.INTERNAL_SECURITY_MAIN_INDEX_7); + String backingIndex = DataStream.getDefaultBackingIndexName("adatastream1", 1); + Metadata metadata = Metadata.builder() + .put(new IndexMetadata.Builder("a1").settings(indexSettings).numberOfShards(1).numberOfReplicas(0).build(), true) + .put(new IndexMetadata.Builder("a2").settings(indexSettings).numberOfShards(1).numberOfReplicas(0).build(), true) + .put(new IndexMetadata.Builder("aaaaaa").settings(indexSettings).numberOfShards(1).numberOfReplicas(0).build(), true) + .put(new IndexMetadata.Builder("bbbbb").settings(indexSettings).numberOfShards(1).numberOfReplicas(0).build(), true) + .put(new IndexMetadata.Builder("b") + .settings(indexSettings) + .numberOfShards(1) + .numberOfReplicas(0) + .putAlias(new AliasMetadata.Builder("ab").build()) + .putAlias(new AliasMetadata.Builder("ba").build()) + .build(), true) + .put(new IndexMetadata.Builder(internalSecurityIndex) + .settings(indexSettings) + .numberOfShards(1) + .numberOfReplicas(0) + .putAlias(new AliasMetadata.Builder(RestrictedIndicesNames.SECURITY_MAIN_ALIAS).build()) + .build(), true) + .put(new IndexMetadata.Builder(backingIndex).settings(indexSettings).numberOfShards(1).numberOfReplicas(0).build(), true) + .put(new DataStream("adatastream1", createTimestampField("@timestamp"), + List.of(new Index(DataStream.getDefaultBackingIndexName("adatastream1", 1), "_na_")))) + .build(); + final PlainActionFuture future = new PlainActionFuture<>(); + final Set descriptors = Sets.newHashSet(aStarRole, bRole); + CompositeRolesStore.buildRoleFromDescriptors(descriptors, new FieldPermissionsCache(Settings.EMPTY), null, future); + Role roles = future.actionGet(); + List list = + RBACEngine.resolveAuthorizedIndicesFromRole(roles, getRequestInfo(SearchAction.NAME), metadata.getIndicesLookup()); + assertThat(list, containsInAnyOrder("a1", "a2", "aaaaaa", "b", "ab")); + assertFalse(list.contains("bbbbb")); + assertFalse(list.contains("ba")); + assertFalse(list.contains("adatastream1")); + assertThat(list, not(contains(internalSecurityIndex))); + assertThat(list, not(contains(RestrictedIndicesNames.SECURITY_MAIN_ALIAS))); + } + + public void testDataStreamsAreIncludedInAuthorizedIndices() { + RoleDescriptor aStarRole = new RoleDescriptor("a_star", null, + new IndicesPrivileges[] { IndicesPrivileges.builder().indices("a*").privileges("all").build() }, null); + RoleDescriptor bRole = new RoleDescriptor("b", null, + new IndicesPrivileges[] { IndicesPrivileges.builder().indices("b").privileges("READ").build() }, null); + Settings indexSettings = Settings.builder().put("index.version.created", Version.CURRENT).build(); + final String internalSecurityIndex = randomFrom(RestrictedIndicesNames.INTERNAL_SECURITY_MAIN_INDEX_6, + RestrictedIndicesNames.INTERNAL_SECURITY_MAIN_INDEX_7); + String backingIndex = DataStream.getDefaultBackingIndexName("adatastream1", 1); + Metadata metadata = Metadata.builder() + .put(new IndexMetadata.Builder("a1").settings(indexSettings).numberOfShards(1).numberOfReplicas(0).build(), true) + .put(new IndexMetadata.Builder("a2").settings(indexSettings).numberOfShards(1).numberOfReplicas(0).build(), true) + .put(new IndexMetadata.Builder("aaaaaa").settings(indexSettings).numberOfShards(1).numberOfReplicas(0).build(), true) + .put(new IndexMetadata.Builder("bbbbb").settings(indexSettings).numberOfShards(1).numberOfReplicas(0).build(), true) + .put(new IndexMetadata.Builder("b") + .settings(indexSettings) + .numberOfShards(1) + .numberOfReplicas(0) + .putAlias(new AliasMetadata.Builder("ab").build()) + .putAlias(new AliasMetadata.Builder("ba").build()) + .build(), true) + .put(new IndexMetadata.Builder(internalSecurityIndex) + .settings(indexSettings) + .numberOfShards(1) + .numberOfReplicas(0) + .putAlias(new AliasMetadata.Builder(RestrictedIndicesNames.SECURITY_MAIN_ALIAS).build()) + .build(), true) + .put(new IndexMetadata.Builder(backingIndex).settings(indexSettings).numberOfShards(1).numberOfReplicas(0).build(), true) + .put(new DataStream("adatastream1", createTimestampField("@timestamp"), + List.of(new Index(DataStream.getDefaultBackingIndexName("adatastream1", 1), "_na_")))) + .build(); + final PlainActionFuture future = new PlainActionFuture<>(); + final Set descriptors = Sets.newHashSet(aStarRole, bRole); + CompositeRolesStore.buildRoleFromDescriptors(descriptors, new FieldPermissionsCache(Settings.EMPTY), null, future); + Role roles = future.actionGet(); + TransportRequest request = new ResolveIndexAction.Request(new String[]{"a*"}); + AuthorizationEngine.RequestInfo requestInfo = new AuthorizationEngine.RequestInfo(null, request, SearchAction.NAME); + List list = + RBACEngine.resolveAuthorizedIndicesFromRole(roles, requestInfo, metadata.getIndicesLookup()); + assertThat(list, containsInAnyOrder("a1", "a2", "aaaaaa", "b", "ab", "adatastream1", backingIndex)); + assertFalse(list.contains("bbbbb")); + assertFalse(list.contains("ba")); + assertThat(list, not(contains(internalSecurityIndex))); + assertThat(list, not(contains(RestrictedIndicesNames.SECURITY_MAIN_ALIAS))); + } + public static AuthorizationEngine.RequestInfo getRequestInfo(String action) { return getRequestInfo(TransportRequest.Empty.INSTANCE, action); }