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