REST API changes for manage-own-api-key privilege#44936
REST API changes for manage-own-api-key privilege#44936bizybot merged 13 commits intoelastic:manage-own-api-key-privilegefrom
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 |
albertzaharovits
left a comment
There was a problem hiding this comment.
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. |
tvernum
left a comment
There was a problem hiding this comment.
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 <tim@adjective.org>
…security/action/GetApiKeyRequestTests.java Co-Authored-By: Tim Vernum <tim@adjective.org>
…security/action/GetApiKeyRequestTests.java Co-Authored-By: Tim Vernum <tim@adjective.org>
…security/action/GetApiKeyRequestTests.java Co-Authored-By: Tim Vernum <tim@adjective.org>
|
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
trueif 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_keyis done, we will have another PR to make theinterface work.
The Get API behavior would be:
when
owneris set totrueGET /_security/api_key?id=abcd&owner=truethe Rest controller will take care of setting
realm_nameandusernameto thevalues for the authenticated user and only return results if it finds one owned by
the currently authenticated user.
when
owneris set tofalse(default)GET /_security/api_key?id=abcdthe Rest controller will assume
realm_nameandusernameto 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_keyprivilege.Similarly, for Delete API key behavior:
when
owneris set totrueDELETE /_security/api_keythe Rest controller will take care of setting
realm_nameandusernameto the valuesfor the authenticated user and only invalidate key if it finds one owned by
the currently authenticated user.
when
my_api_keys_onlyis set tofalse(default)DELETE /_security/api_keythe Rest controller will assume
realm_nameandusernameto 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_keyprivilege.TODO:
my_api_keys_onlyin a separate PRRelates #40031