-
Notifications
You must be signed in to change notification settings - Fork 25.6k
resolve indices for prefixed _all expressions #137330
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
base: main
Are you sure you want to change the base?
resolve indices for prefixed _all expressions #137330
Conversation
| ); | ||
| } | ||
|
|
||
| public void testResolveIndexWithRemotePrefix() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that I could just set all cross project requests to go down the "all indices" path and all the tests would pass, even though this is obviously wrong; I've added this test which fails under that scenario
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all the tests would pass
Do you mean all tests in this test class? I am surprised unless all existing tests are effectively resolving to all accessible indices. Is that the case? Also, I assume tests in other places, e.g. the serverless REST test, should fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's because the majority of the other tests in this file have CPS mode disabled; I'll see if the REST test guards against this, but I don't want it to be the only test that would fail - it makes the feedback loop too long
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed that the REST test fails when this functionality is implemented incorrectly
|
Pinging @elastic/es-security (Team:Security) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This look mostly good. I have only minor comments.
Can you also have a serverless side PR to update the test scenarios?
| isAllIndices = crossProjectModeDecider.resolvesCrossProject(replaceable) | ||
| ? IndexNameExpressionResolver.isAllIndices( | ||
| indicesList(indicesRequest.indices()), | ||
| (expr) -> CrossProjectIndexExpressionsRewriter.rewriteIndexExpression( | ||
| expr, | ||
| authorizedProjects.originProjectAlias(), | ||
| authorizedProjects.allProjectAliases() | ||
| ).localExpression() | ||
| ) | ||
| : IndexNameExpressionResolver.isAllIndices( | ||
| indicesList(indicesRequest.indices()), | ||
| (expr) -> IndexNameExpressionResolver.splitSelectorExpression(expr).v1() | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This matches what I was thinking, i.e. let cases like *:_all go through the all indices handling. I suggest we use RemoteClusterAware#splitIndexName instead of rewriteIndexExpression. It is lighter and we don't care about resolving projects at this point. It also needs to handle syntax like selector. I'd prefer we don't error out at isAllIndices check. The unsupported syntax will still be caught later when we call rewriteIndexExpression. So overall I am suggeting something like
IndexNameExpressionResolver.isAllIndices(
indicesList(indicesRequest.indices()),
expr -> {
IndexNameExpressionResolver.splitSelectorExpression(RemoteClusterAware.splitIndexName(expr)[1]).v1()
}
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears this isn't enough, as this means any expression targeting _all will resolve all indices on the local project, even if that expression is e.g. some_remote_project:_all.
We need to check if the expression is _all, and that the prefix includes the local project. It looks to me like rewriteIndexExpression handles all the edge cases here, even if it does more than what's necessary here.
| ); | ||
| } | ||
|
|
||
| public void testResolveIndexWithRemotePrefix() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all the tests would pass
Do you mean all tests in this test class? I am surprised unless all existing tests are effectively resolving to all accessible indices. Is that the case? Also, I assume tests in other places, e.g. the serverless REST test, should fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Follow up to #135425
As identified, expressions such as
*:_allcurrently don't resolve correctly (it appears that it currently tries to authorize the user against the literal index "_all").This PR fixes the resolution of prefixed
_allexpressions.Relates: ES-13213