-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[DOCS] Update API key API #88499
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
Merged
Merged
[DOCS] Update API key API #88499
Changes from all commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
a8e5cc5
WIP docs
n1v0lg 52c812b
Merge branch 'master' into update-api-keys-docs
n1v0lg c41a996
WIP
n1v0lg ee98c66
More work on docs
n1v0lg 692f853
Merge branch 'master' into update-api-keys-docs
n1v0lg 69a0543
Awkward but complete rd description
n1v0lg 00ddad6
Metadata
n1v0lg 3ae3d52
Tweaks
n1v0lg faeb3f3
Response
n1v0lg b6e3c9a
Example
n1v0lg 228a330
More examples
n1v0lg 2553149
Attempt to simplify role descriptor blurb
n1v0lg 90f2937
Nits
n1v0lg 1b41f24
Complete but long
n1v0lg baa15ec
Future tense
n1v0lg 6fe367b
Minimalist
n1v0lg cc58012
Merge branch 'master' into update-api-keys-docs
n1v0lg 4987848
Tweaks
n1v0lg 2ab89c9
More examples
n1v0lg 4ac59d7
Standardize privs
n1v0lg 92c6f17
Mention grant API
n1v0lg 66dfb13
Better order
n1v0lg 62c643c
Move some things around
n1v0lg 6eb56ac
Typo
n1v0lg 728fedf
Nit
n1v0lg ab157e3
More tweaks
n1v0lg 1bc75ca
Blurb
n1v0lg 8aead08
Reference
n1v0lg 57a8f83
Skip tests for now
n1v0lg 695eb0b
Fix ref
n1v0lg 149c6d8
Merge branch 'master' into update-api-keys-docs
n1v0lg 21901a4
Add tests
n1v0lg eea228c
Shorter blurb
n1v0lg 10d8d11
More tweaks
n1v0lg 751ce51
Better blurb
n1v0lg d1bfda4
Typo
n1v0lg ddc4e38
Fix tests
n1v0lg 3afa218
Merge branch 'master' into update-api-keys-docs
n1v0lg cf5f53b
Address comments
n1v0lg 991b3fc
Tweak callout
n1v0lg 35b9b59
Use owner user consistently
n1v0lg c10ac09
Attempt at role desc reword
n1v0lg 5db427a
Merge branch 'master' into update-api-keys-docs
n1v0lg bf85c93
Nits
n1v0lg 39ba1f9
Tweaks
n1v0lg aa8bfec
More tweaks in examples
n1v0lg d7fa785
Shorter
n1v0lg 7d9269f
Even shorter
n1v0lg 349d0dd
Less awkward sentence
n1v0lg 71d0715
Another stab
n1v0lg 17defe4
Last mod
n1v0lg d2d0933
Review comments
n1v0lg b95fe55
Merge branch 'master' into update-api-keys-docs
n1v0lg f843a23
Merge branch 'master' into update-api-keys-docs
elasticmachine e9c8fc6
Better wording around opt req body
n1v0lg fcde49a
Better callout
n1v0lg 6e85f05
Link
n1v0lg 1efa567
Simplify
n1v0lg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
274 changes: 272 additions & 2 deletions
274
x-pack/docs/en/rest-api/security/update-api-key.asciidoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,275 @@ | ||
| [role="xpack"] | ||
| [[security-api-update-api-key]] | ||
| === Update API key information API | ||
| === Update API key API | ||
|
|
||
| coming::[8.4.0] | ||
| ++++ | ||
| <titleabbrev>Update API key</titleabbrev> | ||
| ++++ | ||
|
|
||
| [[security-api-update-api-key-request]] | ||
| ==== {api-request-title} | ||
|
|
||
| `PUT /_security/api_key/<id>` | ||
|
|
||
| [[security-api-update-api-key-prereqs]] | ||
| ==== {api-prereq-title} | ||
|
|
||
| * To use this API, you must have at least the `manage_own_api_key` cluster privilege. | ||
| Users can only update API keys that they created or that were granted to them. | ||
| To update another user's API key, use the <<run-as-privilege,`run_as` feature>> | ||
| to submit a request on behalf of another user. | ||
|
|
||
| IMPORTANT: It's not possible to use an API key as the authentication credential for this API. | ||
| To update an API key, the owner user's credentials are required. | ||
|
|
||
| [[security-api-update-api-key-desc]] | ||
| ==== {api-description-title} | ||
|
|
||
| Use this API to update API keys created by the <<security-api-create-api-key,create API Key>> or <<security-api-grant-api-key,grant API Key>> APIs. | ||
| It's not possible to update expired API keys, or API keys that have been invalidated by <<security-api-invalidate-api-key,invalidate API Key>>. | ||
|
|
||
| This API supports updates to an API key's access scope and metadata. | ||
| The access scope of an API key is derived from the <<security-api-update-api-key-api-key-role-descriptors,`role_descriptors`>> you specify in the request, and a snapshot of the owner user's permissions at the time of the request. | ||
| The snapshot of the owner's permissions is updated automatically on every call. | ||
|
|
||
| [IMPORTANT] | ||
| ==== | ||
| If you don't specify <<security-api-update-api-key-api-key-role-descriptors,`role_descriptors`>> in the request, a call to this API might still change the API key's access scope. | ||
| This change can occur if the owner user's permissions have changed since the API key was created or last modified. | ||
| ==== | ||
|
|
||
| [[security-api-update-api-key-path-params]] | ||
| ==== {api-path-parms-title} | ||
|
|
||
| `id`:: | ||
| (Required, string) The ID of the API key to update. | ||
|
|
||
| [[security-api-update-api-key-request-body]] | ||
| ==== {api-request-body-title} | ||
|
|
||
| You can specify the following parameters in the request body, which is optional. | ||
|
|
||
| [[security-api-update-api-key-api-key-role-descriptors]] | ||
| `role_descriptors`:: | ||
| (Optional, object) The role descriptors to assign to this API key. | ||
| The API key's effective permissions are an intersection of its assigned privileges and the point in time snapshot of permissions of the owner user. | ||
| If no privileges are assigned, the API key inherits the owner user's full permissions. | ||
| You can assign new privileges to the API key by specifying them in this parameter. | ||
| To remove assigned privileges, you can supply an empty `role_descriptors` parameter. | ||
| The snapshot of the owner's permissions is always updated, whether you supply the `role_descriptors` parameter or not. | ||
| The structure of a role descriptor is the same as the request for the <<security-api-put-role, create or update roles API>>. | ||
|
|
||
| `metadata`:: | ||
| (Optional, object) Arbitrary metadata that you want to associate with the API key. | ||
| It supports nested data structure. | ||
| Within the `metadata` object, top-level keys beginning with `_` are reserved for system usage. | ||
| When specified, this fully replaces metadata previously associated with the API key. | ||
|
|
||
| [[security-api-update-api-key-response-body]] | ||
| ==== {api-response-body-title} | ||
|
|
||
| `updated`:: | ||
| (boolean) If `true`, the API key was updated. | ||
| If `false`, the API key didn't change because no change was detected. | ||
|
|
||
| [[security-api-update-api-key-example]] | ||
| ==== {api-examples-title} | ||
|
|
||
| If you create an API key as follows: | ||
|
|
||
| [source,console] | ||
| ------------------------------------------------------------ | ||
| POST /_security/api_key | ||
| { | ||
| "name": "my-api-key", | ||
| "role_descriptors": { | ||
| "role-a": { | ||
| "cluster": ["all"], | ||
| "index": [ | ||
| { | ||
| "names": ["index-a*"], | ||
| "privileges": ["read"] | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "metadata": { | ||
| "application": "my-application", | ||
| "environment": { | ||
| "level": 1, | ||
| "trusted": true, | ||
| "tags": ["dev", "staging"] | ||
| } | ||
| } | ||
| } | ||
| ------------------------------------------------------------ | ||
|
|
||
| A successful call returns a JSON structure that provides API key information. | ||
| For example: | ||
|
|
||
| [source,console-result] | ||
| -------------------------------------------------- | ||
| { | ||
| "id": "VuaCfGcBCdbkQm-e5aOx", | ||
| "name": "my-api-key", | ||
| "api_key": "ui2lp2axTNmsyakw9tvNnw", | ||
| "encoded": "VnVhQ2ZHY0JDZGJrUW0tZTVhT3g6dWkybHAyYXhUTm1zeWFrdzl0dk5udw==" | ||
| } | ||
| -------------------------------------------------- | ||
| // TESTRESPONSE[s/VuaCfGcBCdbkQm-e5aOx/$body.id/] | ||
| // TESTRESPONSE[s/ui2lp2axTNmsyakw9tvNnw/$body.api_key/] | ||
| // TESTRESPONSE[s/VnVhQ2ZHY0JDZGJrUW0tZTVhT3g6dWkybHAyYXhUTm1zeWFrdzl0dk5udw==/$body.encoded/] | ||
|
|
||
| For the examples below, assume that the owner user's permissions are: | ||
|
|
||
| [[security-api-update-api-key-examples-user-permissions]] | ||
| [source,js] | ||
| -------------------------------------------------- | ||
| { | ||
| "cluster": ["all"], | ||
| "index": [ | ||
| { | ||
| "names": ["*"], | ||
| "privileges": ["all"] | ||
| } | ||
| ] | ||
| } | ||
| -------------------------------------------------- | ||
| // NOTCONSOLE | ||
|
|
||
| The following example updates the API key created above, assigning it new role descriptors and metadata: | ||
|
|
||
| [source,console] | ||
| ---- | ||
| PUT /_security/api_key/VuaCfGcBCdbkQm-e5aOx | ||
| { | ||
| "role_descriptors": { | ||
| "role-a": { | ||
| "index": [ | ||
| { | ||
| "names": ["*"], | ||
| "privileges": ["write"] | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "metadata": { | ||
| "environment": { | ||
| "level": 2, | ||
| "trusted": true, | ||
| "tags": ["production"] | ||
| } | ||
| } | ||
| } | ||
| ---- | ||
| // TEST[s/VuaCfGcBCdbkQm-e5aOx/\${body.id}/] | ||
n1v0lg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // TEST[continued] | ||
|
|
||
| A successful call returns a JSON structure indicating that the API key was updated: | ||
|
|
||
| [source,console-result] | ||
| ---- | ||
| { | ||
| "updated": true | ||
| } | ||
| ---- | ||
|
|
||
| The API key's effective permissions after the update will be the intersection of the supplied role descriptors and the <<security-api-update-api-key-examples-user-permissions, owner user's permissions>>: | ||
|
|
||
| [source,js] | ||
| -------------------------------------------------- | ||
| { | ||
| "index": [ | ||
| { | ||
| "names": ["*"], | ||
| "privileges": ["write"] | ||
| } | ||
| ] | ||
| } | ||
| -------------------------------------------------- | ||
| // NOTCONSOLE | ||
|
|
||
| The following example removes the API key's previously assigned permissions. | ||
|
|
||
| [source,console] | ||
| ---- | ||
| PUT /_security/api_key/VuaCfGcBCdbkQm-e5aOx | ||
| { | ||
| "role_descriptors": {} | ||
| } | ||
| ---- | ||
| // TEST[skip:api key id not available anymore] | ||
n1v0lg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Which returns the response: | ||
|
|
||
| [source,console-result] | ||
| ---- | ||
| { | ||
| "updated": true | ||
| } | ||
| ---- | ||
|
|
||
| The API key's effective permissions after the update will the same as the <<security-api-update-api-key-examples-user-permissions, owner user's>>: | ||
|
|
||
| [source,js] | ||
| -------------------------------------------------- | ||
| { | ||
| "cluster": ["all"], | ||
| "index": [ | ||
| { | ||
| "names": ["*"], | ||
| "privileges": ["all"] | ||
| } | ||
| ] | ||
| } | ||
| -------------------------------------------------- | ||
| // NOTCONSOLE | ||
|
|
||
| For the next example, assume that the owner user's permissions have changed from <<security-api-update-api-key-examples-user-permissions, the original permissions>> to: | ||
|
|
||
| [source,js] | ||
| -------------------------------------------------- | ||
| { | ||
| "cluster": ["manage_security"], | ||
| "index": [ | ||
| { | ||
| "names": ["*"], | ||
| "privileges": ["read"] | ||
| } | ||
| ] | ||
| } | ||
| -------------------------------------------------- | ||
| // NOTCONSOLE | ||
|
|
||
| The following request auto-updates the snapshot of the user's permissions associated with the API key: | ||
|
|
||
| [source,console] | ||
| ---- | ||
| PUT /_security/api_key/VuaCfGcBCdbkQm-e5aOx | ||
| ---- | ||
| // TEST[skip:api key id not available anymore] | ||
|
|
||
| Which returns the response: | ||
|
|
||
| [source,console-result] | ||
| ---- | ||
| { | ||
| "updated": true | ||
| } | ||
| ---- | ||
|
|
||
| Resulting in the following effective permissions for the API key: | ||
|
|
||
| [source,js] | ||
| -------------------------------------------------- | ||
| { | ||
| "cluster": ["manage_security"], | ||
| "index": [ | ||
| { | ||
| "names": ["*"], | ||
| "privileges": ["read"] | ||
| } | ||
| ] | ||
| } | ||
| -------------------------------------------------- | ||
| // NOTCONSOLE | ||
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.
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.
We can be more explicit here. Instead of saying "is derived", we can just say "is an intersection of ...".
Uh oh!
There was an error while loading. Please reload this page.
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 don't think "intersection of" is technically correct here without the disclaimer that when
role_descriptorsis empty (i.e., not assigned) it's not the intersection. I went with "derived" because it side-steps that problem, and references the role desc section where we accurately describe how the permissions are derived.