Skip to content
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

[Feature] Introduces Centralized Resource Access Control and Sharing #5016

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

Conversation

DarshitChanpura
Copy link
Member

@DarshitChanpura DarshitChanpura commented Jan 10, 2025

Description

Introduces a new authorization mechanism to control access to resources defined by plugins.
There are 4 major components to this PR:

  1. Introduces an SPI that defines the contracts for a resource sharing plugin as well as Resource Access Control plugin.
  2. Introduces 4 new APIs that expose resource-sharing and access verification capabilities.
  3. Modifies DLS to implicitly check for resource-access for requesting user if incoming request is for a resource
  4. Adds a sample resource plugin with tests to demonstrate the usage of this new feature.
  5. Adds a feature flag to toggle the feature. Feature is enabled by default.
  • Category : New feature
  • Why these changes are required?
    • At present, plugins have implemented in-house authorization mechanisms for a lack of centralized framework. This PR introduces a centralized way to offload resource permissions check to security plugin. Plugins will leverage the java APIs introduced in core.

Issues Resolved

Testing

  • automated and manual testing

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 <[email protected]>
Signed-off-by: Darshit Chanpura <[email protected]>
Signed-off-by: Darshit Chanpura <[email protected]>
Signed-off-by: Darshit Chanpura <[email protected]>
Signed-off-by: Darshit Chanpura <[email protected]>
Signed-off-by: Darshit Chanpura <[email protected]>
Signed-off-by: Darshit Chanpura <[email protected]>
Signed-off-by: Darshit Chanpura <[email protected]>
Signed-off-by: Darshit Chanpura <[email protected]>
Signed-off-by: Darshit Chanpura <[email protected]>
Signed-off-by: Darshit Chanpura <[email protected]>
Signed-off-by: Darshit Chanpura <[email protected]>
Signed-off-by: Darshit Chanpura <[email protected]>
@DarshitChanpura
Copy link
Member Author

DarshitChanpura commented Jan 20, 2025

I would guess that this is only because the resource sharing index is not marked as hidden. Marking it as hidden should fix this issue without changing the observable behavior.

@nibix should the index be marked as hidden? On another note, this PR has been updated with integration test for sample plugin and these tests run with CI as well. Would you mind re-reviewing it? I'll be pushing the changes to fix code-cov CI.

@DarshitChanpura
Copy link
Member Author

DarshitChanpura commented Jan 20, 2025

In case anyone needs help getting started with review, here is an order that you can follow.

  1. Start with the SPI folder.
  2. Review OpenSearchSecurityPlugin to understand how the SPI is utilized to setup resource index listeners.
  3. Next, review resources package, particularly ResourceAccessHandler and ResourceSharingIndexHandler.
  4. Next review DLS/FLS related changes.
  5. Once you review the main package, you can then review Sample-resource plugin to understand how a plugin might utilize it and checkout the integration tests to understand two paths, i.e. feature flag enabled and disabled.

*
* @opensearch.experimental
*/
public interface ResourceSharingExtension {
Copy link
Member

Choose a reason for hiding this comment

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

nit: Similar to previous comment, wdyt about naming this SharableResourceExtension?

Copy link
Member Author

Choose a reason for hiding this comment

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

IMO ResourceSharingExtension is more clear.

@@ -755,7 +796,10 @@ public Weight doCache(Weight weight, QueryCachingPolicy policy) {

@Override
public void onPreQueryPhase(SearchContext context) {
dlsFlsValve.handleSearchContext(context, threadPool, namedXContentRegistry.get());
CompletableFuture.runAsync(
Copy link
Member

Choose a reason for hiding this comment

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

Is this change necessary?

Copy link
Collaborator

@nibix nibix Jan 21, 2025

Choose a reason for hiding this comment

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

Please see the comment in #5016 (comment) ... i fear, the issue described there still holds.

While the method suggests that the call is "async", the join() call again blocks an OpenSearch thread which brings the risk of thread pool exhaustion and thus deadlocks. It just circumvents the assertion which is done in the actionGet() method.

I am sorry to say, but I am pretty confident that it is not safely possible to make search requests within low level operations like onPreQueryPhase or the lucene filter leaf readers. Even if it would be possible, the performance would be miserable, as this would cause the query to be fired thousands of times for a single user search.

I fear that a completely different approach is necessary:

  • Filter level DLS was designed to allow DLS for term lookup queries which seems a thing which comes closest to the current approach.
  • Alternatively, the whole resource sharing information must be kept in the Java heap.

Still, I have severe doubts whether DLS is really the correct way to tackle this issue.

Reasons:

Copy link
Member

Choose a reason for hiding this comment

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

DLS does only cover read operations. It does not cover write operations and cannot be quickly extended to cover it. I guess, resource sharing, however, also needs support for write operations?

I think with the approach @DarshitChanpura took in this PR, there is a separate index that security owns and keeps track of the resource_user (the owner of the resource) along with sharing info. Plugins reserve the right to write to their system indices, but if the index contains resources (as put forward in this feature) then behind-the-scenes security will filter the search request to only return resources pertinent to the authenticated user.

Copy link
Member Author

Choose a reason for hiding this comment

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

The idea behind this approach was to prevent plugin dev errors. It was discussed as part of the PR in core. (comment). By implementing a DLS approach we do not require plugin devs to make any calls manually.

@reta @nibix @cwperks I think we need to align on the path forward. DLS or not? I've already introduced a sharing api as part of this PR.

@nibix
Copy link
Collaborator

nibix commented Jan 21, 2025

@DarshitChanpura

should the index be marked as hidden?

yes, any system index which is not directly relevant to the end user should be not visible by default to the user. Thus, it should be marked as hidden.

@DarshitChanpura
Copy link
Member Author

@DarshitChanpura

should the index be marked as hidden?

yes, any system index which is not directly relevant to the end user should be not visible by default to the user. Thus, it should be marked as hidden.

In this case the index is not technically directly relevant however when user shares the info or wants to check who has access to this resource. So I'm not sure if hidden still applies here.

@DarshitChanpura
Copy link
Member Author

I've opened a discussion issue to finalize the approach. #5062

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants