-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Add manage_own_api_key
cluster privilege
#45696
Add manage_own_api_key
cluster privilege
#45696
Conversation
Currently, cluster permission checks whether a cluster action is permitted and optionally in the context of a request. There are scenarios where we would want to check whether the cluster action is permitted, optionally in the context of a request and current authentication. For example, management of API keys is only restricted to the API keys owned by the current user. In this case, along with the cluster action and API key request, the check needs to perform whether the currently authenticated user is indeed allowed to operate only on owned API keys. With this commit, we are introducing one more context of the current authentication that can be considered during permission evaluation. Relates: elastic#40031
…based-permission-check
Pinging @elastic/es-security |
The permission checks that are dependent on actions and optionally on request and/or on authentication, now have a way to specify the predicates. By default the implementation will tests all the predicates to be successful for the operation to be allowed. In case customization is required one has option to implement `PermissionCheck`. - Adds a permission check predicate interface that also allows implementers to specify behavior for `implies`.
This commit adds `manage_own_api_key` cluster privilege which only allows api key cluster actions on API keys owned by the current authenticated user.
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 left two questions.
...a/org/elasticsearch/xpack/core/security/authz/privilege/ManageOwnApiKeyClusterPrivilege.java
Show resolved
Hide resolved
...security/src/main/java/org/elasticsearch/xpack/security/action/TransportGetApiKeyAction.java
Outdated
Show resolved
Hide resolved
…based-permission-check
…based-permission-check
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 still not clear to me what API-Key-privileges do I have if I authenticate with an API Key. Do I inherit the API-Key privileges from the user that originally created the first API key that created my API Key, etc... ? Or I don't have any API Key privilege.
For example, a user with manage_api_key
create a key. Does that key grant manage_api_key
as well? I think it shouldn't but the code looks like it does.
The same for manage_own_api_key
.
I
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ApiKeyService.java
Show resolved
Hide resolved
...k/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/ApiKeyIntegTests.java
Show resolved
Hide resolved
...a/org/elasticsearch/xpack/core/security/authz/privilege/ManageOwnApiKeyClusterPrivilege.java
Outdated
Show resolved
Hide resolved
.../src/main/java/org/elasticsearch/xpack/core/security/authz/permission/ClusterPermission.java
Outdated
Show resolved
Hide resolved
.../src/main/java/org/elasticsearch/xpack/core/security/authz/permission/ClusterPermission.java
Show resolved
Hide resolved
...a/org/elasticsearch/xpack/core/security/authz/privilege/ManageOwnApiKeyClusterPrivilege.java
Outdated
Show resolved
Hide resolved
...a/org/elasticsearch/xpack/core/security/authz/privilege/ManageOwnApiKeyClusterPrivilege.java
Outdated
Show resolved
Hide resolved
@albertzaharovits
|
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 left one suggestion and voiced my preference about not using the owner
flag in the authz process.
LGTM
...a/org/elasticsearch/xpack/core/security/authz/privilege/ManageOwnApiKeyClusterPrivilege.java
Outdated
Show resolved
Hide resolved
Thank you for the tabled explanation @bizybot ! I agree we should explicitly deny authorization for API keys with |
…security/authz/privilege/ManageOwnApiKeyClusterPrivilege.java Co-Authored-By: Albert Zaharovits <[email protected]>
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 we're very close on this.
...a/org/elasticsearch/xpack/core/security/authz/privilege/ManageOwnApiKeyClusterPrivilege.java
Outdated
Show resolved
Hide resolved
...a/org/elasticsearch/xpack/core/security/authz/privilege/ManageOwnApiKeyClusterPrivilege.java
Outdated
Show resolved
Hide resolved
.../elasticsearch/xpack/core/security/authz/privilege/ManageOwnApiKeyClusterPrivilegeTests.java
Outdated
Show resolved
Hide resolved
.../elasticsearch/xpack/core/security/authz/privilege/ManageOwnApiKeyClusterPrivilegeTests.java
Outdated
Show resolved
Hide resolved
...k/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/ApiKeyIntegTests.java
Outdated
Show resolved
Hide resolved
...k/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/ApiKeyIntegTests.java
Outdated
Show resolved
Hide resolved
realm = (String) authentication.getMetadata().get(ApiKeyService.API_KEY_CREATOR_REALM); | ||
} else { | ||
realm = authentication.getAuthenticatedBy().getName(); | ||
} |
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.
The same logic is in 2 transport actions. That seems like a strong enough argument to move it to a static method on the service.
- separate tests to test one thing - common code to extract realm name move to ApiKeyService - final and move variables to where it is being used - test API keys with no cluster privilege for an API key
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.
LGTM, subject to 1 minor change.
...a/org/elasticsearch/xpack/core/security/authz/privilege/ManageOwnApiKeyClusterPrivilege.java
Outdated
Show resolved
Hide resolved
@bizybot It looks like you requested another approval after I had already commented. |
Oh, I looked at one of the cached pages in the browser and thought I missed on refresh. |
This commit adds
manage_own_api_key
cluster privilege whichonly allows api key cluster actions on API keys owned by the
currently authenticated user.
Relates: #40031