AuthThe Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats.AvailabilityGenerally available since 7.9This functionality is generally available and ready for production usage.Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments.This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
Create an API key on behalf of another user.
This API is similar to the create API keys API, however it creates the API key for a user that is different than the user that runs the API.
The caller must have authentication credentials for the user on whose behalf the API key will be created.
It is not possible to use this API to create an API key without that user's credentials.
The supported user authentication credential types are:
username and password
Elasticsearch access tokens
JWTs
service account tokens of user-managed service accounts
The user, for whom the authentication credentials is provided, can optionally "run as" (impersonate) another user.
In this case, the API key will be created on behalf of the impersonated user.
Run as is not supported with the _user_managed_service_account grant type.
This API is intended be used by applications that need to create and manage API keys for end users, but cannot guarantee that those users have permission to create API keys on their own behalf.
The API keys are created by the Elasticsearch API key service, which is automatically enabled.
A successful grant API key API call returns a JSON structure that contains the API key, its unique id, and its name.
If applicable, it also returns expiration information for the API key in milliseconds.
By default, API keys never expire. You can specify expiration information when you create the API keys.
If 'true', Elasticsearch refreshes the affected shards to make this operation
visible to search.
If 'wait_for', it waits for a refresh to make this operation visible to search.
If 'false', nothing is done with refreshes.
Expiration time for the API key. By default, API keys never expire.
role_descriptorsuniononeOf
The role descriptors for this API key.
When it is not specified or is an empty array, the API key has a point in time snapshot of permissions of the specified user or access token.
If you supply role descriptors, the resultant permissions are an intersection of API keys permissions and the permissions of the user or access token.
map string to objector[] map string to object
metadataobject
Arbitrary metadata that you want to associate with the API key.
It supports nested data structure.
Within the metadata object, keys beginning with _ are reserved for system usage.
grant_typeenumrequired
The type of grant. Supported grant types are: access_token, password, and _user_managed_service_account.
Supported values include:
access_token
password
_user_managed_service_account: In this type of grant, you must supply a service account token of a user-managed service account in the service_account_token parameter.
The API key is owned by the service account and is limited by the roles assigned to it.
The service account token is authenticated on every grant, so a disabled account or an invalidated token is rejected.
Tokens that belong to built-in (elastic/*) service accounts are rejected.
The user's access token.
If you specify the access_token grant type, this parameter is required.
It is not valid with other grant types.
client_authenticationobjectThe Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats.AvailabilityGenerally available since 8.12This functionality is generally available and ready for production usage.Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments.This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
The client authentication for a JWT that requires it, which is what is normally sent in the ES-Client-Authentication request header.
It is valid only with the access_token grant type, when the access token is a JWT.
schemeenumrequired
The client authentication scheme.
Supported values include:
SharedSecret: The client authenticates with the shared secret configured for the JWT realm.
Values:SharedSecret
valuestringrequired
The client authentication value, which is what normally follows the scheme in the ES-Client-Authentication request header.
service_account_tokenstringThe Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats.AvailabilityPlannedWe plan to add this functionality in a future Elastic Stack update. Subject to changes.Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments.This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
The service account token of a user-managed service account, as returned by the create service account token API.
If you specify the _user_managed_service_account grant type, this parameter is required.
It is not valid with other grant types.
usernamestring
The user name that identifies the user.
If you specify the password grant type, this parameter is required.
It is not valid with other grant types.
passwordstring
The user's password.
If you specify the password grant type, this parameter is required.
It is not valid with other grant types.
run_asstring
The name of the user to be impersonated.
It is not valid with the _user_managed_service_account grant type.