Fix IllegalArgumentException when resolved indices are empty#5797
Fix IllegalArgumentException when resolved indices are empty#5797cwperks merged 2 commits intoopensearch-project:mainfrom
Conversation
|
That looks quite good to me, thank you! Just a few things:
|
4692a36 to
b9d0dec
Compare
96c8e4e to
91a7097
Compare
|
@nibix during the implementation of the integration test, I encountered another edge case: if there are no indices, and users do not have any indices priveleges for the action at all, such requests should be also forbidden. To check this edge case I've added - a new method You've also mentioned IndexAuthorizationReadOnlyIntTests.java to add a new ingegration test there. I've added new
wdyt? |
|
Thanks for the update! On Friday, I will be quite busy with other stuff, so I will only have time to take a closer look on Monday.
We need to take a closer look at this:
Of course, this is a discussable topic - at the moment, we are working on some fundamental behavior changes (see #3905, #5367 and #5399 ; I also need to write an updated RFC soon). Feel invited to discuss there. |
|
Sorry for the late reply, was just too busy :-( That looks generally very good to me! Yet, I think we need to briefly reflect on this:
If I see this correctly, this would have the following effect:
This is a kind of inconsistent behavior which we should avoid IMHO (even though it might be a case that seldomly happens in the real word). For now, I would propose not to do the At the moment, we are busy on revising the index authorization behavior, see #5814. We could use that chance and implement the behavior change in that go. Feel invited to have a look there and comment :) @cwperks wdyt? |
91a7097 to
1c46d7d
Compare
|
@nibix thanks for the comment! I agree with your suggestion. Let's keep the fix short and simple to avoid any problems with backwards compatibility, bearing in mind that the refactoring is still ongoing in other PRs. I've updated the PR to reflect our discussion and amended the description. Is there anything else I need to do to get this into the next security plugin release (2.19.4.0)? |
|
Thanks for the update! It seems that the new int tests are failing at the moment: Maybe we also need to adapt these to expect a 200 response in case no indices are requested? |
Signed-off-by: Maxim Muzafarov <mmuzaf@apache.org>
fc936e2 to
5f3992e
Compare
|
@nibix Sorry, my mistake. Not all the changes made locally have been pushed to the origin. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5797 +/- ##
==========================================
+ Coverage 73.68% 73.71% +0.02%
==========================================
Files 438 438
Lines 26644 26649 +5
Branches 3938 3939 +1
==========================================
+ Hits 19633 19643 +10
+ Misses 5138 5134 -4
+ Partials 1873 1872 -1
🚀 New features to boost your workflow:
|
| @Test | ||
| public void hasIndexPrivilegeEmptyResolvedIndices() throws Exception { | ||
| SecurityDynamicConfiguration<RoleV7> roles = SecurityDynamicConfiguration.fromYaml( | ||
| "test_role:\n" |
There was a problem hiding this comment.
nit: I think we can use java text blocks to define multi-line strings.
|
@Mmuzaf Apologies for not getting back sooner. The changes look reasonable, but for my understanding what does |
|
When all indices are closed is it possible to call I'm also wondering if it makes sense to respond with a warning telling the caller that it could not resolve to indices. |
|
@Mmuzaf @nibix @willyborankin do you think we should respond with a warning when we cannot resolve to indices? I believe https://github.com/opensearch-project/OpenSearch/blob/799fb9bf46b1eb823f26f72e368f70a5675bf88f/server/src/main/java/org/opensearch/cluster/metadata/MetadataIndexTemplateService.java#L651-L662 shows an example of how it can be done. |
You mean the case when an index expression yields an empty set of indices? For me that sounds like a rather normal case, there are many reasons why that might happen. IMHO, that does not need to be warned about. But, generally, that should a core thing, wdyt? |
I see, yea that makes sense esp in cases where a search is performed on an index pattern that does not resolve to any concrete indices. Edit: Searching on an index pattern which matches 0 indices works gracefully: |
Signed-off-by: Craig Perkins <cwperx@amazon.com>
|
@nibix can you re-approve? I resolved the conflict in the CHANGELOG. |
Description
This PR fixes an
IllegalArgumentExceptionthat occured when resolved indices are empty in thePrivilegesEvaluator. This issue occurs when all indices are closed (e.g., during cluster maintenance) and operations like_cat/recoveryare executed.Category
Bug fix
Why these changes are required?
When all indices in a cluster are closed, certain operations like
_cat/recoverycan still be valid and should be authorized. However, whengetAllIndicesResolved()returns an empty set, the code was attempting to create aCheckTablewith an empty collection, which throws anIllegalArgumentException.This prevents valid operations from being authorized when indices are closed.
What is the old behavior before changes and new behavior after changes?
Old behavior:
getAllIndicesResolved()returned an empty set, the code would attempt to create aCheckTablewith an empty collection and throw an exception.New behavior:
getAllIndicesResolved()returns an empty set allow operations to proceed_cat/recoverynow succeed when users have the appropriate permissions, even when all indices are closedIssues Resolved
Resolves #5794
Is this a backport?
No
Do these changes introduce new permission(s) to be displayed in the static dropdown on the front-end?
No
Testing
hasIndexPrivilegeEmptyResolvedIndices()IndexAuthorizationWithClosedIndicesIntTestsManual Testing
_cat/recoveryand similar operations work correctly when all indices are closedCheck List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.