security-basic-setup.asciidoc 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. [[security-basic-setup]]
  2. === Set up basic security for the Elastic Stack
  3. ++++
  4. <titleabbrev>Set up basic security</titleabbrev>
  5. ++++
  6. When you start {es} for the first time, passwords are generated for the `elastic`
  7. user and TLS is automatically configured for you. If you configure security
  8. manually _before_ starting your {es} nodes, the auto-configuration process will
  9. respect your security configuration. You can adjust your TLS configuration at
  10. any time, such as <<update-node-certs,updating node certificates>>.
  11. IMPORTANT: If your cluster has multiple nodes, then you must configure
  12. TLS between nodes. <<dev-vs-prod-mode,Production mode>> clusters will not start
  13. if you do not enable TLS.
  14. The transport layer relies on mutual TLS for both encryption and
  15. authentication of nodes. Correctly applying TLS ensures that a malicious node
  16. cannot join the cluster and exchange data with other nodes. While implementing
  17. username and password authentication at the HTTP layer is useful for securing a
  18. local cluster, the security of communication between nodes requires TLS.
  19. Configuring TLS between nodes is the basic security setup to prevent
  20. unauthorized nodes from accessing to your cluster.
  21. .Understanding transport contexts
  22. ****
  23. Transport Layer Security (TLS) is the name of an industry standard protocol for
  24. applying security controls (such as encryption) to network communications. TLS
  25. is the modern name for what used to be called Secure Sockets Layer (SSL). The
  26. {es} documentation uses the terms TLS and SSL interchangeably.
  27. Transport Protocol is the name of the protocol that {es} nodes use to
  28. communicate with one another. This name is specific to {es} and distinguishes
  29. the transport port (default `9300`) from the HTTP port (default `9200`). Nodes
  30. communicate with one another using the transport port, and REST clients
  31. communicate with {es} using the HTTP port.
  32. Although the word _transport_ appears in both contexts, they mean different
  33. things. It's possible to apply TLS to both the {es} transport port and the HTTP
  34. port. We know that these overlapping terms can be confusing, so to clarify, in
  35. this scenario we're applying TLS to the {es} transport port. In
  36. <<security-basic-setup-https,the next scenario>>, we'll apply TLS to the {es}
  37. HTTP port.
  38. ****
  39. [[generate-certificates]]
  40. ==== Generate the certificate authority
  41. You can add as many nodes as you want in a cluster but they must be able to
  42. communicate with each other. The communication between nodes in a cluster is
  43. handled by the transport module. To secure your cluster, you must ensure that
  44. internode communications are encrypted and verified, which is achieved with
  45. mutual TLS.
  46. In a secured cluster, {es} nodes use certificates to identify
  47. themselves when communicating with other nodes.
  48. The cluster must validate the authenticity of these certificates. The
  49. recommended approach is to trust a specific certificate authority (CA). When
  50. nodes are added to your cluster they must use a certificate signed by the same
  51. CA.
  52. For the transport layer, we recommend using a separate, dedicated CA instead
  53. of an existing, possibly shared CA so that node membership is tightly controlled. Use the `elasticsearch-certutil` tool to
  54. generate a CA for your cluster.
  55. . Before starting {es}, use the `elasticsearch-certutil` tool on any single node
  56. to generate a CA for your cluster.
  57. +
  58. [source,shell]
  59. ----
  60. ./bin/elasticsearch-certutil ca
  61. ----
  62. a. When prompted, accept the default file name, which is `elastic-stack-ca.p12`. This file contains the public certificate for your CA and the private key used to sign certificates for each node.
  63. b. Enter a password for your CA. You can choose to leave the password blank
  64. if you're not deploying to a production environment.
  65. . On any single node, generate a certificate and private key for the nodes in
  66. your cluster. You include the `elastic-stack-ca.p12` output file that you
  67. generated in the previous step.
  68. +
  69. [source,shell]
  70. ----
  71. ./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12
  72. ----
  73. +
  74. `--ca <ca_file>`:: Name of the CA file used to sign your certificates. The
  75. default file name from the `elasticsearch-certutil` tool is `elastic-stack-ca.p12`.
  76. +
  77. a. Enter the password for your CA, or press *Enter* if you did not configure one in the previous step.
  78. b. Create a password for the certificate and accept the default file name.
  79. +
  80. The output file is a keystore named `elastic-certificates.p12`. This file
  81. contains a node certificate, node key, and CA certificate.
  82. . On *every* node in your cluster, copy the `elastic-certificates.p12` file to
  83. the `$ES_PATH_CONF` directory.
  84. [[encrypt-internode-communication]]
  85. ==== Encrypt internode communications with TLS
  86. The transport networking layer is used for internal communication between
  87. nodes in a cluster. When security features are enabled, you must use TLS to
  88. ensure that communication between the nodes is encrypted.
  89. Now that you've generated a certificate authority and certificates, you'll
  90. update your cluster to use these files.
  91. NOTE: {es} monitors all files such as certificates, keys, keystores, or
  92. truststores that are configured as values of TLS-related node settings. If
  93. you update any of these files, such as when your hostnames change or your
  94. certificates are due to expire, {es} reloads them. The files are polled for
  95. changes at a frequency determined by the global {es}
  96. `resource.reload.interval.high` setting, which defaults to 5 seconds.
  97. Complete the following steps *for each node in your cluster*. To join the
  98. same cluster, all nodes must share the same `cluster.name` value.
  99. . Open the `$ES_PATH_CONF/elasticsearch.yml` file and make the following
  100. changes:
  101. a. Add the <<cluster-name,`cluster-name`>> setting and enter a name for your cluster:
  102. +
  103. [source,yaml]
  104. ----
  105. cluster.name: my-cluster
  106. ----
  107. b. Add the <<node-name,`node.name`>> setting and enter a name for the node.
  108. The node name defaults to the hostname of the machine when {es} starts.
  109. +
  110. [source,yaml]
  111. ----
  112. node.name: node-1
  113. ----
  114. c. Add the following settings to enable internode communication and provide
  115. access to the node's certificate.
  116. +
  117. Because you are using the same `elastic-certificates.p12` file on every node in
  118. your cluster, set the verification mode to `certificate`:
  119. +
  120. [source,yaml]
  121. ----
  122. xpack.security.transport.ssl.enabled: true
  123. xpack.security.transport.ssl.verification_mode: certificate <1>
  124. xpack.security.transport.ssl.client_authentication: required
  125. xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
  126. xpack.security.transport.ssl.truststore.path: elastic-certificates.p12
  127. ----
  128. <1> If you want to use hostname verification, set the verification mode to
  129. `full`. You should generate a different certificate for each host that
  130. matches the DNS or IP address. See the
  131. `xpack.security.transport.ssl.verification_mode` parameter in {ref}/security-settings.html#transport-tls-ssl-settings[TLS settings].
  132. . If you entered a password when creating the node certificate, run the following commands to store the password in the {es} keystore:
  133. +
  134. --
  135. [source,shell]
  136. ----
  137. ./bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password
  138. ----
  139. [source,shell]
  140. ----
  141. ./bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password
  142. ----
  143. --
  144. . Complete the previous steps for each node in your cluster.
  145. . On *every* node in your cluster, start {es}. The method for
  146. <<starting-elasticsearch,starting>> and <<starting-elasticsearch,stopping>> {es}
  147. varies depending on how you installed it.
  148. +
  149. For example, if you installed {es} with an archive distribution
  150. (`tar.gz` or `.zip`), you can enter `Ctrl+C` on the command line to stop
  151. {es}.
  152. +
  153. WARNING: You must perform a full cluster restart. Nodes that are configured to
  154. use TLS for transport cannot communicate with nodes that use unencrypted transport connection (and vice-versa).
  155. [[encrypting-internode-whatsnext]]
  156. ==== What's next?
  157. Congratulations! You've encrypted communications between the nodes in your
  158. cluster and can pass the
  159. <<bootstrap-checks-tls,TLS bootstrap check>>.
  160. To add another layer of security, <<security-basic-setup-https,Set up basic security for the Elastic Stack plus secured HTTPS traffic>>. In addition to
  161. configuring TLS on the transport interface of your {es} cluster, you configure
  162. TLS on the HTTP interface for both {es} and {kib}.