Get API key information

  • GET /_security/api_key
Auth

Retrieves information for one or more API keys. NOTE: If you have only the manage_own_api_key privilege, this API returns only the API keys that you own. If you have read_security, manage_api_key or greater privileges (including manage_security), this API returns all API keys regardless of ownership.

Required privileges

Cluster privileges manage_own_api_key read_security

Query parameters

id string

An API key id. This parameter cannot be used with any of name, realm_name or username.

name string

An API key name. This parameter cannot be used with any of id, realm_name or username. It supports prefix search with wildcard.

owner boolean · default: false

A boolean flag that can be used to query API keys owned by the currently authenticated user. The realm_name or username parameters cannot be specified when this parameter is set to true as they are assumed to be the currently authenticated ones.

realm_name string

The name of an authentication realm. This parameter cannot be used with either id or name or when owner flag is set to true.

username string

The username of a user. This parameter cannot be used with either id or name or when owner flag is set to true.

with_limited_by boolean · default: false

Return the snapshot of the owner user's role descriptors associated with the API key. An API key's actual permission is the intersection of its assigned role descriptors and the owner user's role descriptors.

active_only boolean · default: false

A boolean flag that can be used to query API keys that are currently active. An API key is considered active if it is neither invalidated, nor expired at query time. You can specify this together with other parameters such as owner or name. If active_only is false, the response will include both active and inactive (expired or invalidated) keys.

with_profile_uid boolean · default: false

Determines whether to also retrieve the profile uid, for the API key owner principal, if it exists.

Response

application/json
api_keys object[] required
id string required

Id for the API key

name string required

Name of the API key.

type enum required

The type of the API key (e.g. rest or cross_cluster).

Values: rest cross_cluster
creation number required

Creation time for the API key in milliseconds.

expiration number

Expiration time for the API key in milliseconds.

invalidated boolean required

Invalidation status for the API key. If the key has been invalidated, it has a value of true. Otherwise, it is false.

invalidation number

If the key has been invalidated, invalidation time in milliseconds.

username string required

Principal for which this API key was created

realm string required

Realm name of the principal for which this API key was created.

realm_type string

Realm type of the principal for which this API key was created

metadata object required

Metadata of the API key

role_descriptors map string to object

The role descriptors assigned to this API key when it was created or last updated. An empty role descriptor means the API key inherits the owner user’s permissions.

<string> object
cluster union anyOf[]

A list of cluster privileges. These privileges define the cluster level actions that API keys are able to execute.

Values: all cancel_task manage manage_api_key manage_behavioral_analytics manage_enrich manage_esql manage_index_templates manage_inference manage_ingest_pipelines manage_logstash_pipelines manage_ml
indices object[]

A list of indices permissions entries.

field_security object

The document fields that the owners of the role have read access to.

except union oneOf
One of: string[] or string
grant union oneOf
One of: string[] or string
names union string | string[] required

A list of indices (or index name patterns) to which the permissions in this entry apply.

privileges union anyOf[] required

The index level privileges that owners of the role have on the specified indices.

Values: all auto_configure create create_doc create_index create_view delete delete_index delete_view index maintenance manage manage_data_stream_lifecycle manage_view monitor none read read_view_metadata view_index_metadata write
query union oneOf

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.

One of:
applications object[]

A list of application privilege entries

application string required

The name of the application to which this entry applies.

privileges string[] required

A list of strings, where each element is the name of an application privilege or action.

resources string[] required

A list resources to which the privileges are applied.

metadata object

Optional meta-data. Within the metadata object, keys that begin with _ are reserved for system usage.

run_as string[]

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_as field, but a non-empty list will be rejected.

description string

Optional description of the role descriptor

restriction object

Restriction for when the role descriptor is allowed to be effective.

workflows union anyOf[] required

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_metadata map string to object
limited_by string to object[]

The owner user’s permissions associated with the API key. It is a point-in-time snapshot captured at creation and subsequent updates. An API key’s effective permissions are an intersection of its assigned privileges and the owner user’s permissions.

access object

The access granted to cross-cluster API keys. The access is composed of permissions for cross cluster search and cross cluster replication. At least one of them must be specified. When specified, the new access assignment fully replaces the previously assigned access.

replication object[]

A list of indices permission entries for cross-cluster replication.

names union string | string[] required

A list of indices (or index name patterns) to which the permissions in this entry apply.

allow_restricted_indices boolean · default: false

This needs to be set to true if the patterns in the names field should cover system indices.

A list of indices permission entries for cross-cluster search.

field_security object

The document fields that the owners of the role have read access to.

except union oneOf
One of: string[] or string
grant union oneOf
One of: string[] or string
names union string | string[] required

A list of indices (or index name patterns) to which the permissions in this entry apply.

query union oneOf

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.

One of:
profile_uid string

The profile uid for the API key owner principal, if requested and if it exists

_sort union[]

Sorting values when using the sort parameter with the security.query_api_keys API.