invalidate-api-keys.asciidoc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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` cluster privilege.
  14. [[security-api-invalidate-api-key-desc]]
  15. ==== {api-description-title}
  16. The API keys created by <<security-api-create-api-key,create API Key>> can be
  17. invalidated using this API.
  18. [[security-api-invalidate-api-key-request-body]]
  19. ==== {api-request-body-title}
  20. The following parameters can be specified in the body of a DELETE request and
  21. pertain to invalidating 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-invalidate-api-key-response-body]]
  36. ==== {api-response-body-title}
  37. A successful call returns a JSON structure that contains the ids of the API keys
  38. that were invalidated, the ids of the API keys that had already been invalidated,
  39. and potentially a list of errors encountered while invalidating specific api
  40. keys.
  41. [[security-api-invalidate-api-key-example]]
  42. ==== {api-examples-title}
  43. If you create an API key as follows:
  44. [source, js]
  45. ------------------------------------------------------------
  46. POST /_security/api_key
  47. {
  48. "name": "my-api-key"
  49. }
  50. ------------------------------------------------------------
  51. // CONSOLE
  52. // TEST
  53. A successful call returns a JSON structure that provides
  54. API key information. For example:
  55. [source,js]
  56. --------------------------------------------------
  57. {
  58. "id":"VuaCfGcBCdbkQm-e5aOx",
  59. "name":"my-api-key",
  60. "api_key":"ui2lp2axTNmsyakw9tvNnw"
  61. }
  62. --------------------------------------------------
  63. // TESTRESPONSE[s/VuaCfGcBCdbkQm-e5aOx/$body.id/]
  64. // TESTRESPONSE[s/ui2lp2axTNmsyakw9tvNnw/$body.api_key/]
  65. The following example invalidates the API key identified by specified `id`
  66. immediately:
  67. [source,js]
  68. --------------------------------------------------
  69. DELETE /_security/api_key
  70. {
  71. "id" : "VuaCfGcBCdbkQm-e5aOx"
  72. }
  73. --------------------------------------------------
  74. // CONSOLE
  75. // TEST[s/VuaCfGcBCdbkQm-e5aOx/$body.id/]
  76. // TEST[continued]
  77. The following example invalidates the API key identified by specified `name`
  78. immediately:
  79. [source,js]
  80. --------------------------------------------------
  81. DELETE /_security/api_key
  82. {
  83. "name" : "my-api-key"
  84. }
  85. --------------------------------------------------
  86. // CONSOLE
  87. // TEST
  88. The following example invalidates all API keys for the `native1` realm
  89. immediately:
  90. [source,js]
  91. --------------------------------------------------
  92. DELETE /_security/api_key
  93. {
  94. "realm_name" : "native1"
  95. }
  96. --------------------------------------------------
  97. // CONSOLE
  98. // TEST
  99. The following example invalidates all API keys for the user `myuser` in all
  100. realms immediately:
  101. [source,js]
  102. --------------------------------------------------
  103. DELETE /_security/api_key
  104. {
  105. "username" : "myuser"
  106. }
  107. --------------------------------------------------
  108. // CONSOLE
  109. // TEST
  110. Finally, the following example invalidates all API keys for the user `myuser` in
  111. the `native1` realm immediately:
  112. [source,js]
  113. --------------------------------------------------
  114. DELETE /_security/api_key
  115. {
  116. "username" : "myuser",
  117. "realm_name" : "native1"
  118. }
  119. --------------------------------------------------
  120. // CONSOLE
  121. // TEST
  122. [source,js]
  123. --------------------------------------------------
  124. {
  125. "invalidated_api_keys": [ <1>
  126. "api-key-id-1"
  127. ],
  128. "previously_invalidated_api_keys": [ <2>
  129. "api-key-id-2",
  130. "api-key-id-3"
  131. ],
  132. "error_count": 2, <3>
  133. "error_details": [ <4>
  134. {
  135. "type": "exception",
  136. "reason": "error occurred while invalidating api keys",
  137. "caused_by": {
  138. "type": "illegal_argument_exception",
  139. "reason": "invalid api key id"
  140. }
  141. },
  142. {
  143. "type": "exception",
  144. "reason": "error occurred while invalidating api keys",
  145. "caused_by": {
  146. "type": "illegal_argument_exception",
  147. "reason": "invalid api key id"
  148. }
  149. }
  150. ]
  151. }
  152. --------------------------------------------------
  153. // NOTCONSOLE
  154. <1> The IDs of the API keys that were invalidated as part of this request.
  155. <2> The IDs of the API keys that were already invalidated.
  156. <3> The number of errors that were encountered when invalidating the API keys.
  157. <4> Details about these errors. This field is not present in the response when
  158. `error_count` is 0.