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

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