-
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
REST API changes for manage-own-api-key privilege #44936
REST API changes for manage-own-api-key privilege #44936
Conversation
This commit adds a flag that can be set to `true` if the API key request (Get or Invalidate) is for the API keys owned by the current authenticated user only. The Get API behavior would be: - when `my_api_keys_only` is set to `true` `GET /_security/api_key?id=abcd&my_api_keys_only=true` the Rest controller will take care of setting `realm_name` and `username` to the values for authenticated user and only return results if it finds one owned by the currently authenticated user. - when `my_api_keys_only` is set to `false` (default) `GET /_security/api_key?id=abcd` the Rest controller will assume `realm_name` and `username` to be unspecified meaning it will try to search for the API key across users and realms. This will fail if the user has only `manage_own_api_key` privilege. Similarly, for Delete API key behavior: - when `my_api_keys_only` is set to `true` `DELETE /_security/api_key` ``` { "id" : "VuaCfGcBCdbkQm-e5aOx", "my_api_keys_only": "true" } ``` the Rest controller will take care of setting `realm_name` and `username` to the values for authenticated user and only invalidate key if it finds one owned by the currently authenticated user. - when `my_api_keys_only` is set to `false` (default) `DELETE /_security/api_key` ``` { "id" : "VuaCfGcBCdbkQm-e5aOx", "my_api_keys_only": "true" } ``` the Rest controller will assume `realm_name` and `username` to be unspecified meaning it will try to search for the API key across users and realms. This will fail if the user has only `manage_own_api_key` privilege.
Pinging @elastic/es-security |
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 save for the lack of version guards.
...plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/GetApiKeyRequest.java
Outdated
Show resolved
Hide resolved
...core/src/main/java/org/elasticsearch/xpack/core/security/action/InvalidateApiKeyRequest.java
Outdated
Show resolved
Hide resolved
|
@elasticmachine run elasticsearch-ci/packaging-sample |
Did you consider alternatives for the parameter name? I don't love it (it's a bit verbose), but I don't want to go back over old ground if you've worked through a bunch of options already. I would think that |
I did consider but went with verbose as the intent was clear with the name, I agree it is too verbose now that I look at it. I like |
I'm personally not that worried about whether the meaning of the parameter is 100% obvious from its name - we have docs. |
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 didn't get to finish my review, but I left some comments...
...n/core/src/test/java/org/elasticsearch/xpack/core/security/action/GetApiKeyRequestTests.java
Outdated
Show resolved
Hide resolved
...n/core/src/test/java/org/elasticsearch/xpack/core/security/action/GetApiKeyRequestTests.java
Outdated
Show resolved
Hide resolved
...n/core/src/test/java/org/elasticsearch/xpack/core/security/action/GetApiKeyRequestTests.java
Outdated
Show resolved
Hide resolved
...n/core/src/test/java/org/elasticsearch/xpack/core/security/action/GetApiKeyRequestTests.java
Outdated
Show resolved
Hide resolved
…security/action/GetApiKeyRequestTests.java Co-Authored-By: Tim Vernum <[email protected]>
…security/action/GetApiKeyRequestTests.java Co-Authored-By: Tim Vernum <[email protected]>
…security/action/GetApiKeyRequestTests.java Co-Authored-By: Tim Vernum <[email protected]>
…security/action/GetApiKeyRequestTests.java Co-Authored-By: Tim Vernum <[email protected]>
could not download artifacts |
...plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/GetApiKeyRequest.java
Outdated
Show resolved
Hide resolved
...core/src/main/java/org/elasticsearch/xpack/core/security/action/InvalidateApiKeyRequest.java
Outdated
Show resolved
Hide resolved
...src/test/java/org/elasticsearch/xpack/core/security/action/InvalidateApiKeyRequestTests.java
Outdated
Show resolved
Hide resolved
...src/test/java/org/elasticsearch/xpack/core/security/action/InvalidateApiKeyRequestTests.java
Outdated
Show resolved
Hide resolved
...src/test/java/org/elasticsearch/xpack/core/security/action/InvalidateApiKeyRequestTests.java
Outdated
Show resolved
Hide resolved
...ava/org/elasticsearch/xpack/security/rest/action/apikey/RestInvalidateApiKeyActionTests.java
Outdated
Show resolved
Hide resolved
...ava/org/elasticsearch/xpack/security/rest/action/apikey/RestInvalidateApiKeyActionTests.java
Show resolved
Hide resolved
.../test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestGetApiKeyActionTests.java
Outdated
Show resolved
Hide resolved
.../test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestGetApiKeyActionTests.java
Show resolved
Hide resolved
@elasticmachine run elasticsearch-ci/1 |
@bizybot - PR looks good, we had to patch the REST API specification to add the "owner" flag. I will open an issue for this. |
This commit adds a flag that can be set to
true
if theAPI key request (Get or Invalidate) is for the API keys owned
by the currently authenticated user only.
These only interface changes and once the actual cluster privilege
manage_own_api_key
is done, we will have another PR to make theinterface work.
The Get API behavior would be:
when
owner
is set totrue
GET /_security/api_key?id=abcd&owner=true
the Rest controller will take care of setting
realm_name
andusername
to thevalues for the authenticated user and only return results if it finds one owned by
the currently authenticated user.
when
owner
is set tofalse
(default)GET /_security/api_key?id=abcd
the Rest controller will assume
realm_name
andusername
to be unspecifiedmeaning it will try to search for the API key across users and realms.
This will fail if the user has only
manage_own_api_key
privilege.Similarly, for Delete API key behavior:
when
owner
is set totrue
DELETE /_security/api_key
the Rest controller will take care of setting
realm_name
andusername
to the valuesfor the authenticated user and only invalidate key if it finds one owned by
the currently authenticated user.
when
my_api_keys_only
is set tofalse
(default)DELETE /_security/api_key
the Rest controller will assume
realm_name
andusername
to be unspecified meaning it willtry to search for the API key across users and realms. This will fail if the user has only
manage_own_api_key
privilege.TODO:
my_api_keys_only
in a separate PRRelates #40031