configuring-stack-security.asciidoc 7.4 KB

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