invalidate-api-keys.asciidoc 6.6 KB

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