-
Notifications
You must be signed in to change notification settings - Fork 291
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
Subset of permissions check on creation #5012
base: feature/api-tokens
Are you sure you want to change the base?
Conversation
Signed-off-by: Derek Ho <[email protected]>
Signed-off-by: Derek Ho <[email protected]>
Signed-off-by: Derek Ho <[email protected]>
Signed-off-by: Derek Ho <[email protected]>
Signed-off-by: Derek Ho <[email protected]>
…rmissions Signed-off-by: Derek Ho <[email protected]>
Signed-off-by: Derek Ho <[email protected]>
Signed-off-by: Derek Ho <[email protected]>
Signed-off-by: Derek Ho <[email protected]>
Signed-off-by: Derek Ho <[email protected]>
Signed-off-by: Derek Ho <[email protected]>
Signed-off-by: Derek Ho <[email protected]>
Signed-off-by: Derek Ho <[email protected]>
Signed-off-by: Derek Ho <[email protected]>
… write test Signed-off-by: Derek Ho <[email protected]>
Signed-off-by: Derek Ho <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feature/api-tokens #5012 +/- ##
======================================================
- Coverage 71.46% 71.23% -0.24%
======================================================
Files 334 354 +20
Lines 22552 23322 +770
Branches 3590 3692 +102
======================================================
+ Hits 16117 16613 +496
- Misses 4642 4870 +228
- Partials 1793 1839 +46
|
Signed-off-by: Derek Ho <[email protected]>
Signed-off-by: Derek Ho <[email protected]>
Signed-off-by: Derek Ho <[email protected]>
Signed-off-by: Derek Ho <[email protected]>
…curity into subset Signed-off-by: Derek Ho <[email protected]>
Signed-off-by: Derek Ho <[email protected]>
* Validates that the user has the required permissions to create an API token (must be a subset of their own permissions) | ||
* */ | ||
@SuppressWarnings("unchecked") | ||
void validateUserPermissions(List<String> clusterPermissions, List<ApiToken.IndexPermission> indexPermissions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, the token they are requesting is validated to be a subset of the permissions available to them in roles.yml, right?
What is supposed to happen if the permissions in roles.yml are later changed, especially if they are reduced?
// Early return conditions | ||
if (roles.isEmpty()) { | ||
throw new OpenSearchException("User does not have any roles"); | ||
} else if (roles.contains("all_access")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this assumption safe?
List<String> roleIndexPerms = indexPermission.getAllowed_actions(); | ||
|
||
// Check if this role's pattern covers the requested pattern | ||
if (WildcardMatcher.from(rolePatterns).test(requestedPattern)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assume that I have a role with the index_pattern
/index_[0-9]+/
. How can a requestedPattern
look like that replicates this pattern?
At the moment, I have doubts that simple pattern matching can be used to support the full pattern semantics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also does not cover alias semantics.
return DynamicConfigFactory.addStatics(loaded); | ||
} | ||
|
||
protected void authorizeSecurityAccess(RestRequest request) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about having a dedicated transport action backing the REST action? Then, one would get access control out of the box without needing explicit checks within the action code.
Description
This PR adds permission checks around API token creation, and cleans up misc. items from the feature branch, including authorizing API token endpoint properly and stashing the context in order to perform the API token refresh action without explicit permission to do so. This PR is dependent on #4992 to be merged first, and this PR only contains the following changes:
https://github.com/opensearch-project/security/pull/5012/files/aa506e78eb5699d2580e28d4bb0f0060971449e1..e13c055e063ae3e5ee40386a53155e5c65893b58
Issues Resolved
[List any issues this PR will resolve]
Is this a backport? If so, please add backport PR # and/or commits #, and remove
backport-failed
label from the original PR.Do these changes introduce new permission(s) to be displayed in the static dropdown on the front-end? If so, please open a draft PR in the security dashboards plugin and link the draft PR here
Testing
[Please provide details of testing done: unit testing, integration testing and manual 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.