opensearch-project / security

🔐 Secure your cluster with TLS, numerous authentication backends, data masking, audit logging as well as role-based access control on indices, documents, and fields
https://opensearch.org/docs/latest/security-plugin/index/
Apache License 2.0
180 stars 264 forks source link

New algorithm for resolving action groups #4448

Closed nibix closed 2 weeks ago

nibix commented 2 weeks ago

Description

This code change is just in preparation for the change in #4380 as requested in https://github.com/opensearch-project/security/pull/4416#pullrequestreview-2106138499 .

This replaces the previous action group resolution algorithm done in ConfigModelV7 by a new one, which has a number of enhancements:

Testing

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.

codecov[bot] commented 2 weeks ago

Codecov Report

Attention: Patch coverage is 82.75862% with 10 lines in your changes missing coverage. Please review.

Project coverage is 65.48%. Comparing base (94f7ccb) to head (110426f). Report is 5 commits behind head on main.

:exclamation: Current head 110426f differs from pull request most recent head 289e9dd

Please upload reports for the commit 289e9dd to get more accurate results.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/opensearch-project/security/pull/4448/graphs/tree.svg?width=650&height=150&src=pr&token=rBpySfQXMt&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opensearch-project)](https://app.codecov.io/gh/opensearch-project/security/pull/4448?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opensearch-project) ```diff @@ Coverage Diff @@ ## main #4448 +/- ## ========================================== + Coverage 65.45% 65.48% +0.03% ========================================== Files 312 313 +1 Lines 22042 22064 +22 Branches 3559 3562 +3 ========================================== + Hits 14427 14449 +22 + Misses 5843 5840 -3 - Partials 1772 1775 +3 ``` | [Files](https://app.codecov.io/gh/opensearch-project/security/pull/4448?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opensearch-project) | Coverage Δ | | |---|---|---| | [...ecurityconf/impl/SecurityDynamicConfiguration.java](https://app.codecov.io/gh/opensearch-project/security/pull/4448?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fopensearch%2Fsecurity%2Fsecurityconf%2Fimpl%2FSecurityDynamicConfiguration.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opensearch-project#diff-c3JjL21haW4vamF2YS9vcmcvb3BlbnNlYXJjaC9zZWN1cml0eS9zZWN1cml0eWNvbmYvaW1wbC9TZWN1cml0eUR5bmFtaWNDb25maWd1cmF0aW9uLmphdmE=) | `80.30% <100.00%> (+0.77%)` | :arrow_up: | | [...pensearch/security/securityconf/ConfigModelV7.java](https://app.codecov.io/gh/opensearch-project/security/pull/4448?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fopensearch%2Fsecurity%2Fsecurityconf%2FConfigModelV7.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opensearch-project#diff-c3JjL21haW4vamF2YS9vcmcvb3BlbnNlYXJjaC9zZWN1cml0eS9zZWN1cml0eWNvbmYvQ29uZmlnTW9kZWxWNy5qYXZh) | `67.74% <80.00%> (-0.18%)` | :arrow_down: | | [...h/security/securityconf/FlattenedActionGroups.java](https://app.codecov.io/gh/opensearch-project/security/pull/4448?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fopensearch%2Fsecurity%2Fsecurityconf%2FFlattenedActionGroups.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opensearch-project#diff-c3JjL21haW4vamF2YS9vcmcvb3BlbnNlYXJjaC9zZWN1cml0eS9zZWN1cml0eWNvbmYvRmxhdHRlbmVkQWN0aW9uR3JvdXBzLmphdmE=) | `81.25% <81.25%> (ø)` | | ... and [3 files with indirect coverage changes](https://app.codecov.io/gh/opensearch-project/security/pull/4448/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opensearch-project)
nibix commented 2 weeks ago

@cwperks

Thank you @nibix! This change looks good to me. One scenario I'd like to see covered would be a change in action group and verify its reflected in the new FlattenedActionGroups data structure.

This is certainly an important thing to test. However, such configuration updates are handled by the DynamicConfigFactory class which is not changed by this PR.

There used to be an integration test which would test what you are asking for - that is, it changed action groups via API and tested the effectiveness of these changes via normal user operations. That was at https://github.com/opensearch-project/security/blob/069249656970e839302a0d3b8b87c82fbf3e56cc/src/test/java/org/opensearch/security/dlic/rest/api/ActionGroupsApiTest.java . There was recently a refactor of this test in #4371. I quickly skimmed the replacement code and could not find any logic which tests the effectiveness of the modified configuration, but maybe I missed something?

nibix commented 2 weeks ago

@DarshitChanpura

Would the new runtime be more linear compared to the older implementation because we are using a combination of BFS + DFS?

The major gain comes from the fact that we calculate the resolved action group space only once instead of re-calculating it again and again for each action privilege configuration. Additionally, by using an iterative algorithm instead of a recursive algorithm it is easier for us to detect that resolution has finished and abort early. That give some more gain. However, all these gains only pertain to the config reload phase and not to the actual privilege evaluation.

DarshitChanpura commented 2 weeks ago

Merging this since we have approvals. Any discussions can be addressed in follow-up PRs.