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.
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?
Subset of permissions check on creation #5012
Changes from 22 commits
9f695fa
d3fcc4a
6904317
17bca93
92d4e60
22cfbe8
665b9e9
e39df0d
ad63974
73eb2ab
6418226
bc8aacf
b90bae9
552aeda
aa506e7
8299645
eebe5fb
c079d09
5b48fb9
e13c055
a1057ce
b6aa196
bf31791
c95d256
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
Check warning on line 134 in src/main/java/org/opensearch/security/action/apitokens/ApiTokenAction.java
src/main/java/org/opensearch/security/action/apitokens/ApiTokenAction.java#L133-L134
Check warning on line 142 in src/main/java/org/opensearch/security/action/apitokens/ApiTokenAction.java
src/main/java/org/opensearch/security/action/apitokens/ApiTokenAction.java#L138-L142
Check warning on line 147 in src/main/java/org/opensearch/security/action/apitokens/ApiTokenAction.java
src/main/java/org/opensearch/security/action/apitokens/ApiTokenAction.java#L144-L147
Check warning on line 190 in src/main/java/org/opensearch/security/action/apitokens/ApiTokenAction.java
src/main/java/org/opensearch/security/action/apitokens/ApiTokenAction.java#L190
Check warning on line 368 in src/main/java/org/opensearch/security/action/apitokens/ApiTokenAction.java
src/main/java/org/opensearch/security/action/apitokens/ApiTokenAction.java#L368
Check warning on line 371 in src/main/java/org/opensearch/security/action/apitokens/ApiTokenAction.java
src/main/java/org/opensearch/security/action/apitokens/ApiTokenAction.java#L371
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 arequestedPattern
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.
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.
Do role definitions support this? I have only seen this in a context of masked fields
Edit: Found an example: https://github.com/opensearch-project/security/blob/main/src/test/resources/roles.yml#L20-L33
Edit2: Is that the purpose of the renderedMatcher?Looks like this is handled by WildcardMatcher itself.
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.
Added alias support in this commit: bf31791. I also shimmed in a way to not pass in a privilegesEvaluationContext into the indexpattern class, as long as you pass in the used components out of the context. What do y'all think of this change?
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.
How would this not cover aliases? i.e. if a user has a role mapping with read access to
logs
and requests a token with read access tologs
(assuminglogs
is an alias) won't this work?Agree on regexp support here, @derek-ho can we throw an IllegalArgumentException if the requested permission is for a regexp?
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.
I think it doesn't cover alias support for underlying indices, i.e. Users with access to
logs
alias would not be able to request api tokens for a subset of any of the underlying indices, even when they have permission to do so.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.
Regarding the regexp issue:
I think, one of the fundamental issues here is the following:
Normal users generally do not have access to the
roles.yml
configuration. Thus, they do not know how they gain access to the indices - they just know that they have access to the indices they can observe.Thus, they need to resort to trial-and-error process to see whether they can gain API tokens to an index or whether the roles.yml definition uses a construct that is not supported.
Obviously, this is sub-optimal from a UX point of view.
Ways around that issue - just from the top of my head:
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.
Can't this be handled another way though? i.e. prevent using tokens entirely if any role uses regex in
index_permissions
or skip the subset check for any role usingregexes
?One other way this could be handled is creating an API that a user can call that helps them comprehend what actions and index patterns they are able to select. This API could also be used to power UX for the feature.
What about glob-like patterns?
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.
It is quite a brain-twister to think about matching patterns against patterns 😅 .. but I thought this through again, and there might be another issue.
Consider:
I have in roles.yml privileges for the pattern
index_1?
. This gives me privileges onindex_10
,index_11
, etc., but not onindex_1
.I now try to request an API token for the index pattern
index_1*
. The patternindex_1?
will positively matchindex_1*
. The*
character will be bound to the?
. However, the patternindex_1*
is broader thanindex_1?
. It will also matchindex_1
, which was not matched byindex_1?
. Thus, we would have a privilege escalation vulnerability.Of course, this might be quite a theoretical issue where its real world applicability is questionable. Still, IMHO, security software should be also safe of such scenarios.
Thus, I would strongly recommend against matching any patterns against patterns. It is just too fragile.
I would still recommend the approach sketched out above:
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.
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.
Agree with this though it depends on the action.
If the security admin is going to a page in the security dashboards plugin to manage the existing tokens (listing them and performing actions such as revoke) then these should follow the authorization model of other security APIs.
If regular users are allowed to request a token (with a subset of their own permissions) then that could be authorized like other cluster actions in OpenSearch.
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.
I think (for now) my operating assumption would be that this is an admin-level action to issue api tokens to connect with other services programmatically. Since API tokens (currently) do not follow the new optimized privileges evaluation, and thus have higher performance penalty than other means of authc/z, and thus we should restrict this as much as possible. However, if there is community feedback/requests for this feature, then we can consider it at a later time. Since we want to authorize these APIs like the others, I added this logic.
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.
To be honest, it is a bit difficult for me to review this without a proper scope definition. During review, I learned from you about a couple of assumptions and assumed limitations (such as not using the optimized privilege evaluation code paths, not supporting regexes, etc). IMHO, there should be some definitions in the issue #1504 what's the initial goal to be achieved and what not. That will be then an information to guide the code review process. Otherwise, this review process will get quite inefficient.
If the assumption is indeed that issuing tokens is an admin-level action, I do wonder why we need the matching to existing privileges at all. Won't an admin-level action just be similar to granting new privileges?
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.
If its rolled out to admin users initially at first than I agree, but if the longer term plan is for other users to be able to request tokens then the logic to determine whether the requested permissions are a subset of the user's permissions would be needed. I was thinking to keep the logic simple and only consider: 1)
cluster_permissions
and 2)index_permissions
. For index permissions, would it be sufficient to limit the checks to concrete indices and glob-like patterns and prohibit regexes?In practice, I have not come across many roles definitions where cluster administrators use regex when defining the index patterns in a role. I'm sure its used, but not prevalent from my experience.
Check warning on line 449 in src/main/java/org/opensearch/security/action/apitokens/ApiTokenAction.java
src/main/java/org/opensearch/security/action/apitokens/ApiTokenAction.java#L449
Check warning on line 451 in src/main/java/org/opensearch/security/action/apitokens/ApiTokenAction.java
src/main/java/org/opensearch/security/action/apitokens/ApiTokenAction.java#L451