invalidate-api-keys.asciidoc 7.1 KB

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