configuring-stack-security.asciidoc 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. [[configuring-stack-security]]
  2. == Start the {stack} with security enabled automatically
  3. When you start {es} for the first time, the following security configuration
  4. occurs automatically:
  5. * <<stack-security-certificates,Certificates and keys>> for TLS are
  6. generated for the transport and HTTP layers.
  7. * The TLS configuration settings are written to `elasticsearch.yml`.
  8. * A password is generated for the `elastic` user.
  9. * An enrollment token is generated for {kib}.
  10. You can then start {kib} and enter the enrollment token, which is valid for 30
  11. minutes. This token automatically applies the security settings from your {es}
  12. cluster, authenticates to {es} with the built-in `kibana` service account, and
  13. writes the security configuration to `kibana.yml`.
  14. NOTE: There are <<stack-skip-auto-configuration,some cases>> where security
  15. can't be configured automatically because the node startup process detects that
  16. the node is already part of a cluster, or that security is already configured or
  17. explicitly disabled.
  18. [discrete]
  19. === Prerequisites
  20. * https://www.elastic.co/downloads/elasticsearch[Download] and
  21. unpack the `elasticsearch` package distribution for your
  22. environment.
  23. * https://www.elastic.co/downloads/kibana[Download] and unpack
  24. the `kibana` package distribution for your environment.
  25. [discrete]
  26. [[stack-start-with-security]]
  27. === Start {es} and enroll {kib} with security enabled
  28. . From the installation directory, start {es}.
  29. +
  30. [source,shell]
  31. ----
  32. bin/elasticsearch
  33. ----
  34. +
  35. The command prints the `elastic` user password and an enrollment token for {kib}.
  36. . Copy the generated `elastic` password and enrollment token. These credentials
  37. are only shown when you start {es} for the first time.
  38. +
  39. [NOTE]
  40. ====
  41. If you need to reset the password for the `elastic` user or other
  42. built-in users, run the <<reset-password,`elasticsearch-reset-password`>> tool.
  43. To generate new enrollment tokens for {kib} or {es} nodes, run the
  44. <<create-enrollment-token,`elasticsearch-create-enrollment-token`>> tool.
  45. These tools are available in the {es} `bin` directory.
  46. ====
  47. +
  48. We recommend storing the `elastic` password as an environment variable in your shell. Example:
  49. +
  50. [source,sh]
  51. ----
  52. export ELASTIC_PASSWORD="your_password"
  53. ----
  54. . (Optional) Open a new terminal and verify that you can connect to your {es}
  55. cluster by making an authenticated call.
  56. +
  57. [source,shell]
  58. ----
  59. curl --cacert config/certs/http_ca.crt -u elastic:$ELASTIC_PASSWORD https://localhost:9200
  60. ----
  61. // NOTCONSOLE
  62. . From the directory where you installed {kib}, start {kib}.
  63. +
  64. [source,shell]
  65. ----
  66. bin/kibana
  67. ----
  68. . Enroll {kib} using either interactive or detached mode.
  69. * *Interactive mode* (browser)
  70. .. In your terminal, click the generated link to open {kib} in your browser.
  71. .. In your browser, paste the enrollment token that you copied and click the
  72. button to connect your {kib} instance with {es}.
  73. +
  74. --
  75. [NOTE]
  76. ====
  77. {kib} won't enter interactive mode if it detects existing credentials for {es}
  78. (`elasticsearch.username` and `elasticsearch.password`) or an existing URL for
  79. `elasticsearch.hosts`.
  80. ====
  81. --
  82. * *Detached mode* (non-browser)
  83. +
  84. Run the `kibana-setup` tool and pass the generated enrollment token with the
  85. `--enrollment-token` parameter.
  86. +
  87. ["source","sh",subs="attributes"]
  88. ----
  89. bin/kibana-setup --enrollment-token <enrollment-token>
  90. ----
  91. [discrete]
  92. [[stack-enroll-nodes]]
  93. === Enroll additional nodes in your cluster
  94. :slash: /
  95. include::enroll-nodes.asciidoc[]
  96. [discrete]
  97. include::{es-ref-dir}/setup/install/connect-clients.asciidoc[leveloffset=-1]
  98. [discrete]
  99. === What's next?
  100. Congratulations! You've successfully started the {stack} with security enabled.
  101. {es} and {kib} are secured with TLS on the HTTP layer, and internode
  102. communication is encrypted. If you want to enable HTTPS for web traffic, you
  103. can <<encrypt-kibana-browser,encrypt traffic between your browser and {kib}>>.
  104. [discrete]
  105. [[stack-security-certificates]]
  106. include::{es-ref-dir}/setup/install/security-files-reference.asciidoc[leveloffset=-2]
  107. Additionally, when you use the enrollment token to connect {kib} to a secured {es} cluster, the HTTP layer CA certificate is retrieved from {es} and stored in the
  108. {kib} `/data` directory. This file establishes trust between {kib} and the {es}
  109. Certificate Authority (CA) for the HTTP layer.
  110. [discrete]
  111. [[stack-skip-auto-configuration]]
  112. === Cases when security auto configuration is skipped
  113. When you start {es} for the first time, the node startup process tries to
  114. automatically configure security for you. The process runs some checks to
  115. determine:
  116. * If this is the first time that the node is starting
  117. * Whether security is already configured
  118. * If the startup process can modify the node configuration
  119. If any of those checks fail, there's a good indication that you
  120. <<manually-configure-security,manually configured security>>, or don't want
  121. security to be configured automatically. In these cases, the node starts
  122. normally using the existing configuration.
  123. IMPORTANT: If you redirect {es} output to a file, security autoconfiguration is skipped.
  124. Autoconfigured credentials can only be viewed on the terminal the first time you start {es}.
  125. If you need to redirect output to a file, start {es} without redirection the first time
  126. and use redirection on all subsequent starts.
  127. [discrete]
  128. [[stack-existing-environment-detected]]
  129. ==== Existing environment detected
  130. If certain directories already exist, there's a strong indication that the node
  131. was started previously. Similarly, if certain files _don't_ exist, or we can't
  132. read or write to specific files or directories, then we're likely not running as
  133. the user who installed {es} or an administrator imposed restrictions. If any of
  134. the following environment checks are true, security isn't configured
  135. automatically.
  136. The {es} `/data` directory exists and isn't empty::
  137. The existence of this directory is a strong indicator that the node was started
  138. previously, and might already be part of a cluster.
  139. The `elasticsearch.yml` file doesn't exist (or isn't readable), or the `elasticsearch.keystore` isn't readable::
  140. If either of these files aren't readable, we can't determine whether {es} security
  141. features are already enabled. This state can also indicate that the node startup
  142. process isn't running as a user with sufficient privileges to modify the
  143. node configuration.
  144. The {es} configuration directory isn't writable::
  145. This state likely indicates that an administrator made this directory read-only,
  146. or that the user who is starting {es} is not the user that installed {es}.
  147. [discrete]
  148. [[stack-existing-settings-detected]]
  149. ==== Existing settings detected
  150. The following settings are incompatible with security auto configuration. If any
  151. of these settings exist, the node startup process skips configuring security
  152. automatically and the node starts normally.
  153. * {ref}/modules-node.html#node-roles[`node.roles`] is set to a value where the
  154. node can't be elected as `master`, or if the node can't hold data
  155. * {ref}/security-settings.html#general-security-settings[`xpack.security.autoconfiguration.enabled`] is set to `false`
  156. * {ref}/security-settings.html#general-security-settings[`xpack.security.enabled`] has a value set
  157. * Any of the
  158. {ref}/security-settings.html#transport-tls-ssl-settings[`xpack.security.transport.ssl.*`] or
  159. {ref}/security-settings.html#http-tls-ssl-settings[`xpack.security.http.ssl.*`]
  160. settings have a value set in the `elasticsearch.yml` configuration file or in
  161. the `elasticsearch.keystore`
  162. * Any of the `discovery.type`, `discovery.seed_hosts`, or
  163. `cluster.initial_master_nodes`
  164. {ref}/modules-discovery-settings.html[discovery and cluster formation settings]
  165. have a value set
  166. +
  167. --
  168. [NOTE]
  169. ====
  170. Exceptions are when `discovery.type` is set to `single-node`, or when
  171. `cluster.initial_master_nodes` exists but contains only the name of the current
  172. node.
  173. ====
  174. --