Skip to content

[Resource Sharing] Adds a Resource Access Evaluator for standalone Resource access authorization #5408

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

Open
wants to merge 67 commits into
base: main
Choose a base branch
from

Conversation

DarshitChanpura
Copy link
Member

@DarshitChanpura DarshitChanpura commented Jun 17, 2025

Description

This PR adds a new privilege evaluator for evaluating access to a resource. #5281 introduced a way for plugin offload sharing and access evaluation to security plugin but that was done by requiring plugins to call verifyAccess method on their end. This leaves room for error. This new evaluator will filter all resource access requests through SecurityFilter class without requiring plugins to explicitly call verifyAccess method. It also adds support for access-levels instead of just the default one declared in the previous PR.

Notes:

  1. Removes verifyAccess from the client as plugin no longer have to explicitly call the method to check user access.
  2. Sharing model will be in full-effect. i.e. if a user has full access to a resource they can update, manage access or delete it.
  3. Doesn't consider hierarchical access. It will be added in future PRs.

Issues Resolved

#5442

Testing

  • Automated Tests

Check List

  • New functionality includes testing
  • New functionality has been documented
    - [ ] New Roles/Permissions have a corresponding security dashboards plugin PR
    - [ ] API changes companion pull request created
  • Commits are signed per the DCO using --signoff

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.

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
…ource access

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
… framework

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
@DarshitChanpura DarshitChanpura added the resource-permissions Label to track all items related to resource permissions label Jun 17, 2025
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
@DarshitChanpura DarshitChanpura force-pushed the standalone-resource-authz branch from 8c7eb57 to f636120 Compare June 18, 2025 17:40
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Copy link

codecov bot commented Jun 18, 2025

Codecov Report

❌ Patch coverage is 75.13661% with 91 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.80%. Comparing base (5dc83be) to head (f7ddaac).

Files with missing lines Patch % Lines
...org/opensearch/security/filter/SecurityFilter.java 63.52% 27 Missing and 4 partials ⚠️
...h/security/privileges/ResourceAccessEvaluator.java 70.14% 15 Missing and 5 partials ⚠️
...ecurity/resources/ResourceSharingIndexHandler.java 71.01% 18 Missing and 2 partials ⚠️
...arch/security/resources/ResourceAccessHandler.java 53.33% 7 Missing ⚠️
...ecurity/spi/resources/sharing/ResourceSharing.java 86.36% 2 Missing and 1 partial ⚠️
...tions/rest/revoke/RevokeResourceAccessRequest.java 71.42% 2 Missing ⚠️
...ource/actions/rest/share/ShareResourceRequest.java 71.42% 2 Missing ⚠️
...va/org/opensearch/security/auth/RolesInjector.java 75.00% 0 Missing and 2 partials ⚠️
...rce/actions/rest/create/CreateResourceRequest.java 50.00% 1 Missing ⚠️
...ns/rest/revoke/RevokeResourceAccessRestAction.java 92.85% 0 Missing and 1 partial ⚠️
... and 2 more
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5408      +/-   ##
==========================================
+ Coverage   72.78%   72.80%   +0.02%     
==========================================
  Files         398      398              
  Lines       24641    24693      +52     
  Branches     3747     3759      +12     
==========================================
+ Hits        17934    17977      +43     
- Misses       4878     4887       +9     
  Partials     1829     1829              
Files with missing lines Coverage Δ
...org/opensearch/sample/SampleResourceExtension.java 100.00% <100.00%> (ø)
...va/org/opensearch/sample/SampleResourcePlugin.java 96.55% <ø> (-0.23%) ⬇️
...rce/actions/rest/create/UpdateResourceRequest.java 56.25% <100.00%> (+6.25%) ⬆️
...rce/actions/rest/delete/DeleteResourceRequest.java 58.33% <100.00%> (+8.33%) ⬆️
.../resource/actions/rest/get/GetResourceRequest.java 58.33% <100.00%> (+8.33%) ⬆️
...ce/actions/rest/share/ShareResourceRestAction.java 87.50% <100.00%> (+4.16%) ⬆️
...tions/transport/DeleteResourceTransportAction.java 66.66% <100.00%> (-2.78%) ⬇️
.../actions/transport/GetResourceTransportAction.java 88.88% <100.00%> (-4.96%) ⬇️
...transport/RevokeResourceAccessTransportAction.java 100.00% <100.00%> (ø)
...tions/transport/UpdateResourceTransportAction.java 77.77% <100.00%> (-2.72%) ⬇️
... and 23 more

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
…abled scenarios

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
…api test

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
@DarshitChanpura DarshitChanpura force-pushed the standalone-resource-authz branch from 70b7628 to 98eef3a Compare July 8, 2025 20:43
@DarshitChanpura DarshitChanpura force-pushed the standalone-resource-authz branch 2 times, most recently from c472133 to d842b4d Compare July 14, 2025 15:57
@DarshitChanpura DarshitChanpura force-pushed the standalone-resource-authz branch from d842b4d to 9871f17 Compare July 14, 2025 16:04
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
…ecurity filter

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
@DarshitChanpura
Copy link
Member Author

@nibix @cwperks All outstanding concerns have been addressed. mind re-reviewing the PR?

@DarshitChanpura DarshitChanpura force-pushed the standalone-resource-authz branch from 0dc358f to 9876fde Compare July 25, 2025 17:30
…s context in action-listener, and merges main

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
@DarshitChanpura DarshitChanpura force-pushed the standalone-resource-authz branch from 76db70e to 6670f51 Compare July 25, 2025 19:31
// NOTE: Since resource-access evaluation requires fetching documents from index, we make the call async otherwise it would
// require blocking transport threads leading to thread exhaustion and request timeouts
// We perform the rest of the evaluation as normal if the request is not for resource-access or if the feature is disabled
resourceAccessEvaluator.evaluateAsync(request, action, context, ActionListener.wrap(response -> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see if we can move this down into PrivilegesEvaluator along with the rest of the authorizers like system index and snapshot restore.

I know that one of the problems is PrivilegesEvaluatorResponse pres = eval.evaluate(context); expects a return value of PrivilegesEvaluatorResponse and not designed to be async.

I'm wondering if it makes sense to change this to either return an Optional or just handle the case where it can return null and then simply return. i.e. if the return value indicates that privilege evaluation is not done, then it means its being done async so stop here and the decision to proceed will be handled in the async call where it either proceeds through the chain or returns early with forbidden error if the user does not have access.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a markPending() method in PrivilegeEvalResponse class. I tried using it but was not successful. I can give it another try. With rest of PrivilegeEval being synchronous there are only 2 paths forward, as i see:

  1. Create a delegating handler that handles rest of the evaluation when feature is disabled or request is not of Resource type
  2. Utilize markPending() to indicate that access is currently being evaluated and will be processed by the evaluator. However, due to the nature of PrivilegeEval being synchronous i'm not entirely sure if that will be helpful.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

markPending() looks perfectly suited for this use-case :). I see its not utilized atm as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
resource-permissions Label to track all items related to resource permissions v3.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants