1
0

invalidate-api-keys.asciidoc 7.2 KB

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