get-api-keys.asciidoc 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. [role="xpack"]
  2. [[security-api-get-api-key]]
  3. === Get API key information API
  4. ++++
  5. <titleabbrev>Get API key information</titleabbrev>
  6. ++++
  7. Retrieves information for one or more API keys.
  8. [[security-api-get-api-key-request]]
  9. ==== {api-request-title}
  10. `GET /_security/api_key`
  11. [[security-api-get-api-key-prereqs]]
  12. ==== {api-prereq-title}
  13. * To use this API, you must have at least the `manage_api_key` cluster privilege.
  14. [[security-api-get-api-key-desc]]
  15. ==== {api-description-title}
  16. The information for the API keys created by
  17. <<security-api-create-api-key,create API Key>> can be retrieved using this API.
  18. [[security-api-get-api-key-request-body]]
  19. ==== {api-request-body-title}
  20. The following parameters can be specified in the query parameters of a GET request and
  21. pertain to retrieving api keys:
  22. `id`::
  23. (Optional, string) An API key id. This parameter cannot be used with any of
  24. `name`, `realm_name` or `username` are used.
  25. `name`::
  26. (Optional, string) An API key name. This parameter cannot be used with any of
  27. `id`, `realm_name` or `username` are used.
  28. `realm_name`::
  29. (Optional, string) The name of an authentication realm. This parameter cannot be
  30. used with either `id` or `name`.
  31. `username`::
  32. (Optional, string) The username of a user. This parameter cannot be used with
  33. either `id` or `name`.
  34. NOTE: While all parameters are optional, at least one of them is required.
  35. [[security-api-get-api-key-example]]
  36. ==== {api-examples-title}
  37. If you create an API key as follows:
  38. [source, js]
  39. ------------------------------------------------------------
  40. POST /_security/api_key
  41. {
  42. "name": "my-api-key",
  43. "role_descriptors": {}
  44. }
  45. ------------------------------------------------------------
  46. // CONSOLE
  47. // TEST
  48. A successful call returns a JSON structure that provides
  49. API key information. For example:
  50. [source,js]
  51. --------------------------------------------------
  52. {
  53. "id":"VuaCfGcBCdbkQm-e5aOx",
  54. "name":"my-api-key",
  55. "api_key":"ui2lp2axTNmsyakw9tvNnw"
  56. }
  57. --------------------------------------------------
  58. // TESTRESPONSE[s/VuaCfGcBCdbkQm-e5aOx/$body.id/]
  59. // TESTRESPONSE[s/ui2lp2axTNmsyakw9tvNnw/$body.api_key/]
  60. You can use the following example to retrieve the API key by ID:
  61. [source,js]
  62. --------------------------------------------------
  63. GET /_security/api_key?id=VuaCfGcBCdbkQm-e5aOx
  64. --------------------------------------------------
  65. // CONSOLE
  66. // TEST[s/VuaCfGcBCdbkQm-e5aOx/$body.id/]
  67. // TEST[continued]
  68. You can use the following example to retrieve the API key by name:
  69. [source,js]
  70. --------------------------------------------------
  71. GET /_security/api_key?name=my-api-key
  72. --------------------------------------------------
  73. // CONSOLE
  74. // TEST[continued]
  75. The following example retrieves all API keys for the `native1` realm:
  76. [source,js]
  77. --------------------------------------------------
  78. GET /_security/api_key?realm_name=native1
  79. --------------------------------------------------
  80. // CONSOLE
  81. // TEST[continued]
  82. The following example retrieves all API keys for the user `myuser` in all realms:
  83. [source,js]
  84. --------------------------------------------------
  85. GET /_security/api_key?username=myuser
  86. --------------------------------------------------
  87. // CONSOLE
  88. // TEST[continued]
  89. Finally, the following example retrieves all API keys for the user `myuser` in
  90. the `native1` realm immediately:
  91. [source,js]
  92. --------------------------------------------------
  93. GET /_security/api_key?username=myuser&realm_name=native1
  94. --------------------------------------------------
  95. // CONSOLE
  96. // TEST[continued]
  97. A successful call returns a JSON structure that contains the information of one or more API keys that were retrieved.
  98. [source,js]
  99. --------------------------------------------------
  100. {
  101. "api_keys": [ <1>
  102. {
  103. "id": "dGhpcyBpcyBub3QgYSByZWFsIHRva2VuIGJ1dCBpdCBpcyBvbmx5IHRlc3QgZGF0YS4gZG8gbm90IHRyeSB0byByZWFkIHRva2VuIQ==", <2>
  104. "name": "hadoop_myuser_key", <3>
  105. "creation": 1548550550158, <4>
  106. "expiration": 1548551550158, <5>
  107. "invalidated": false, <6>
  108. "username": "myuser", <7>
  109. "realm": "native1" <8>
  110. },
  111. {
  112. "id": "api-key-id-2",
  113. "name": "api-key-name-2",
  114. "creation": 1548550550158,
  115. "invalidated": false,
  116. "username": "user-y",
  117. "realm": "realm-2"
  118. }
  119. ]
  120. }
  121. --------------------------------------------------
  122. // NOTCONSOLE
  123. <1> The list of API keys that were retrieved for this request.
  124. <2> Id for the API key
  125. <3> Name of the API key
  126. <4> Creation time for the API key in milliseconds
  127. <5> Optional expiration time for the API key in milliseconds
  128. <6> Invalidation status for the API key. If the key has been invalidated, it has
  129. a value of `true`. Otherwise, it is `false`.
  130. <7> Principal for which this API key was created
  131. <8> Realm name of the principal for which this API key was created