Skip hasExplicitIndexPrivilege check for plugin users accessing their own system indices#5858
Conversation
|
Thank you for this! We have already tests for enabled system index privileges in https://github.com/opensearch-project/security/blob/main/src/integrationTest/java/org/opensearch/security/privileges/int_tests/IndexAuthorizationReadOnlyIntTests.java ... do you think it would be possible to move the new tests there? We are currently working on a major change on privilege evaluation in #5827 , which also includes system indices. With the tests being in IndexAuthorizationReadOnlyIntTests, it would be easy for us to have test coverage also for these cases. |
...egrationTest/java/org/opensearch/security/systemindex/SystemIndexPermissionEnabledTests.java
Outdated
Show resolved
Hide resolved
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5858 +/- ##
==========================================
+ Coverage 73.68% 73.71% +0.03%
==========================================
Files 438 438
Lines 26649 26656 +7
Branches 3939 3943 +4
==========================================
+ Hits 19635 19650 +15
+ Misses 5141 5133 -8
Partials 1873 1873
🚀 New features to boost your workflow:
|
|
Thanks for the review, @nibix! I can either:
Which approach would you prefer? |
|
@llilyy thanks for the explanation!
If you wouldn't mind, this seems to be the optimal approach, wdyt? |
|
Thank you @llilyy. The functional changes in this PR LGTM, reviewing the tests added now. |
|
Thanks! I will add tests this week. |
db3bebd to
a0c9e3a
Compare
|
Apologies for replying to late, but:
To be honest, I do strongly believe that using super classes for test suites is a strong anti-pattern. Inheritance is meant for polymorphic usage of implementations, it is NOT meant for code-reuse. This creates IMHO really difficult to understand test classes because actual test suites like do actually not contain any tests. See also https://en.wikipedia.org/wiki/Composition_over_inheritance |
b8d7b72 to
40fd7c5
Compare
|
This test structure is not using inheritance for ad-hoc code reuse. It defines an explicit privileges test contract that is executed across multiple cluster configurations. The abstract base class expresses the complete set of privilege rules that must hold, while the concrete subclasses provide different environments in which the same contract is validated. These tests are actually executed polymorphically: the same test methods are run with different In privilege-focused tests, duplicating the same privilege rules and expectations across multiple test classes is particularly error-prone. When privilege semantics change, duplicated logic is easy to update inconsistently, which can lead to missed cases, diverging behavior, or even false positives. Centralizing the privilege rules in a single abstract test suite intentionally enforces a single source of truth for the privileges contract, while cleanly separating environmental differences such as cluster configuration or feature flags. From the perspective of privilege correctness and long-term test stability, this is a deliberate and justified design choice rather than an inheritance anti-pattern. To address the readability concern, I've added comprehensive Javadoc to the abstract base class and the concrete implementations explaining that the actual test cases are defined in the base class to enforce consistency across configurations. |
40fd7c5 to
9af3b37
Compare
…ices Signed-off-by: llilyy <llilyy0215@gmail.com>
Signed-off-by: llilyy <llilyy0215@gmail.com>
Signed-off-by: llilyy <llilyy0215@gmail.com>
Signed-off-by: llilyy <llilyy0215@gmail.com>
Signed-off-by: llilyy <llilyy0215@gmail.com>
8392561 to
1c3d1a2
Compare
Signed-off-by: llilyy <llilyy0215@gmail.com>
|
@cwperks @nibix |
|
given the current test implementation, we will have to re-implement the tests before we can merge #5827 in order to also have test coverage for the new privilege evaluation mode. This will then add friction to merging #5827. Regarding this:
As far as I understand, the approach with a parameterized test using the
For this exact purpose, parameterized tests do exist. |
nibix
left a comment
There was a problem hiding this comment.
As it seem to cause a lot of pain, approving...
Still, I would really appreciate it if the tests could be afterwards adapted to use the ClusterConfig enum. #5827 should also not wait much longer; and, actually, it will fix quite a lot of system index bugs.
…ecture Signed-off-by: Nils Bandener <nils.bandener@eliatra.com>
…ecture Signed-off-by: Nils Bandener <nils.bandener@eliatra.com>
…ecture Signed-off-by: Nils Bandener <nils.bandener@eliatra.com>
…ecture Signed-off-by: Nils Bandener <nils.bandener@eliatra.com>
Description
Category
Why these changes are required?
When
isSystemIndexPermissionEnabledis set totrue, plugin users are unable to access their own registered system indices. This happens because thehasExplicitIndexPrivilegecheck is performed before the plugin user's own system index access logic, causing the request to be rejected even though the plugin should have access to its own system indices.This breaks the expected behavior where plugins can manage their own system indices without requiring explicit
system_indexpermission.What is the old behavior before changes and new behavior after changes?
Old behavior:
isSystemIndexPermissionEnabled = true, all system index access (including plugin's own system indices) goes throughhasExplicitIndexPrivilegecheckevaluateSystemIndicesAccess()is never reached because the request is already rejectedNew behavior:
hasExplicitIndexPrivilegecheckisPluginIndexActioncondition is added to skip the permission check when:getMatchingPluginIndices()is added to calculate plugin's own system indices once and reuse it, avoiding code duplicationIssues Resolved
opensearch-project/job-scheduler#865
Testing
New Integration Tests Added:
SystemIndexPermissionEnabledTests.javawithisSystemIndexPermissionEnabled = trueconfigurationtestPluginShouldBeAbleToIndexDocumentIntoItsSystemIndextestPluginShouldBeAbleToBulkIndexDocumentIntoItsSystemIndextestPluginShouldBeAbleSearchOnItsSystemIndextestPluginShouldBeAbleGetOnItsSystemIndextestPluginShouldBeAbleUpdateOnItsSystemIndextestPluginShouldNotBeAbleToIndexDocumentIntoSystemIndexRegisteredByOtherPlugintestPluginShouldNotBeAbleToRunClusterActionstestPluginShouldNotBeAbleToBulkIndexDocumentIntoMixOfSystemIndexWhereAtLeastOneDoesNotBelongToPluginExisting Tests Verified:
SystemIndexTests- All tests pass (no regression withisSystemIndexPermissionEnabled = false)SystemIndexAccessEvaluatorTest- All unit tests pass (no impact on regular user behavior)Test Execution:
Check 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.