Invalidate API keys
Generally available
This API invalidates API keys created by the create API key or grant API key APIs. Invalidated API keys fail authentication, but they can still be viewed using the get API key information and query API key information APIs, for at least the configured retention period, until they are automatically deleted.
To use this API, you must have at least the manage_security, manage_api_key, or manage_own_api_key cluster privileges.
The manage_security privilege allows deleting any API key, including both REST and cross cluster API keys.
The manage_api_key privilege allows deleting any REST API key, but not cross cluster API keys.
The manage_own_api_key only allows deleting REST API keys that are owned by the user.
In addition, with the manage_own_api_key privilege, an invalidation request must be issued in one of the three formats:
- Set the parameter
owner=true. - Or, set both
usernameandrealm_nameto match the user's identity. - Or, if the request is issued by an API key, that is to say an API key invalidates itself, specify its ID in the
idsfield.
Required authorization
- Cluster privileges:
manage_api_key,manage_own_api_key
Body
Required
-
A list of API key ids. This parameter cannot be used with any of
name,realm_name, orusername. -
An API key name. This parameter cannot be used with any of
ids,realm_nameorusername. -
Query API keys owned by the currently authenticated user. The
realm_nameorusernameparameters cannot be specified when this parameter is set totrueas they are assumed to be the currently authenticated ones.NOTE: At least one of
ids,name,username, andrealm_namemust be specified ifownerisfalse.Default value is
false. -
The name of an authentication realm. This parameter cannot be used with either
idsorname, or whenownerflag is set totrue. -
The username of a user. This parameter cannot be used with either
idsornameor whenownerflag is set totrue.
DELETE /_security/api_key
{
"ids" : [ "VuaCfGcBCdbkQm-e5aOx" ]
}
resp = client.security.invalidate_api_key(
ids=[
"VuaCfGcBCdbkQm-e5aOx"
],
)
const response = await client.security.invalidateApiKey({
ids: ["VuaCfGcBCdbkQm-e5aOx"],
});
response = client.security.invalidate_api_key(
body: {
"ids": [
"VuaCfGcBCdbkQm-e5aOx"
]
}
)
$resp = $client->security()->invalidateApiKey([
"body" => [
"ids" => array(
"VuaCfGcBCdbkQm-e5aOx",
),
],
]);
curl -X DELETE -H "Authorization: ApiKey $ELASTIC_API_KEY" -H "Content-Type: application/json" -d '{"ids":["VuaCfGcBCdbkQm-e5aOx"]}' "$ELASTICSEARCH_URL/_security/api_key"
client.security().invalidateApiKey(i -> i
.ids("VuaCfGcBCdbkQm-e5aOx")
);
{
"ids" : [ "VuaCfGcBCdbkQm-e5aOx" ]
}
{
"name" : "my-api-key"
}
{
"realm_name" : "native1"
}
{
"username" : "myuser"
}
{
"ids" : ["VuaCfGcBCdbkQm-e5aOx"],
"owner" : "true"
}
{
"username" : "myuser",
"realm_name" : "native1"
}
{
"invalidated_api_keys": [
"api-key-id-1"
],
"previously_invalidated_api_keys": [
"api-key-id-2",
"api-key-id-3"
],
"error_count": 2,
"error_details": [
{
"type": "exception",
"reason": "error occurred while invalidating api keys",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "invalid api key id"
}
},
{
"type": "exception",
"reason": "error occurred while invalidating api keys",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "invalid api key id"
}
}
]
}