2019-02-04 22:21:57 -05:00
|
|
|
[role="xpack"]
|
|
|
|
[[security-api-get-api-key]]
|
2019-03-19 14:00:42 -04:00
|
|
|
=== Get API key information API
|
2019-02-04 22:21:57 -05:00
|
|
|
++++
|
|
|
|
<titleabbrev>Get API key information</titleabbrev>
|
|
|
|
++++
|
|
|
|
|
|
|
|
Retrieves information for one or more API keys.
|
|
|
|
|
2019-08-02 13:56:05 -04:00
|
|
|
[[security-api-get-api-key-request]]
|
|
|
|
==== {api-request-title}
|
2019-02-04 22:21:57 -05:00
|
|
|
|
|
|
|
`GET /_security/api_key`
|
|
|
|
|
2019-08-02 13:56:05 -04:00
|
|
|
[[security-api-get-api-key-prereqs]]
|
|
|
|
==== {api-prereq-title}
|
2019-02-04 22:21:57 -05:00
|
|
|
|
2019-08-02 13:56:05 -04:00
|
|
|
* To use this API, you must have at least the `manage_api_key` cluster privilege.
|
2019-02-04 22:21:57 -05:00
|
|
|
|
2019-08-02 13:56:05 -04:00
|
|
|
[[security-api-get-api-key-desc]]
|
|
|
|
==== {api-description-title}
|
|
|
|
|
|
|
|
The information for the API keys created by
|
|
|
|
<<security-api-create-api-key,create API Key>> can be retrieved using this API.
|
|
|
|
|
2020-02-03 10:34:34 -05:00
|
|
|
[[security-api-get-api-key-path-params]]
|
|
|
|
==== {api-path-parms-title}
|
2019-02-04 22:21:57 -05:00
|
|
|
|
|
|
|
The following parameters can be specified in the query parameters of a GET request and
|
|
|
|
pertain to retrieving api keys:
|
|
|
|
|
2019-08-02 13:56:05 -04:00
|
|
|
`id`::
|
2020-07-14 08:06:20 -04:00
|
|
|
(Optional, string) An API key id. This parameter cannot be used with any of
|
2019-08-02 13:56:05 -04:00
|
|
|
`name`, `realm_name` or `username` are used.
|
2019-02-04 22:21:57 -05:00
|
|
|
|
2019-08-02 13:56:05 -04:00
|
|
|
`name`::
|
|
|
|
(Optional, string) An API key name. This parameter cannot be used with any of
|
2020-07-14 08:06:20 -04:00
|
|
|
`id`, `realm_name` or `username` are used. It supports prefix search with wildcard.
|
2019-02-04 22:21:57 -05:00
|
|
|
|
2019-08-02 13:56:05 -04:00
|
|
|
`realm_name`::
|
|
|
|
(Optional, string) The name of an authentication realm. This parameter cannot be
|
2019-08-27 10:44:23 -04:00
|
|
|
used with either `id` or `name` or when `owner` flag is set to `true`.
|
2019-02-04 22:21:57 -05:00
|
|
|
|
2019-08-02 13:56:05 -04:00
|
|
|
`username`::
|
|
|
|
(Optional, string) The username of a user. This parameter cannot be used with
|
2019-08-27 10:44:23 -04:00
|
|
|
either `id` or `name` or when `owner` flag is set to `true`.
|
2019-02-04 22:21:57 -05:00
|
|
|
|
2019-08-27 10:44:23 -04:00
|
|
|
`owner`::
|
|
|
|
(Optional, boolean) A boolean flag that can be used to query API keys owned
|
2020-07-14 08:06:20 -04:00
|
|
|
by the currently authenticated user. Defaults to false.
|
2019-08-27 10:44:23 -04:00
|
|
|
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.
|
|
|
|
|
2019-10-07 08:58:21 -04:00
|
|
|
NOTE: When none of the parameters "id", "name", "username" and "realm_name"
|
|
|
|
are specified, and the "owner" is set to false then it will retrieve all API
|
|
|
|
keys if the user is authorized. If the user is not authorized to retrieve other user's
|
|
|
|
API keys, then an error will be returned.
|
2019-02-04 22:21:57 -05:00
|
|
|
|
2019-08-02 13:56:05 -04:00
|
|
|
[[security-api-get-api-key-example]]
|
|
|
|
==== {api-examples-title}
|
2019-02-04 22:21:57 -05:00
|
|
|
|
2019-03-19 14:00:42 -04:00
|
|
|
If you create an API key as follows:
|
|
|
|
|
2019-09-05 14:12:39 -04:00
|
|
|
[source,console]
|
2019-03-19 14:00:42 -04:00
|
|
|
------------------------------------------------------------
|
|
|
|
POST /_security/api_key
|
|
|
|
{
|
|
|
|
"name": "my-api-key",
|
|
|
|
"role_descriptors": {}
|
|
|
|
}
|
|
|
|
------------------------------------------------------------
|
|
|
|
|
|
|
|
A successful call returns a JSON structure that provides
|
|
|
|
API key information. For example:
|
2019-02-04 22:21:57 -05:00
|
|
|
|
2019-09-05 14:12:39 -04:00
|
|
|
[source,console-result]
|
2019-02-04 22:21:57 -05:00
|
|
|
--------------------------------------------------
|
2019-03-19 14:00:42 -04:00
|
|
|
{
|
|
|
|
"id":"VuaCfGcBCdbkQm-e5aOx",
|
|
|
|
"name":"my-api-key",
|
|
|
|
"api_key":"ui2lp2axTNmsyakw9tvNnw"
|
|
|
|
}
|
2019-02-04 22:21:57 -05:00
|
|
|
--------------------------------------------------
|
2019-03-19 14:00:42 -04:00
|
|
|
// TESTRESPONSE[s/VuaCfGcBCdbkQm-e5aOx/$body.id/]
|
|
|
|
// TESTRESPONSE[s/ui2lp2axTNmsyakw9tvNnw/$body.api_key/]
|
2019-02-04 22:21:57 -05:00
|
|
|
|
2019-03-19 14:00:42 -04:00
|
|
|
You can use the following example to retrieve the API key by ID:
|
2019-02-04 22:21:57 -05:00
|
|
|
|
2019-09-05 14:12:39 -04:00
|
|
|
[source,console]
|
2019-02-04 22:21:57 -05:00
|
|
|
--------------------------------------------------
|
2019-03-19 14:00:42 -04:00
|
|
|
GET /_security/api_key?id=VuaCfGcBCdbkQm-e5aOx
|
2019-02-04 22:21:57 -05:00
|
|
|
--------------------------------------------------
|
2019-03-19 14:00:42 -04:00
|
|
|
// TEST[s/VuaCfGcBCdbkQm-e5aOx/$body.id/]
|
|
|
|
// TEST[continued]
|
|
|
|
|
|
|
|
You can use the following example to retrieve the API key by name:
|
|
|
|
|
2019-09-05 14:12:39 -04:00
|
|
|
[source,console]
|
2019-03-19 14:00:42 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
GET /_security/api_key?name=my-api-key
|
|
|
|
--------------------------------------------------
|
|
|
|
// TEST[continued]
|
2019-02-04 22:21:57 -05:00
|
|
|
|
2020-07-14 08:06:20 -04:00
|
|
|
API key name supports prefix search by using wildcard:
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
--------------------------------------------------
|
|
|
|
GET /_security/api_key?name=my-*
|
|
|
|
--------------------------------------------------
|
|
|
|
// TEST[continued]
|
|
|
|
|
2019-02-04 22:21:57 -05:00
|
|
|
The following example retrieves all API keys for the `native1` realm:
|
|
|
|
|
2019-09-05 14:12:39 -04:00
|
|
|
[source,console]
|
2019-02-04 22:21:57 -05:00
|
|
|
--------------------------------------------------
|
2019-02-28 14:08:39 -05:00
|
|
|
GET /_security/api_key?realm_name=native1
|
2019-02-04 22:21:57 -05:00
|
|
|
--------------------------------------------------
|
2019-03-19 14:00:42 -04:00
|
|
|
// TEST[continued]
|
2019-02-04 22:21:57 -05:00
|
|
|
|
|
|
|
The following example retrieves all API keys for the user `myuser` in all realms:
|
|
|
|
|
2019-09-05 14:12:39 -04:00
|
|
|
[source,console]
|
2019-02-04 22:21:57 -05:00
|
|
|
--------------------------------------------------
|
2019-02-28 14:08:39 -05:00
|
|
|
GET /_security/api_key?username=myuser
|
2019-02-04 22:21:57 -05:00
|
|
|
--------------------------------------------------
|
2019-03-19 14:00:42 -04:00
|
|
|
// TEST[continued]
|
2019-02-04 22:21:57 -05:00
|
|
|
|
2019-08-27 10:44:23 -04:00
|
|
|
The following example retrieves all API keys owned by the currently authenticated user:
|
|
|
|
|
2019-09-05 14:12:39 -04:00
|
|
|
[source,console]
|
2019-08-27 10:44:23 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
GET /_security/api_key?owner=true
|
|
|
|
--------------------------------------------------
|
|
|
|
// TEST[continued]
|
|
|
|
|
2019-10-07 08:58:21 -04:00
|
|
|
The following example retrieves all API keys if the user is authorized to do so:
|
|
|
|
[source,console]
|
|
|
|
--------------------------------------------------
|
|
|
|
GET /_security/api_key
|
|
|
|
--------------------------------------------------
|
|
|
|
// TEST[continued]
|
|
|
|
|
2019-08-27 10:44:23 -04:00
|
|
|
Following creates an API key
|
|
|
|
|
2019-09-05 14:12:39 -04:00
|
|
|
[source,console]
|
2019-08-27 10:44:23 -04:00
|
|
|
------------------------------------------------------------
|
|
|
|
POST /_security/api_key
|
|
|
|
{
|
|
|
|
"name": "my-api-key-1"
|
|
|
|
}
|
|
|
|
------------------------------------------------------------
|
|
|
|
|
|
|
|
The following example retrieves the API key identified by the specified `id` if
|
|
|
|
it is owned by the currently authenticated user:
|
|
|
|
|
2019-09-05 14:12:39 -04:00
|
|
|
[source,console]
|
2019-08-27 10:44:23 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
GET /_security/api_key?id=VuaCfGcBCdbkQm-e5aOx&owner=true
|
|
|
|
--------------------------------------------------
|
|
|
|
// TEST[s/VuaCfGcBCdbkQm-e5aOx/$body.id/]
|
|
|
|
// TEST[continued]
|
|
|
|
|
2019-02-04 22:21:57 -05:00
|
|
|
Finally, the following example retrieves all API keys for the user `myuser` in
|
|
|
|
the `native1` realm immediately:
|
|
|
|
|
2019-09-05 14:12:39 -04:00
|
|
|
[source,console]
|
2019-02-04 22:21:57 -05:00
|
|
|
--------------------------------------------------
|
2019-02-28 14:08:39 -05:00
|
|
|
GET /_security/api_key?username=myuser&realm_name=native1
|
2019-02-04 22:21:57 -05:00
|
|
|
--------------------------------------------------
|
2019-03-19 14:00:42 -04:00
|
|
|
// TEST[continued]
|
2019-02-04 22:21:57 -05:00
|
|
|
|
|
|
|
A successful call returns a JSON structure that contains the information of one or more API keys that were retrieved.
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"api_keys": [ <1>
|
|
|
|
{
|
|
|
|
"id": "dGhpcyBpcyBub3QgYSByZWFsIHRva2VuIGJ1dCBpdCBpcyBvbmx5IHRlc3QgZGF0YS4gZG8gbm90IHRyeSB0byByZWFkIHRva2VuIQ==", <2>
|
|
|
|
"name": "hadoop_myuser_key", <3>
|
|
|
|
"creation": 1548550550158, <4>
|
|
|
|
"expiration": 1548551550158, <5>
|
|
|
|
"invalidated": false, <6>
|
|
|
|
"username": "myuser", <7>
|
|
|
|
"realm": "native1" <8>
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": "api-key-id-2",
|
|
|
|
"name": "api-key-name-2",
|
|
|
|
"creation": 1548550550158,
|
|
|
|
"invalidated": false,
|
|
|
|
"username": "user-y",
|
|
|
|
"realm": "realm-2"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
// NOTCONSOLE
|
|
|
|
|
|
|
|
<1> The list of API keys that were retrieved for this request.
|
|
|
|
<2> Id for the API key
|
|
|
|
<3> Name of the API key
|
|
|
|
<4> Creation time for the API key in milliseconds
|
2019-03-19 14:00:42 -04:00
|
|
|
<5> Optional expiration time for the API key in milliseconds
|
|
|
|
<6> Invalidation status for the API key. If the key has been invalidated, it has
|
|
|
|
a value of `true`. Otherwise, it is `false`.
|
|
|
|
<7> Principal for which this API key was created
|
|
|
|
<8> Realm name of the principal for which this API key was created
|