create-cross-cluster-api-key.asciidoc 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. [role="xpack"]
  2. [[security-api-create-cross-cluster-api-key]]
  3. === Create Cross-Cluster API key API
  4. beta::[]
  5. ++++
  6. <titleabbrev>Create Cross-Cluster API key</titleabbrev>
  7. ++++
  8. Creates an API key of the `cross_cluster` type for the <<remote-clusters-api-key,API key based remote cluster>> access.
  9. A `cross_cluster` API key cannot be used to authenticate through the REST interface.
  10. On the contrary, a <<security-api-create-api-key,REST API key>> is meant to be used through the REST interface
  11. and cannot be used for the API key based remote cluster access.
  12. [[security-api-create-cross-cluster-api-key-request]]
  13. ==== {api-request-title}
  14. `POST /_security/cross_cluster/api_key`
  15. [[security-api-create-cross-cluster-api-key-prereqs]]
  16. ==== {api-prereq-title}
  17. * To use this API, you must have at least the `manage_security` cluster privilege.
  18. IMPORTANT: To authenticate this request you must use a credential that is *not* an API key. Even if you use an API key that has the required privilege, the API returns an error.
  19. [[security-api-create-cross-cluster-api-key-desc]]
  20. ==== {api-description-title}
  21. Cross-cluster API keys are created by the {es} API key service, which is automatically enabled.
  22. For instructions on disabling the API key service, refer to <<api-key-service-settings>>.
  23. A successful request returns a JSON structure that contains the
  24. API key, its unique ID, and its name. If applicable, it also returns expiration
  25. information for the API key in milliseconds.
  26. NOTE: By default, API keys never expire. You can specify expiration information
  27. when you create the API keys.
  28. Refer to <<api-key-service-settings>> for configuration settings related to API key
  29. service.
  30. Cross-cluster API keys can only be updated with the
  31. <<security-api-update-cross-cluster-api-key,Update Cross-Cluster API key API>>.
  32. Attempting to update them with the <<security-api-update-api-key,Update REST API key API>>
  33. or the <<security-api-bulk-update-api-keys,Bulk Update REST API Keys API>> will result
  34. into an error. They can be retrieved and invalidated using
  35. <<security-api-get-api-key,Get API keys API>>, <<security-api-query-api-key,Query API keys API>>
  36. and <<security-api-invalidate-api-key,Invalidate API keys API>>.
  37. [[security-api-create-cross-cluster-api-key-request-body]]
  38. ==== {api-request-body-title}
  39. The following parameters can be specified in the body of a POST request:
  40. `name`::
  41. (Required, string) Specifies the name for this API key.
  42. [[cross-cluster-api-key-access]]
  43. `access`::
  44. (required, object) The access to be granted to this API key. The access is
  45. composed of permissions for cross-cluster search and cross-cluster replication.
  46. At least one of them must be specified.
  47. `search`::: (optional, list) A list of indices permission entries for cross-cluster search.
  48. `names`:::: (required, list) A list of indices or name patterns to which the
  49. permissions in this entry apply.
  50. `field_security`:::: (optional, object) The document fields that the owners of the role have
  51. read access to. For more information, check <<field-and-document-access-control>>.
  52. `query`:::: (optional) A search query that defines the documents the owners of the role have
  53. read access to. A document within the specified indices must match this query to be accessible by the owners of the role. For more information, check
  54. <<field-and-document-access-control>>.
  55. `allow_restricted_indices`:::: (optional, boolean) This needs to be set to `true` (default
  56. is `false`) if the patterns in the `names` field should cover <<system-indices,system indices>>.
  57. `replication`::: (optional, list) A list of indices permission entries for cross-cluster replication.
  58. `names`:::: (required, list) A list of indices or name patterns to which the
  59. permissions in this entry apply.
  60. NOTE: No explicit <<security-privileges,privileges>> should be specified for either search
  61. or replication access. The creation process automatically converts the `access` specification
  62. to a <<api-key-role-descriptors,role descriptor>> which has relevant privileges assigned accordingly.
  63. The `access` value as well as its corresponding `role_descriptors` are returned in responses of
  64. <<security-api-get-api-key,Get API keys API>> and <<security-api-query-api-key,Query API keys API>>.
  65. NOTE: Unlike <<api-key-role-descriptors,REST API keys>>, a cross-cluster API key
  66. does not capture permissions of the authenticated user. The API key's effective
  67. permission is exactly as specified with the `access` parameter.
  68. `expiration`::
  69. (optional, string) Expiration time for the API key. By default, API keys never
  70. expire.
  71. `metadata`::
  72. (optional, object) Arbitrary metadata that you want to associate with the API key.
  73. It supports nested data structure.
  74. Within the `metadata` object, keys beginning with `_` are reserved for
  75. system usage.
  76. [[security-api-create-cross-cluster-api-key-example]]
  77. ==== {api-examples-title}
  78. The following example creates a cross-cluster API key:
  79. [source,console]
  80. ----
  81. POST /_security/cross_cluster/api_key
  82. {
  83. "name": "my-cross-cluster-api-key",
  84. "expiration": "1d", <1>
  85. "access": {
  86. "search": [ <2>
  87. {
  88. "names": ["logs*"]
  89. }
  90. ],
  91. "replication": [ <3>
  92. {
  93. "names": ["archive*"]
  94. }
  95. ]
  96. },
  97. "metadata": {
  98. "description": "phase one",
  99. "environment": {
  100. "level": 1,
  101. "trusted": true,
  102. "tags": ["dev", "staging"]
  103. }
  104. }
  105. }
  106. ----
  107. <1> Optional expiration for the API key being generated. If expiration is not
  108. provided then the API key does not expire.
  109. <2> Cross-cluster search access to be granted to the API key.
  110. <3> Cross-cluster replication access to be granted to the API key.
  111. A successful call returns a JSON structure that provides API key information.
  112. [source,console-result]
  113. ----
  114. {
  115. "id": "VuaCfGcBCdbkQm-e5aOx", <1>
  116. "name": "my-cross-cluster-api-key",
  117. "expiration": 1544068612110, <2>
  118. "api_key": "ui2lp2axTNmsyakw9tvNnw", <3>
  119. "encoded": "VnVhQ2ZHY0JDZGJrUW0tZTVhT3g6dWkybHAyYXhUTm1zeWFrdzl0dk5udw==" <4>
  120. }
  121. ----
  122. // TESTRESPONSE[s/VuaCfGcBCdbkQm-e5aOx/$body.id/]
  123. // TESTRESPONSE[s/1544068612110/$body.expiration/]
  124. // TESTRESPONSE[s/ui2lp2axTNmsyakw9tvNnw/$body.api_key/]
  125. // TESTRESPONSE[s/VnVhQ2ZHY0JDZGJrUW0tZTVhT3g6dWkybHAyYXhUTm1zeWFrdzl0dk5udw==/$body.encoded/]
  126. <1> Unique `id` for this API key
  127. <2> Optional expiration in milliseconds for this API key
  128. <3> Generated API key secret
  129. <4> API key credentials which is the Base64-encoding of the UTF-8
  130. representation of the `id` and `api_key` joined by a colon (`:`)
  131. The API key information can be retrieved with the <<security-api-get-api-key,Get API key API>>.
  132. [source,console]
  133. --------------------------------------------------
  134. GET /_security/api_key?id=VuaCfGcBCdbkQm-e5aOx
  135. --------------------------------------------------
  136. // TEST[s/VuaCfGcBCdbkQm-e5aOx/$body.id/]
  137. // TEST[continued]
  138. A successful call returns a JSON structure that contains the information of the API key:
  139. [source,js]
  140. --------------------------------------------------
  141. {
  142. "api_keys": [
  143. {
  144. "id": "VuaCfGcBCdbkQm-e5aOx", <1>
  145. "name": "my-cross-cluster-api-key", <2>
  146. "type": "cross_cluster", <3>
  147. "creation": 1548550550158,
  148. "expiration": 1548551550158,
  149. "invalidated": false,
  150. "username": "myuser",
  151. "realm": "native1",
  152. "metadata": {
  153. "description": "phase one",
  154. "environment": {
  155. "level": 1,
  156. "trusted": true,
  157. "tags": ["dev", "staging"]
  158. }
  159. },
  160. "role_descriptors": { <4>
  161. "cross_cluster": {
  162. "cluster": [ <5>
  163. "cross_cluster_search", "cross_cluster_replication"
  164. ],
  165. "indices": [
  166. { <6>
  167. "names": [
  168. "logs*"
  169. ],
  170. "privileges": [
  171. "read", "read_cross_cluster", "view_index_metadata"
  172. ],
  173. "allow_restricted_indices": false
  174. },
  175. { <7>
  176. "names": [
  177. "archive*"
  178. ],
  179. "privileges": [
  180. "cross_cluster_replication", "cross_cluster_replication_internal"
  181. ],
  182. "allow_restricted_indices": false
  183. }
  184. ],
  185. "applications": [ ],
  186. "run_as": [ ],
  187. "metadata": { },
  188. "transient_metadata": {
  189. "enabled": true
  190. }
  191. }
  192. },
  193. "access": { <8>
  194. "search": [
  195. {
  196. "names": [
  197. "logs*"
  198. ],
  199. "allow_restricted_indices": false
  200. }
  201. ],
  202. "replication": [
  203. {
  204. "names": [
  205. "archive*"
  206. ],
  207. "allow_restricted_indices": false
  208. }
  209. ]
  210. }
  211. }
  212. ]
  213. }
  214. --------------------------------------------------
  215. // NOTCONSOLE
  216. <1> ID for the API key
  217. <2> Name of the API key
  218. <3> Type of the API key
  219. <4> The role descriptors generated for the cross-cluster API key. It always
  220. contains exactly one role descriptor named `cross_cluster`.
  221. A cross-cluster API key has no limited-by role descriptors.
  222. <5> The cluster privileges necessary for the required cross-cluster access.
  223. The value is `cross_cluster_search` if only cross-cluster search is required.
  224. It is `cross_cluster_replication` if only cross-cluster replication is required.
  225. Or both, if search and replication are required.
  226. <6> The indices privileges corresponding to the required cross-cluster search access.
  227. <7> The indices privileges corresponding to the required cross-cluster replication access.
  228. <8> The `access` corresponds to the value specified at API key creation time.
  229. To use the generated API key, configure it as the cluster credential as part of an API key based remote cluster configuration.