Skip to content

[Resource Access Control] [Part3] Introduces a sample plugin to demonstrate usage of Resource Access Control feature#5187

Merged
DarshitChanpura merged 36 commits intoopensearch-project:feature/resource-permissionsfrom
DarshitChanpura:sample-resource-plugin-spi
Apr 21, 2025
Merged

[Resource Access Control] [Part3] Introduces a sample plugin to demonstrate usage of Resource Access Control feature#5187
DarshitChanpura merged 36 commits intoopensearch-project:feature/resource-permissionsfrom
DarshitChanpura:sample-resource-plugin-spi

Conversation

@DarshitChanpura
Copy link
Copy Markdown
Member

@DarshitChanpura DarshitChanpura commented Mar 17, 2025

#5016 is being broken down into smaller pieces. This is part 3.

Description

Introduces a sample resource plugin that demonstrate usage of opensearch-security-spi for resource access control.

Issues Resolved

Related to #4500

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.

@DarshitChanpura
Copy link
Copy Markdown
Member Author

CI should pass once #5185 and #5186 are merged.

…rol, and add extensive integration tests

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

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>
@DarshitChanpura DarshitChanpura force-pushed the sample-resource-plugin-spi branch from 16774d1 to 4c21bbd Compare March 20, 2025 20:43
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>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
@DarshitChanpura DarshitChanpura force-pushed the sample-resource-plugin-spi branch from a4bf285 to e13e81f Compare March 31, 2025 02:48
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>
… fetch all resource-ids for a user

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 18, 2025

Codecov Report

Attention: Patch coverage is 0% with 28 lines in your changes missing coverage. Please review.

Project coverage is 70.52%. Comparing base (adf96f1) to head (83483c7).
Report is 1 commits behind head on feature/resource-permissions.

Files with missing lines Patch % Lines
...ecurity/resources/ResourceSharingIndexHandler.java 0.00% 15 Missing ⚠️
...arch/security/resources/ResourceAccessHandler.java 0.00% 13 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                        Coverage Diff                        @@
##           feature/resource-permissions    #5187       +/-   ##
=================================================================
+ Coverage                              0   70.52%   +70.52%     
=================================================================
  Files                                 0      342      +342     
  Lines                                 0    23175    +23175     
  Branches                              0     3591     +3591     
=================================================================
+ Hits                                  0    16344    +16344     
- Misses                                0     5057     +5057     
- Partials                              0     1774     +1774     
Files with missing lines Coverage Δ
...g/opensearch/security/dlic/rest/support/Utils.java 58.66% <ø> (ø)
...arch/security/resources/ResourceAccessHandler.java 4.16% <0.00%> (ø)
...ecurity/resources/ResourceSharingIndexHandler.java 2.77% <0.00%> (ø)

... and 339 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>
/**
* This abstract class defines common tests between different feature flag scenarios
*/
public abstract class AbstractSampleResourcePluginFeatureEnabledTests extends AbstractSampleResourcePluginTests {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd recommend to avoid super classes for test classes, as these take away flexibility and composability, as you can have only one super class. Additionally, the inherited @test methods make it quite difficult to understand what is being tested. IMHO, one should follow the "composition over inheritance" pattern and use references to other classes intead.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The tests are common for feature enabled scenarios. This class is inherited by 3 tests which implement 3 scenarios: User with full access, user with limited access and direct access when system index feature is disabled. The super-class test suite was added only to avoid duplicated tests-code.

}
}

@SuppressWarnings("unchecked")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Using @SuppressWarnings("unchecked") on untrusted input (the request body source) bears the risk of getting ClassCastExceptions deep inside the application code. While this is usually not security critical, it might locating the root cause of issues diificult - both for admins and for end users.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I agree. However this is is a sample plugin and hence should be fine IMO.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Well, the primary purpse of sample plugins is to give other developers an idea/blueprint on how to design their own code. Thus, there is a big chance that developers will follow any pattern displayed in that code base, including bad patterns.

And, experience shows that developers have the tendency to follow patterns they are finding in existing code bases, no matter how bad these actually might be.

IMHO, to cope for this, we should add in such cases at least a comment like "this is just done for simplicity, do not do that for real plugins".

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We do use this pattern at a decent number of places in security plugin. Here is one such example. I will add a comment here stating suppressing should be avoided in real-world, however there is no mechanism to stop plugin's from implementing it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There are different "risk classes" of using @SuppressWarnings("unchecked"). For the example you have linked, it is possible to argue within a minute that this is actually a safe cast and no late ClassCastExceptions can be caused by it.

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 merged commit 04aa12d into opensearch-project:feature/resource-permissions Apr 21, 2025
45 checks passed
@DarshitChanpura
Copy link
Copy Markdown
Member Author

Merged this feature-branch PR as i didn't see amy blocking reviews. The PR against main is already open and is the last step to getting this feature merged.

DarshitChanpura added a commit to DarshitChanpura/security that referenced this pull request Apr 21, 2025
…strate usage of Resource Access Control feature (opensearch-project#5187)

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
DarshitChanpura added a commit that referenced this pull request Apr 21, 2025
…strate usage of Resource Access Control feature (#5187)

Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants