remote-clusters-api-key.asciidoc 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. [[remote-clusters-api-key]]
  2. === Add remote clusters using API key authentication
  3. beta::[]
  4. API key authentication enables a local cluster to authenticate itself with a
  5. remote cluster via a <<security-api-create-cross-cluster-api-key,cross-cluster
  6. API key>>. The API key needs to be created by an administrator of the remote
  7. cluster. The local cluster is configured to provide this API key on each request
  8. to the remote cluster. The remote cluster verifies the API key and grants
  9. access, based on the API key's privileges.
  10. All cross-cluster requests from the local cluster are bound by the API key's
  11. privileges, regardless of local users associated with the requests. For example,
  12. if the API key only allows read access to `my-index` on the remote cluster, even
  13. a superuser from the local cluster is limited by this constraint. This mechanism
  14. enables the remote cluster's administrator to have full control over who can
  15. access what data with cross-cluster search and/or cross-cluster replication. The
  16. remote cluster's administrator can be confident that no access is possible
  17. beyond what is explicitly assigned to the API key.
  18. On the local cluster side, not every local user needs to access every piece of
  19. data allowed by the API key. An administrator of the local cluster can further
  20. configure additional permission constraints on local users so each user only
  21. gets access to the necessary remote data. Note it is only possible to further
  22. reduce the permissions allowed by the API key for individual local users. It is
  23. impossible to increase the permissions to go beyond what is allowed by the API
  24. key.
  25. In this model, cross-cluster operations use <<remote_cluster.port,a dedicated
  26. server port>> (remote cluster interface) for communication between clusters. A
  27. remote cluster must enable this port for local clusters to connect. Configure
  28. Transport Layer Security (TLS) for this port to maximize security (as explained
  29. in <<remote-clusters-security-api-key>>).
  30. The local cluster must trust the remote cluster on the remote cluster interface.
  31. This means that the local cluster trusts the remote cluster's certificate
  32. authority (CA) that signs the server certificate used by the remote cluster
  33. interface. When establishing a connection, all nodes from the local cluster that
  34. participate in cross-cluster communication verify certificates from nodes on the
  35. other side, based on the TLS trust configuration.
  36. To add a remote cluster using API key authentication:
  37. . <<remote-clusters-prerequisites-api-key,Review the prerequisites>>
  38. . <<remote-clusters-security-api-key>>
  39. . <<remote-clusters-connect-api-key>>
  40. . <<remote-clusters-privileges-api-key>>
  41. If you run into any issues, refer to <<remote-clusters-troubleshooting>>.
  42. [[remote-clusters-prerequisites-api-key]]
  43. ==== Prerequisites
  44. * The {es} security features need to be enabled on both clusters, on every node.
  45. Security is enabled by default. If it's disabled, set `xpack.security.enabled`
  46. to `true` in `elasticsearch.yml`. Refer to <<general-security-settings>>.
  47. * The nodes of the local and remote clusters must be on version 8.10 or later.
  48. * The local and remote clusters must have an appropriate license. For more
  49. information, refer to https://www.elastic.co/subscriptions.
  50. [[remote-clusters-security-api-key]]
  51. ==== Establish trust with a remote cluster
  52. ===== On the remote cluster
  53. // tag::remote-cluster-steps[]
  54. . Enable the remote cluster server on every node of the remote cluster. In
  55. `elasticsearch.yml`:
  56. .. Set <<remote-cluster-network-settings,`remote_cluster_server.enabled`>> to
  57. `true`.
  58. .. Configure the bind and publish address for remote cluster server traffic, for
  59. example using <<remote-cluster-network-settings,`remote_cluster.host`>>. Without
  60. configuring the address, remote cluster traffic may be bound to the local
  61. interface, and remote clusters running on other machines can't connect.
  62. .. Optionally, configure the remote server port using
  63. <<remote_cluster.port,`remote_cluster.port`>> (defaults to `9443`).
  64. . Next, generate a certificate authority (CA) and a server certificate/key pair.
  65. On one of the nodes of the remote cluster, from the directory where {es} has
  66. been installed:
  67. .. Create a CA, if you don't have a CA already:
  68. +
  69. [source,sh]
  70. ----
  71. ./bin/elasticsearch-certutil ca --pem --out=cross-cluster-ca.zip --pass CA_PASSWORD
  72. ----
  73. +
  74. Replace `CA_PASSWORD` with the password you want to use for the CA. You can
  75. remove the `--pass` option and its argument if you are not deploying to a
  76. production environment.
  77. .. Unzip the generated `cross-cluster-ca.zip` file. This compressed file
  78. contains the following content:
  79. +
  80. [source,txt]
  81. ----
  82. /ca
  83. |_ ca.crt
  84. |_ ca.key
  85. ----
  86. .. Generate a certificate and private key pair for the nodes in the remote
  87. cluster:
  88. +
  89. [source,sh]
  90. ----
  91. ./bin/elasticsearch-certutil cert --out=cross-cluster.p12 --pass=CERT_PASSWORD --ca-cert=ca/ca.crt --ca-key=ca/ca.key --ca-pass=CA_PASSWORD --dns=example.com --ip=127.0.0.1
  92. ----
  93. +
  94. * Replace `CA_PASSWORD` with the CA password from the previous step.
  95. * Replace `CERT_PASSWORD` with the password you want to use for the generated
  96. private key.
  97. * Use the `--dns` option to specify the relevant DNS name for the certificate.
  98. You can specify it multiple times for multiple DNS.
  99. * Use the `--ip` option to specify the relevant IP address for the certificate.
  100. You can specify it multiple times for multiple IP addresses.
  101. .. If the remote cluster has multiple nodes, you can either:
  102. +
  103. * create a single wildcard certificate for all nodes;
  104. * or, create separate certificates for each node either manually or in batch
  105. with the <<certutil-silent,silent mode>>.
  106. . On every node of the remote cluster:
  107. .. Copy the `cross-cluster.p12` file from the earlier step to the `config`
  108. directory. If you didn't create a wildcard certificate, make sure you copy the
  109. correct node-specific p12 file.
  110. .. Add following configuration to `elasticsearch.yml`:
  111. +
  112. [source,yaml]
  113. ----
  114. xpack.security.remote_cluster_server.ssl.enabled: true
  115. xpack.security.remote_cluster_server.ssl.keystore.path: cross-cluster.p12
  116. ----
  117. .. Add the SSL keystore password to the {es} keystore:
  118. +
  119. [source,sh]
  120. ----
  121. ./bin/elasticsearch-keystore add xpack.security.remote_cluster_server.ssl.keystore.secure_password
  122. ----
  123. +
  124. When prompted, enter the `CERT_PASSWORD` from the earlier step.
  125. . Restart the remote cluster.
  126. . On the remote cluster, generate a cross-cluster API key that provides access
  127. to the indices you want to use for {ccs} or {ccr}. You can use the
  128. <<security-api-create-cross-cluster-api-key>> API or
  129. {kibana-ref}/api-keys.html[Kibana].
  130. . Copy the encoded key (`encoded` in the response) to a safe location. You will
  131. need it to connect to the remote cluster later.
  132. // end::remote-cluster-steps[]
  133. ===== On the local cluster
  134. // tag::local-cluster-steps[]
  135. . On every node of the local cluster:
  136. .. Copy the `ca.crt` file generated on the remote cluster earlier into the
  137. `config` directory, renaming the file `remote-cluster-ca.crt`.
  138. .. Add following configuration to `elasticsearch.yml`:
  139. +
  140. [source,yaml]
  141. ----
  142. xpack.security.remote_cluster_client.ssl.enabled: true
  143. xpack.security.remote_cluster_client.ssl.certificate_authorities: [ "remote-cluster-ca.crt" ]
  144. ----
  145. // end::local-cluster-steps[]
  146. .. Add the cross-cluster API key, created on the remote cluster earlier, to the
  147. keystore:
  148. +
  149. [source,sh]
  150. ----
  151. ./bin/elasticsearch-keystore add cluster.remote.ALIAS.credentials
  152. ----
  153. +
  154. Replace `ALIAS` with the same name that you will use to create the remote cluster entry
  155. later. When prompted, enter the encoded cross-cluster API key created on the
  156. remote cluster earlier.
  157. . Restart the local cluster to load changes to the keystore and settings.
  158. **Note:** If you are configuring only the cross-cluster API key, you can call the <<cluster-nodes-reload-secure-settings>> API, instead of restarting the cluster.
  159. Configuring the `remote_cluster_client` settings in `elasticsearch.yml` still requires a restart.
  160. [[remote-clusters-connect-api-key]]
  161. ==== Connect to a remote cluster
  162. :trust-mechanism: api-key
  163. include::remote-clusters-connect.asciidoc[]
  164. :!trust-mechanism:
  165. include::{es-repo-dir}/security/authentication/remote-clusters-privileges-api-key.asciidoc[leveloffset=+1]