Create an API key
- POST also PUT /_security/api_key
Create an API key for access without requiring basic authentication.
IMPORTANT: If the credential that is used to authenticate this request is an API key, the derived API key cannot have any privileges. If you specify privileges, the API returns an error.
A successful request 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.
NOTE: By default, API keys never expire. You can specify expiration information when you create the API keys.
The API keys are created by the Elasticsearch API key service, which is automatically enabled. To configure or turn off the API key service, refer to API key service setting documentation.
- Cluster privileges:
manage_own_api_key
Query Parameters
-
refreshRefresh If
true(the default) then refresh the affected shards to make this operation visible to search, ifwait_forthen wait for a refresh to make this operation visible to search, iffalsethen do nothing with refreshes.-
Values:
truefalsewait_for
Request
-
expirationstring Duration -
The expiration time for the API key. By default, API keys never expire.
-
namestring Name -
A name for the API key.
-
role_descriptorsmap string to RoleDescriptor -
An array of role descriptors for this API key. When it is not specified or it is an empty array, the API key will have a point in time snapshot of permissions of the authenticated user. If you supply role descriptors, the resultant permissions are an intersection of API keys permissions and the authenticated user's permissions thereby limiting the access scope for API keys. The structure of role descriptor is the same as the request for the create role API. For more details, refer to the create or update roles API.
NOTE: Due to the way in which this permission intersection is calculated, it is not possible to create an API key that is a child of another API key, unless the derived key is created without any privileges. In this case, you must explicitly specify a role descriptor with no privileges. The derived API key can be used for authentication; it will not have authority to call Elasticsearch APIs.
- Reference
-
<string>RoleDescriptor -
clusterClusterPrivilege -
A list of cluster privileges. These privileges define the cluster level actions that API keys are able to execute.
-
Values:
allcancel_taskclone_api_keycreate_snapshotcross_cluster_replicationcross_cluster_searchdelegate_pkigrant_api_keymanagemanage_api_keymanage_autoscalingmanage_behavioral_analyticsmanage_ccrmanage_data_frame_transformsmanage_data_stream_global_retentionmanage_enrichmanage_esqlmanage_ilmmanage_index_templatesmanage_inferencemanage_ingest_pipelinesmanage_logstash_pipelinesmanage_mlmanage_oidcmanage_own_api_keymanage_pipelinemanage_reindexmanage_rollupmanage_samlmanage_search_applicationmanage_search_query_rulesmanage_search_synonymsmanage_securitymanage_service_accountmanage_slmmanage_tokenmanage_transformmanage_user_profilemanage_watchermonitormonitor_data_frame_transformsmonitor_data_stream_global_retentionmonitor_enrichmonitor_esqlmonitor_inferencemonitor_mlmonitor_reindexmonitor_rollupmonitor_snapshotmonitor_statsmonitor_text_structuremonitor_transformmonitor_watchernonepost_behavioral_analytics_eventread_ccrread_fleet_secretsread_ilmread_pipelineread_securityread_slmtransport_clientwrite_connector_secretswrite_fleet_secrets -
indicesIndicesPrivileges -
A list of indices permissions entries.
-
field_securityFieldSecurity -
The document fields that the owners of the role have read access to.
- Reference
-
namesIndexName | IndexNamerequired -
A list of indices (or index name patterns) to which the permissions in this entry apply.
-
privilegesIndexPrivilegerequired -
The index level privileges that owners of the role have on the specified indices.
-
Values:
allauto_configurecreatecreate_doccreate_indexcreate_viewcross_cluster_replicationcross_cluster_replication_internaldeletedelete_indexdelete_viewindexmaintenancemanagemanage_data_stream_lifecyclemanage_follow_indexmanage_ilmmanage_leader_indexmanage_viewmonitornonereadread_cross_clusterread_view_metadataview_index_metadatawrite -
queryIndicesPrivilegesQuery -
A search query that defines the documents the owners of the role have access to. A document within the specified indices must match this query for it to be accessible by the owners of the role.
-
allow_restricted_indicesboolean · default: false -
Set to
trueif using wildcard or regular expressions for patterns that cover restricted indices. Implicitly, restricted indices have limited privileges that can cause pattern tests to fail. If restricted indices are explicitly included in thenameslist, Elasticsearch checks privileges against these indices regardless of the value set forallow_restricted_indices. -
remote_indicesRemoteIndicesPrivileges -
A list of indices permissions for remote clusters.
-
clustersstring Namesrequired -
A list of cluster aliases to which the permissions in this entry apply.
-
field_securityFieldSecurity -
The document fields that the owners of the role have read access to.
- Reference
-
namesIndexName | IndexNamerequired -
A list of indices (or index name patterns) to which the permissions in this entry apply.
-
privilegesIndexPrivilegerequired -
The index level privileges that owners of the role have on the specified indices.
-
Values:
allauto_configurecreatecreate_doccreate_indexcreate_viewcross_cluster_replicationcross_cluster_replication_internaldeletedelete_indexdelete_viewindexmaintenancemanagemanage_data_stream_lifecyclemanage_follow_indexmanage_ilmmanage_leader_indexmanage_viewmonitornonereadread_cross_clusterread_view_metadataview_index_metadatawrite -
queryIndicesPrivilegesQuery -
A search query that defines the documents the owners of the role have access to. A document within the specified indices must match this query for it to be accessible by the owners of the role.
-
allow_restricted_indicesboolean · default: false -
Set to
trueif using wildcard or regular expressions for patterns that cover restricted indices. Implicitly, restricted indices have limited privileges that can cause pattern tests to fail. If restricted indices are explicitly included in thenameslist, Elasticsearch checks privileges against these indices regardless of the value set forallow_restricted_indices. -
remote_clusterRemoteClusterPrivileges -
A list of cluster permissions for remote clusters. NOTE: This is limited a subset of the cluster permissions.
-
clustersstring Namesrequired -
A list of cluster aliases to which the permissions in this entry apply.
-
privilegesRemoteClusterPrivilegerequired -
The cluster level privileges that owners of the role have on the remote cluster.
-
Values:
monitor_enrichmonitor_stats -
globalGlobalPrivilege -
An object defining global privileges. A global privilege is a form of cluster privilege that is request-aware.
-
applicationApplicationGlobalUserPrivileges -
manageManageUserPrivilegesrequired -
applicationsstringrequired -
data_sourceDataSourcePrivileges -
A list of data source privilege entries, used to grant access to ES|QL data sources.
-
namesstringrequired -
A list of data source names or wildcard patterns to which the permissions in this entry apply.
-
privilegesDataSourcePrivilegerequired -
The data source privileges that owners of the role have for the specified data sources.
Supported values include:
create: Grants privilege to create a data source with a matching name.delete: Grants privilege to delete a data source with a matching name.read_metadata: Grants privilege to read a data source's metadata.read: Grants privilege to attach a dataset to a data source with a matching name.manage: Grants all data source privileges, includingcreate,delete,read, andread_metadata.
-
Values:
createdeleteread_metadatareadmanage -
applicationsApplicationPrivileges -
A list of application privilege entries
-
applicationstringrequired -
The name of the application to which this entry applies.
-
privilegesstringrequired -
A list of strings, where each element is the name of an application privilege or action.
-
resourcesstringrequired -
A list resources to which the privileges are applied.
-
metadataMetadata -
Optional meta-data. Within the metadata object, keys that begin with
_are reserved for system usage. -
run_asstring -
A list of users that the API keys can impersonate. NOTE: In Elastic Cloud Serverless, the run-as feature is disabled. For API compatibility, you can still specify an empty
run_asfield, but a non-empty list will be rejected. - Reference
-
descriptionstring -
Optional description of the role descriptor
-
restrictionRestriction -
Restriction for when the role descriptor is allowed to be effective.
-
workflowsRestrictionWorkflowrequired -
A list of workflows to which the API key is restricted. NOTE: In order to use a role restriction, an API key must be created with a single role descriptor.
-
Values:
search_application_query -
transient_metadatamap string to object -
metadataMetadata -
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.
Response
-
api_keystringrequired -
Generated API key.
-
expirationnumber -
Expiration in milliseconds for the API key.
-
idstring Idrequired -
Unique ID for this API key.
-
namestring Namerequired -
Specifies the name for this API key.
-
encodedstringrequired -
API key credentials which is the base64-encoding of the UTF-8 representation of
idandapi_keyjoined by a colon (:).