Create API for dashboards-plugins to get resource access level#6107
Draft
cwperks wants to merge 15 commits intoopensearch-project:mainfrom
Draft
Create API for dashboards-plugins to get resource access level#6107cwperks wants to merge 15 commits intoopensearch-project:mainfrom
cwperks wants to merge 15 commits intoopensearch-project:mainfrom
Conversation
…l for which resource is shared generally Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Craig Perkins <craig5008@gmail.com>
…rity into resource-visibility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a new security REST API for resolving the current user’s effective access on a single shareable resource:
GET /_plugins/_security/api/resource/access?resource_type=<type>&resource_id=<id>The goal is to give Dashboards plugins a simple, security-owned way to understand what the current user can do with a resource without re-implementing resource sharing logic in the UI.
This was motivated by the new collaborative docs plugin work, but the API is generic and intended for any resource-sharing-enabled plugin.
Problem
Today, a Dashboards plugin can fetch:
But it does not have a clean API for:
That leaves the UI with two awkward options:
authinfo+share_with+ role matching403from a write action and then degrade the UX afterwardBoth approaches push authorization reasoning into the client, which is brittle and duplicates logic that already exists in security.
What this PR adds
New endpoint:
GET /_plugins/_security/api/resource/accessQuery params:
resource_typeresource_idResponse shape:
{ "access": { "resource_id": "abc123", "resource_type": "docs-document", "is_owner": false, "is_admin": false, "effective_access_level": "docs_read_only", "access_levels": ["docs_read_only"], "allowed_actions": ["docs:document/get", "docs:document/list"], "can_share": false } }Behavior
The endpoint resolves access for the current authenticated user by:
is_owner,is_admin, andcan_shareBehavior notes:
403400404Implementation
Main additions:
/api/resource/accessResourceAccessHandlermethod to resolve access levels and allowed actions for the current user on a single resourceThis intentionally builds on existing resource-sharing internals rather than introducing a second permission model.
Why this shape
I chose to return both:
access_levelsallowed_actionsinstead of only a single “effective access level” because:
allowed_actionsare what UIs actually need to enable/disable affordanceseffective_access_levelis included as a convenience for display and simple UI flows.Testing
Added integration coverage using
sample-resource-pluginfor:Follow-up / motivation
This API is already useful for a Dashboards resource-sharing consumer like the docs plugin, where the UI needs to know up front whether to allow:
instead of waiting for a write failure.
Example use cases
Dashboards plugins can use this to:
Checklist
If you want, I can also turn this into a shorter, more “upstream OpenSearch-style” PR description with less context and a tighter changelog tone.