invalidate-api-keys.asciidoc 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. [role="xpack"]
  2. [[security-api-invalidate-api-key]]
  3. === Invalidate API key API
  4. ++++
  5. <titleabbrev>Invalidate API key</titleabbrev>
  6. ++++
  7. Invalidates one or more API keys.
  8. [[security-api-invalidate-api-key-request]]
  9. ==== {api-request-title}
  10. `DELETE /_security/api_key`
  11. [[security-api-invalidate-api-key-prereqs]]
  12. ==== {api-prereq-title}
  13. * To use this API, you must have at least the `manage_api_key` or the `manage_own_api_key` cluster privilege.
  14. The `manage_api_key` privilege allows deleting any API keys.
  15. The `manage_own_api_key` only allows deleting API keys that are owned by the user.
  16. In addition, with the `manage_own_api_key` privilege, an invalidation request must be issued
  17. in one of the three formats:
  18. 1. Set the parameter `owner=true`
  19. 2. Or, set both `username` and `realm_name` to match the user's identity.
  20. 3. Or, if the request is issued by an API key, i.e. an API key invalidates itself, specify its ID in the `ids` field.
  21. [[security-api-invalidate-api-key-desc]]
  22. ==== {api-description-title}
  23. This API invalidates API keys created by the <<security-api-create-api-key,create API key>> or <<security-api-grant-api-key,grant API key>>
  24. APIs.
  25. Invalidated API keys fail authentication, but they can still be viewed using the
  26. <<security-api-get-api-key,get API key information>> and <<security-api-query-api-key,query API key information>> APIs,
  27. for at least the <<api-key-service-settings-delete-retention-period,configured retention period>>, until they are automatically deleted.
  28. [[security-api-invalidate-api-key-request-body]]
  29. ==== {api-request-body-title}
  30. The following parameters can be specified in the body of a DELETE request and
  31. pertain to invalidating api keys:
  32. `ids`::
  33. (Optional, array of string) A list of API key ids. This parameter cannot be used
  34. when any of `name`, `realm_name`, `username` are used
  35. `name`::
  36. (Optional, string) An API key name. This parameter cannot be used with any of
  37. `ids`, `realm_name` or `username` are used.
  38. `realm_name`::
  39. (Optional, string) The name of an authentication realm. This parameter cannot be
  40. used with either `ids` or `name` or when `owner` flag is set to `true`.
  41. `username`::
  42. (Optional, string) The username of a user. This parameter cannot be used with
  43. either `ids` or `name` or when `owner` flag is set to `true`.
  44. `owner`::
  45. (Optional, Boolean) A boolean flag that can be used to query API keys owned
  46. by the currently authenticated user. Defaults to false.
  47. The 'realm_name' or 'username' parameters cannot be specified when this
  48. parameter is set to 'true' as they are assumed to be the currently authenticated ones.
  49. NOTE: At least one of "ids", "name", "username" and "realm_name" must be specified
  50. if "owner" is "false" (default).
  51. [[security-api-invalidate-api-key-response-body]]
  52. ==== {api-response-body-title}
  53. A successful call returns a JSON structure that contains the ids of the API keys
  54. that were invalidated, the ids of the API keys that had already been invalidated,
  55. and potentially a list of errors encountered while invalidating specific api
  56. keys.
  57. [[security-api-invalidate-api-key-example]]
  58. ==== {api-examples-title}
  59. If you create an API key as follows:
  60. [source,console]
  61. ------------------------------------------------------------
  62. POST /_security/api_key
  63. {
  64. "name": "my-api-key"
  65. }
  66. ------------------------------------------------------------
  67. A successful call returns a JSON structure that provides
  68. API key information. For example:
  69. [source,console-result]
  70. --------------------------------------------------
  71. {
  72. "id": "VuaCfGcBCdbkQm-e5aOx",
  73. "name": "my-api-key",
  74. "api_key": "ui2lp2axTNmsyakw9tvNnw",
  75. "encoded": "VnVhQ2ZHY0JDZGJrUW0tZTVhT3g6dWkybHAyYXhUTm1zeWFrdzl0dk5udw=="
  76. }
  77. --------------------------------------------------
  78. // TESTRESPONSE[s/VuaCfGcBCdbkQm-e5aOx/$body.id/]
  79. // TESTRESPONSE[s/ui2lp2axTNmsyakw9tvNnw/$body.api_key/]
  80. // TESTRESPONSE[s/VnVhQ2ZHY0JDZGJrUW0tZTVhT3g6dWkybHAyYXhUTm1zeWFrdzl0dk5udw==/$body.encoded/]
  81. The following example invalidates the API key identified by specified `ids`
  82. immediately:
  83. [source,console]
  84. --------------------------------------------------
  85. DELETE /_security/api_key
  86. {
  87. "ids" : [ "VuaCfGcBCdbkQm-e5aOx" ]
  88. }
  89. --------------------------------------------------
  90. // TEST[s/VuaCfGcBCdbkQm-e5aOx/$body.id/]
  91. // TEST[continued]
  92. The following example invalidates the API key identified by specified `name`
  93. immediately:
  94. [source,console]
  95. --------------------------------------------------
  96. DELETE /_security/api_key
  97. {
  98. "name" : "my-api-key"
  99. }
  100. --------------------------------------------------
  101. The following example invalidates all API keys for the `native1` realm
  102. immediately:
  103. [source,console]
  104. --------------------------------------------------
  105. DELETE /_security/api_key
  106. {
  107. "realm_name" : "native1"
  108. }
  109. --------------------------------------------------
  110. The following example invalidates all API keys for the user `myuser` in all
  111. realms immediately:
  112. [source,console]
  113. --------------------------------------------------
  114. DELETE /_security/api_key
  115. {
  116. "username" : "myuser"
  117. }
  118. --------------------------------------------------
  119. The following example invalidates the API key identified by the specified `ids` if
  120. it is owned by the currently authenticated user immediately:
  121. [source,console]
  122. --------------------------------------------------
  123. DELETE /_security/api_key
  124. {
  125. "ids" : ["VuaCfGcBCdbkQm-e5aOx"],
  126. "owner" : "true"
  127. }
  128. --------------------------------------------------
  129. The following example invalidates all API keys owned by the currently authenticated
  130. user immediately:
  131. [source,console]
  132. --------------------------------------------------
  133. DELETE /_security/api_key
  134. {
  135. "owner" : "true"
  136. }
  137. --------------------------------------------------
  138. Finally, the following example invalidates all API keys for the user `myuser` in
  139. the `native1` realm immediately:
  140. [source,console]
  141. --------------------------------------------------
  142. DELETE /_security/api_key
  143. {
  144. "username" : "myuser",
  145. "realm_name" : "native1"
  146. }
  147. --------------------------------------------------
  148. [source,js]
  149. --------------------------------------------------
  150. {
  151. "invalidated_api_keys": [ <1>
  152. "api-key-id-1"
  153. ],
  154. "previously_invalidated_api_keys": [ <2>
  155. "api-key-id-2",
  156. "api-key-id-3"
  157. ],
  158. "error_count": 2, <3>
  159. "error_details": [ <4>
  160. {
  161. "type": "exception",
  162. "reason": "error occurred while invalidating api keys",
  163. "caused_by": {
  164. "type": "illegal_argument_exception",
  165. "reason": "invalid api key id"
  166. }
  167. },
  168. {
  169. "type": "exception",
  170. "reason": "error occurred while invalidating api keys",
  171. "caused_by": {
  172. "type": "illegal_argument_exception",
  173. "reason": "invalid api key id"
  174. }
  175. }
  176. ]
  177. }
  178. --------------------------------------------------
  179. // NOTCONSOLE
  180. <1> The IDs of the API keys that were invalidated as part of this request.
  181. <2> The IDs of the API keys that were already invalidated.
  182. <3> The number of errors that were encountered when invalidating the API keys.
  183. <4> Details about these errors. This field is not present in the response when
  184. `error_count` is 0.