Get API key information
Generally available; Added in 6.7.0
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 authorization
- Cluster privileges:
manage_own_api_key
,read_security
Query parameters
-
An API key id. This parameter cannot be used with any of
name
,realm_name
orusername
. -
An API key name. This parameter cannot be used with any of
id
,realm_name
orusername
. It supports prefix search with wildcard. -
A boolean flag that can be used to query API keys owned by the currently authenticated user. The
realm_name
orusername
parameters cannot be specified when this parameter is set totrue
as they are assumed to be the currently authenticated ones. -
The name of an authentication realm. This parameter cannot be used with either
id
orname
or whenowner
flag is set totrue
. -
The username of a user. This parameter cannot be used with either
id
orname
or whenowner
flag is set totrue
. -
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.
-
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
orname
. Ifactive_only
is false, the response will include both active and inactive (expired or invalidated) keys. -
Determines whether to also retrieve the profile uid, for the API key owner principal, if it exists.
GET /_security/api_key?username=myuser&realm_name=native1
resp = client.security.get_api_key(
username="myuser",
realm_name="native1",
)
const response = await client.security.getApiKey({
username: "myuser",
realm_name: "native1",
});
response = client.security.get_api_key(
username: "myuser",
realm_name: "native1"
)
$resp = $client->security()->getApiKey([
"username" => "myuser",
"realm_name" => "native1",
]);
curl -X GET -H "Authorization: ApiKey $ELASTIC_API_KEY" "$ELASTICSEARCH_URL/_security/api_key?username=myuser&realm_name=native1"
{
"api_keys": [
{
"id": "VuaCfGcBCdbkQm-e5aOx",
"name": "my-api-key",
"creation": 1548550550158,
"expiration": 1548551550158,
"invalidated": false,
"username": "myuser",
"realm": "native1",
"realm_type": "native",
"metadata": {
"application": "myapp"
},
"role_descriptors": { },
"limited_by": [
{
"role-power-user": {
"cluster": [
"monitor"
],
"indices": [
{
"names": [
"*"
],
"privileges": [
"read"
],
"allow_restricted_indices": false
}
],
"applications": [ ],
"run_as": [ ],
"metadata": { },
"transient_metadata": {
"enabled": true
}
}
}
]
}
]
}
{
"api_keys": [
{
"id": "0GF5GXsBCXxz2eDxWwFN",
"name": "hadoop_myuser_key",
"creation": 1548550550158,
"expiration": 1548551550158,
"invalidated": false,
"username": "myuser",
"realm": "native1",
"realm_type": "native",
"metadata": {
"application": "myapp"
},
"role_descriptors": {
"role-a": {
"cluster": [
"monitor"
],
"indices": [
{
"names": [
"index-a"
],
"privileges": [
"read"
],
"allow_restricted_indices": false
}
],
"applications": [ ],
"run_as": [ ],
"metadata": { },
"transient_metadata": {
"enabled": true
}
}
}
},
{
"id": "6wHJmcQpReKBa42EHV5SBw",
"name": "api-key-name-2",
"creation": 1548550550158,
"invalidated": false,
"username": "user-y",
"realm": "realm-2",
"metadata": {},
"role_descriptors": { }
}
]
}