Skip to content

Commit aaea6cf

Browse files
use rewriteIndexExpression again
1 parent 8bbfd8f commit aaea6cf

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolver.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,13 @@ ResolvedIndices resolveIndicesAndAliases(
342342
// Always parse selectors, but do so lazily so that we don't spend a lot of time splitting strings each resolution
343343
isAllIndices = IndexNameExpressionResolver.isAllIndices(indicesList(indicesRequest.indices()), (expr) -> {
344344
var unprefixed = crossProjectModeDecider.resolvesCrossProject(replaceable)
345-
? RemoteClusterAware.splitIndexName(expr)[1]
345+
? CrossProjectIndexExpressionsRewriter.rewriteIndexExpression(
346+
expr,
347+
authorizedProjects.originProjectAlias(),
348+
authorizedProjects.allProjectAliases()
349+
).localExpression()
346350
: expr;
347-
return IndexNameExpressionResolver.splitSelectorExpression(unprefixed).v1();
351+
return unprefixed != null ? IndexNameExpressionResolver.splitSelectorExpression(unprefixed).v1() : null;
348352
});
349353
if (isAllIndices) {
350354
// This parses the single all-indices expression for a second time in this conditional branch, but this is better than

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolverTests.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113

114114
import static org.elasticsearch.action.ResolvedIndexExpression.LocalIndexResolutionResult.CONCRETE_RESOURCE_NOT_VISIBLE;
115115
import static org.elasticsearch.action.ResolvedIndexExpression.LocalIndexResolutionResult.CONCRETE_RESOURCE_UNAUTHORIZED;
116+
import static org.elasticsearch.action.ResolvedIndexExpression.LocalIndexResolutionResult.NONE;
116117
import static org.elasticsearch.action.ResolvedIndexExpression.LocalIndexResolutionResult.SUCCESS;
117118
import static org.elasticsearch.cluster.metadata.DataStreamTestHelper.newInstance;
118119
import static org.elasticsearch.test.ActionListenerUtils.anyActionListener;
@@ -2985,7 +2986,7 @@ public void testResolveAllWithWildcardRemotePrefix() {
29852986
);
29862987
}
29872988

2988-
public void testResolveAllWithRemotePrefix() {
2989+
public void testResolveAllWithLocalPrefix() {
29892990
when(crossProjectModeDecider.resolvesCrossProject(any(IndicesRequest.Replaceable.class))).thenReturn(true);
29902991

29912992
var expression = randomBoolean() ? "local:_all" : "_origin:_all";
@@ -3012,6 +3013,33 @@ public void testResolveAllWithRemotePrefix() {
30123013
assertThat(resolved.expressions(), contains(resolvedIndexExpression(expression, Set.of(expectedIndices), SUCCESS, Set.of())));
30133014
}
30143015

3016+
public void testResolveAllWithRemotePrefix() {
3017+
when(crossProjectModeDecider.resolvesCrossProject(any(IndicesRequest.Replaceable.class))).thenReturn(true);
3018+
3019+
var request = new SearchRequest().indices("P*:_all");
3020+
request.indicesOptions(IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), true, true));
3021+
var resolvedIndices = defaultIndicesResolver.resolveIndicesAndAliases(
3022+
"indices:/" + randomAlphaOfLength(8),
3023+
request,
3024+
projectMetadata,
3025+
buildAuthorizedIndices(user, TransportSearchAction.TYPE.name()),
3026+
new TargetProjects(
3027+
createRandomProjectWithAlias("local"),
3028+
List.of(createRandomProjectWithAlias("P1"), createRandomProjectWithAlias("P2"), createRandomProjectWithAlias("P3"))
3029+
)
3030+
);
3031+
3032+
assertThat(resolvedIndices.getLocal(), is(empty()));
3033+
assertThat(resolvedIndices.getRemote(), contains("P1:_all", "P2:_all", "P3:_all"));
3034+
3035+
final var resolved = request.getResolvedIndexExpressions();
3036+
assertThat(resolved, is(notNullValue()));
3037+
assertThat(
3038+
resolved.expressions(),
3039+
contains(resolvedIndexExpression("P*:_all", Set.of(), NONE, Set.of("P1:_all", "P2:_all", "P3:_all")))
3040+
);
3041+
}
3042+
30153043
public void testResolveIndexWithRemotePrefix() {
30163044
when(crossProjectModeDecider.resolvesCrossProject(any(IndicesRequest.Replaceable.class))).thenReturn(true);
30173045

0 commit comments

Comments
 (0)