security-basic-setup-https.asciidoc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. [[security-basic-setup-https]]
  2. === Set up basic security for the Elastic Stack plus secured HTTPS traffic
  3. ++++
  4. <titleabbrev>Set up basic security plus HTTPS</titleabbrev>
  5. ++++
  6. When you enable TLS on the HTTP layer it provides an additional layer of
  7. security to ensure that all communications to and from your
  8. cluster are encrypted.
  9. When you run the `elasticsearch-certutil` tool in `http` mode, the tool asks
  10. several questions about how you want to generate certificates. While there are
  11. numerous options, the following choices result in certificates that should
  12. work for most environments.
  13. [[signing-certificates]]
  14. .Signing certificates
  15. ****
  16. The first question that the `elasticsearch-certutil` tool prompts you with is
  17. whether you want to generate a Certificate Signing Request (CSR). Answer
  18. `n` if you want to sign your own certificates, or `y` if you want to sign
  19. certificates with a central CA.
  20. [discrete]
  21. ===== Sign your own certificates
  22. If you want to use the CA that you created when
  23. <<generate-certificates,Generating the certificate authority>> answer `n` when
  24. asked if you want to generate a CSR. You then specify the location of your CA,
  25. which the tool uses to sign and generate a `.p12` certificate. The steps in
  26. this procedure follow this workflow.
  27. [discrete]
  28. ===== Sign certificates with a central CA
  29. If you work in an environment with a central security team, they can likely
  30. generate a certificate for you. Infrastructure within your organization
  31. might already be configured to trust an existing CA, so it may be easier
  32. for clients to connect to {es} if you use a CSR and send that
  33. request to the team that controls your CA. To use a central CA, answer `y` to
  34. the first question.
  35. ****
  36. [[basic-setup-https-prerequisites]]
  37. ==== Prerequisites
  38. Complete all steps in <<security-basic-setup,Set up basic security for the Elastic Stack>>.
  39. [[encrypt-http-communication]]
  40. ==== Encrypt HTTP client communications for {es}
  41. . On *every* node in your cluster, stop {es} and {kib} if they are running.
  42. . On any single node, from the directory where you installed {es}, run the {es}
  43. HTTP certificate tool to generate a Certificate Signing Request (CSR).
  44. +
  45. [source,shell]
  46. ----
  47. ./bin/elasticsearch-certutil http
  48. ----
  49. +
  50. This command generates a `.zip` file that contains certificates and keys
  51. to use with {es} and {kib}. Each folder contains a `README.txt`
  52. explaining how to use these files.
  53. a. When asked if you want to generate a CSR, enter `n`.
  54. b. When asked if you want to use an existing CA, enter `y`.
  55. c. Enter the path to your CA. This is the absolute path to
  56. the `elastic-stack-ca.p12` file that you generated for your cluster.
  57. d. Enter the password for your CA.
  58. e. Enter an expiration value for your certificate. You can enter the
  59. validity period in years, months, or days. For example, enter `90D` for 90
  60. days.
  61. f. When asked if you want to generate one certificate per node, enter `y`.
  62. +
  63. Each certificate will have its own private key, and will be issued for a
  64. specific hostname or IP address.
  65. g. When prompted, enter the name of the first node in your cluster. Use the same node name that you used when <<generate-certificates,generating node certificates>>.
  66. h. Enter all hostnames used to connect to your first node. These hostnames
  67. will be added as DNS names in the Subject Alternative Name (SAN) field in your certificate.
  68. +
  69. List every hostname and variant used to connect to your cluster over HTTPS.
  70. i. Enter the IP addresses that clients can use to connect to your node.
  71. j. Repeat these steps for each additional node in your cluster.
  72. . After generating a certificate for each of your nodes, enter a password for
  73. your private key when prompted.
  74. . Unzip the generated `elasticsearch-ssl-http.zip` file. This compressed file
  75. contains one directory for both {es} and {kib}.
  76. +
  77. --
  78. [source,txt]
  79. ----
  80. /elasticsearch
  81. |_ README.txt
  82. |_ http.p12
  83. |_ sample-elasticsearch.yml
  84. ----
  85. [source,txt]
  86. ----
  87. /kibana
  88. |_ README.txt
  89. |_ elasticsearch-ca.pem
  90. |_ sample-kibana.yml
  91. ----
  92. --
  93. . On *every* node in your cluster, complete the following steps:
  94. .. Copy the relevant `http.p12` certificate to the `$ES_PATH_CONF` directory.
  95. .. Edit the `elasticsearch.yml` file to enable HTTPS security and specify the
  96. location of the `http.p12` security certificate.
  97. +
  98. [source,yaml]
  99. ----
  100. xpack.security.http.ssl.enabled: true
  101. xpack.security.http.ssl.keystore.path: http.p12
  102. ----
  103. .. Add the password for your private key to the secure settings in {es}.
  104. +
  105. [source,shell]
  106. ----
  107. ./bin/elasticsearch-keystore add xpack.security.http.ssl.keystore.secure_password
  108. ----
  109. .. Start {es}.
  110. **Next**: <<encrypt-kibana-http,Encrypt HTTP client communications for {kib}>>
  111. [[encrypt-kibana-http]]
  112. ==== Encrypt HTTP client communications for {kib}
  113. Browsers send traffic to {kib} and {kib} sends traffic to {es}.
  114. These communication channels are configured separately to use TLS. You encrypt
  115. traffic between {kib} and {es}, and then encrypt traffic between your browser
  116. and {kib}.
  117. [[encrypt-kibana-elasticsearch]]
  118. ===== Encrypt traffic between {kib} and {es}
  119. When you ran the `elasticsearch-certutil` tool with the `http` option, it
  120. created a `/kibana` directory containing an `elasticsearch-ca.pem` file. You
  121. use this file to configure {kib} to trust the {es} CA for the HTTP
  122. layer.
  123. . Copy the `elasticsearch-ca.pem` file to the {kib} configuration directory,
  124. as defined by the `$KBN_PATH_CONF` path.
  125. . Open `kibana.yml` and add the following line to specify the location of the
  126. security certificate for the HTTP layer.
  127. +
  128. [source,yaml]
  129. ----
  130. elasticsearch.ssl.certificateAuthorities: $KBN_PATH_CONF/elasticsearch-ca.pem
  131. ----
  132. . Add the following line to specify the HTTPS URL for your {es}
  133. cluster.
  134. +
  135. [source,yaml]
  136. ----
  137. elasticsearch.hosts: https://<your_elasticsearch_host>:9200
  138. ----
  139. . Restart {kib}.
  140. .Connect to a secure monitoring cluster
  141. ****
  142. If the Elastic monitoring features are enabled and you configured a separate
  143. {es} monitoring cluster, you can also configure {kib} to connect to
  144. the monitoring cluster via HTTPS. The steps are the same, but each setting is
  145. prefixed by `monitoring`. For example, `monitoring.ui.elasticsearch.hosts` and
  146. `monitoring.ui.elasticsearch.ssl.truststore.path`.
  147. NOTE: You must create a separate `elasticsearch-ca.pem` security file for the
  148. monitoring cluster.
  149. ****
  150. **Next**: <<encrypt-kibana-browser,Encrypt traffic between your browser and {kib}>>
  151. [[encrypt-kibana-browser]]
  152. ===== Encrypt traffic between your browser and {kib}
  153. You create a server certificate and private key for {kib}. {kib} uses this
  154. server certificate and corresponding private key when receiving connections
  155. from web browsers.
  156. When you obtain a server certificate, you must set its subject alternative
  157. name (SAN) correctly to ensure that browsers will trust it. You can set one or
  158. more SANs to the {kib} server’s fully-qualified domain name (FQDN), hostname,
  159. or IP address. When choosing the SAN, pick whichever attribute you'll use to
  160. connect to {kib} in your browser, which is likely the FQDN.
  161. The following instructions create a Certificate Signing Request (CSR) for {kib}.
  162. A CSR contains information that a CA uses to generate and sign a security
  163. certificate. The certificate can be trusted (signed by a public, trusted CA)
  164. or untrusted (signed by an internal CA). A self-signed or internally-signed
  165. certificate is acceptable for development environments and building a proof of
  166. concept, but should not be used in a production environment.
  167. WARNING: Before going to production, use a trusted CA such as https://letsencrypt.org/[Let's
  168. Encrypt] or your organization's internal CA to sign the certificate. Using a
  169. signed certificate establishes browser trust for connections to {kib} for
  170. internal access or on the public internet.
  171. . Generate a server certificate and private key for {kib}.
  172. +
  173. [source,shell]
  174. ----
  175. ./bin/elasticsearch-certutil csr -name kibana-server -dns example.com,www.example.com
  176. ----
  177. +
  178. The CSR has a common name (CN) of `kibana-server`, a SAN of `example.com`,
  179. and another SAN of `www.example.com`.
  180. +
  181. This command generates a `csr-bundle.zip` file by default with the following
  182. contents:
  183. +
  184. [source,txt]
  185. ----
  186. /kibana-server
  187. |_ kibana-server.csr
  188. |_ kibana-server.key
  189. ----
  190. . Unzip the `csr-bundle.zip` file to obtain the `kibana-server.csr` unsigned
  191. security certificate and the `kibana-server.key` unencrypted private key.
  192. . Send the `kibana-server.csr` certificate signing request to your internal
  193. CA or trusted CA for signing to obtain a signed certificate. The signed file
  194. can be in different formats, such as a `.crt` file like `kibana-server.crt`.
  195. . Open `kibana.yml` and add the following lines to configure {kib} to access
  196. the server certificate and unencrypted private key.
  197. +
  198. [source,yaml]
  199. ----
  200. server.ssl.certificate: $KBN_PATH_CONF/kibana-server.crt
  201. server.ssl.key: $KBN_PATH_CONF/kibana-server.key
  202. ----
  203. +
  204. NOTE: `$KBN_PATH_CONF` contains the path for the {kib} configuration files. If
  205. you installed {kib} using archive distributions (`zip` or `tar.gz`), the
  206. path defaults to `$KBN_HOME/config`. If you used package distributions
  207. (Debian or RPM), the path defaults to `/etc/kibana`.
  208. . Add the following line to `kibana.yml` to enable TLS for inbound
  209. connections.
  210. +
  211. [source,yaml]
  212. ----
  213. server.ssl.enabled: true
  214. ----
  215. . Start {kib}.
  216. NOTE: After making these changes, you must always access {kib} via HTTPS. For
  217. example, `https://<your_kibana_host>.com`.
  218. **Next**: <<configure-beats-security,Configure {beats} security>>
  219. [[configure-beats-security]]
  220. ==== Configure {beats} security
  221. {beats} are open source data shippers that you install as agents on your
  222. servers to send operational data to {es}. Each Beat is a separately
  223. installable product. The following steps cover configuring security for
  224. {metricbeat}. Follow these steps for each
  225. {beats-ref}/getting-started.html[additional Beat] you want to configure security
  226. for.
  227. ===== Prerequisites
  228. {metricbeat-ref}/metricbeat-installation-configuration.html[Install {metricbeat}] using your preferred method.
  229. IMPORTANT: You cannot connect to the {stack} or configure assets for {metricbeat}
  230. before completing the following steps.
  231. ===== Create roles for {metricbeat}
  232. Typically, you need to create the following separate roles:
  233. - **setup** role for setting up index templates and other dependencies
  234. - **monitoring** role for sending monitoring information
  235. - **writer** role for publishing events collected by {metricbeat}
  236. - **reader** role for Kibana users who need to view and create visualizations that access {metricbeat} data
  237. NOTE: These instructions assume that you are using the default name for
  238. {metricbeat} indices. If the indicated index names are not listed, or you are
  239. using a custom name, enter it manually when defining roles and modify the
  240. privileges to match your index naming pattern.
  241. To create users and roles from Stack Management in {kib}, select **Roles**
  242. or **Users** from the side navigation.
  243. **Next**: <<beats-setup-role,Create a setup role>>
  244. [discrete]
  245. [[beats-setup-role]]
  246. ====== Create a setup role and user
  247. Administrators who set up {metricbeat} typically need to load mappings,
  248. dashboards, and other objects used to index data into {es} and visualize it in
  249. {kib}.
  250. WARNING: Setting up {metricbeat} is an admin-level task that requires extra
  251. privileges. As a best practice, grant the setup role to administrators only,
  252. and use a more restrictive role for event publishing.
  253. . Create the setup role:
  254. . Enter **metricbeat_setup** as the role name.
  255. . Choose the **monitor** and **manage_ilm** cluster privileges.
  256. . On the **metricbeat-\*** indices, choose the **manage** and **write**
  257. privileges.
  258. +
  259. If the **metricbeat-\*** indices aren't listed, enter that pattern into the
  260. list of indices.
  261. . Create the setup user:
  262. . Enter **metricbeat_setup** as the user name.
  263. . Enter the username, password, and other user details.
  264. . Assign the following roles to the **metricbeat_setup** user:
  265. +
  266. [cols="1,1"]
  267. |===
  268. | Role | Purpose
  269. | `metricbeat_setup` | Set up {metricbeat}.
  270. | `kibana_admin` | Load dependencies, such as example dashboards, if available, into {kib}
  271. | `ingest_admin` | Set up index templates and, if available, ingest pipelines
  272. |===
  273. **Next**: <<beats-monitoring-role,Create a monitoring role>>
  274. [discrete]
  275. [[beats-monitoring-role]]
  276. ====== Create a monitoring role and user
  277. To send monitoring data securely, create a monitoring user and grant it the
  278. necessary privileges.
  279. You can use the built-in `beats_system` user, if it’s available in your
  280. environment. Because the built-in users are not available in {ecloud},
  281. these instructions create a user that is explicitly used for monitoring
  282. {metricbeat}.
  283. . If you're using the built-in `beats_system` user, on any node in your cluster,
  284. run the <<reset-password,`elasticsearch-reset-password`>> utility to set the
  285. password for that user:
  286. +
  287. This command resets the password for the `beats_system` user to an
  288. auto-generated value.
  289. +
  290. [source,shell]
  291. ----
  292. ./bin/elasticsearch-reset-password -u beats_system
  293. ----
  294. +
  295. If you want to set the password to a specific value, run the command with the
  296. interactive (`-i`) parameter.
  297. +
  298. [source,shell]
  299. ----
  300. ./bin/elasticsearch-reset-password -i -u beats_system
  301. ----
  302. . Create the monitoring role:
  303. . Enter **metricbeat_monitoring** as the role name.
  304. . Choose the **monitor** cluster privilege.
  305. . On the **.monitoring-beats-\*** indices, choose the **create_index** and
  306. **create_doc** privileges.
  307. . Create the monitoring user:
  308. . Enter **metricbeat_monitoring** as the user name.
  309. . Enter the username, password, and other user details.
  310. . Assign the following roles to the **metricbeat_monitoring** user:
  311. +
  312. [cols="1,1"]
  313. |===
  314. | Role | Purpose
  315. | `metricbeat_monitoring` | Monitor {metricbeat}.
  316. | `kibana_admin` | Use {kib}
  317. | `monitoring_user` | Use Stack Monitoring in {kib} to monitor {metricbeat}
  318. |===
  319. **Next**: <<beats-writer-role,Create a writer role>>
  320. [discrete]
  321. [[beats-writer-role]]
  322. ====== Create a writer role and user
  323. Users who publish events to {es} need to create and write to {metricbeat} indices. To minimize the privileges required by the writer role, use the setup role to pre-load dependencies. This section assumes that you’ve
  324. <<beats-setup-role,created the setup role>>.
  325. . Create the writer role:
  326. . Enter **metricbeat_writer** as the role name.
  327. . Choose the **monitor** and **read_ilm** cluster privileges.
  328. . On the **metricbeat-\*** indices, choose the **create_doc**, **create_index**, and **view_index_metadata** privileges.
  329. . Create the writer user:
  330. . Enter **metricbeat_writer** as the user name.
  331. . Enter the username, password, and other user details.
  332. . Assign the following roles to the **metricbeat_writer** user:
  333. +
  334. [cols="1,1"]
  335. |===
  336. | Role | Purpose
  337. | `metricbeat_writer` | Monitor {metricbeat}
  338. | `remote_monitoring_collector` | Collect monitoring metrics from {metricbeat}
  339. | `remote_monitoring_agent` | Send monitoring data to the monitoring cluster
  340. |===
  341. **Next**: <<beats-reader-role,Create a reader role>>
  342. [discrete]
  343. [[beats-reader-role]]
  344. ====== Create a reader role and user
  345. {kib} users typically need to view dashboards and visualizations that contain
  346. {metricbeat} data. These users might also need to create and edit dashboards
  347. and visualizations. Create the reader role to assign proper privileges to these
  348. users.
  349. . Create the reader role:
  350. . Enter **metricbeat_reader** as the role name.
  351. . On the **metricbeat-\*** indices, choose the **read** privilege.
  352. . Under **Kibana**, click **Add Kibana privilege**.
  353. - Under **Spaces**, choose **Default**.
  354. - Choose **Read** or **All** for Discover, Visualize, Dashboard, and Metrics.
  355. . Create the reader user:
  356. . Enter **metricbeat_reader** as the user name.
  357. . Enter the username, password, and other user details.
  358. . Assign the following roles to the **metricbeat_reader** user:
  359. +
  360. [cols="1,1"]
  361. |===
  362. | Role | Purpose
  363. | `metricbeat_reader` | Read {metricbeat} data.
  364. | `monitoring_user` | Allow users to monitor the health of {metricbeat}
  365. itself. Only assign this role to users who manage {metricbeat}
  366. | `beats_admin` | Create and manage configurations in {beats} central
  367. management. Only assign this role to users who need to use {beats} central
  368. management.
  369. |===
  370. **Next**: <<configure-metricbeat-tls,Configure {metricbeat} to use TLS>>
  371. [discrete]
  372. [[configure-metricbeat-tls]]
  373. ===== Configure {metricbeat} to use TLS
  374. Before starting {metricbeat}, you configure the connections to {es} and
  375. {kib}. You can configure authentication to send data to your secured cluster
  376. using basic authentication, API key authentication, or Public Key
  377. Infrastructure (PKI) certificates.
  378. The following instructions use the credentials for the `metricbeat_writer`
  379. and `metricbeat_setup` users that you created. If you need a greater level of
  380. security, we recommend using PKI certificates.
  381. After configuring connections to {es} and {kib}, you'll enable the
  382. `elasticsearch-xpack` module and configure that module to use HTTPS.
  383. WARNING: In production environments, we strongly recommend using a separate
  384. cluster (referred to as the monitoring cluster) to store your data. Using a
  385. separate monitoring cluster prevents production cluster outages from impacting
  386. your ability to access your monitoring data. It also prevents monitoring
  387. activities from impacting the performance of your production cluster.
  388. . On the node where you
  389. <<encrypt-http-communication,generated certificates for the HTTP layer>>,
  390. navigate to the `/kibana` directory.
  391. . Copy the `elasticsearch-ca.pem` certificate to the directory where you
  392. installed {metricbeat}.
  393. . Open the `metricbeat.yml` configuration file and configure the connection
  394. to {es}.
  395. +
  396. Under `output.elasticsearch`, specify the following fields:
  397. +
  398. [source,yaml]
  399. ----
  400. output.elasticsearch:
  401. hosts: ["<your_elasticsearch_host>:9200"]
  402. protocol: "https"
  403. username: "metricbeat_writer"
  404. password: "<password>"
  405. ssl:
  406. certificate_authorities: ["elasticsearch-ca.pem"]
  407. verification_mode: "certificate"
  408. ----
  409. `hosts`:: Specifies the host where your {es} cluster is running.
  410. `protocol`:: Indicates the protocol to use when connecting to {es}.
  411. This value must be `https`.
  412. `username`:: Name of the user with privileges required to publish events to
  413. {es}. The `metricbeat_writer` user that you created has these
  414. privileges.
  415. `password`:: Password for the indicated `username`.
  416. `certificate_authorities`:: Indicates the path to the local `.pem` file that
  417. contains your CA's certificate.
  418. . Configure the connection to {kib}.
  419. +
  420. Under `setup.kibana`, specify the following fields:
  421. +
  422. [source,yaml]
  423. ----
  424. setup.kibana
  425. host: "https://<your_elasticsearch_host>:5601"
  426. ssl.enabled: true
  427. username: "metricbeat_setup"
  428. password: "p@ssw0rd"
  429. ----
  430. `hosts`:: The URLs of the {es} instances to use for all your
  431. queries. Ensure that you include `https` in the URL.
  432. `username`:: Name of the user with privileges required to set up dashboards in {kib}. The `metricbeat_setup` user that you created has these privileges.
  433. `password`:: Password for the indicated `username`.
  434. . Enable the `elasticsearch-xpack` module.
  435. +
  436. [source,shell]
  437. ----
  438. ./metricbeat modules enable elasticsearch-xpack
  439. ----
  440. . Modify the `elasticsearch-xpack` module to use HTTPS. This module collects
  441. metrics about {es}.
  442. +
  443. Open `/modules.d/elasticsearch-xpack.yml` and specify the following fields:
  444. +
  445. [source,yaml]
  446. ----
  447. - module: elasticsearch
  448. xpack.enabled: true
  449. period: 10s
  450. hosts: ["https://<your_elasticsearch_host>:9200"]
  451. username: "remote_monitoring_user"
  452. password: "<password>"
  453. ssl: <1>
  454. enabled: true
  455. certificate_authorities: ["elasticsearch-ca.pem"]
  456. verification_mode: "certificate"
  457. ----
  458. <1> Configuring SSL is required when monitoring a node with encrypted traffic.
  459. See {metricbeat-ref}/configuration-ssl.html[Configure SSL for {metricbeat}].
  460. `hosts`:: Specifies the host where your {es} cluster is running.
  461. Ensure that you include `https` in the URL.
  462. `username`:: Name of the user with privileges to collect metric data. The
  463. built-in `monitoring_user` user has these privileges. Alternatively,
  464. you can create a user and assign it the `monitoring_user` role.
  465. `password`:: Password for the indicated `username`.
  466. `certificate_authorities`:: Indicates the path to the local `.pem` file that
  467. contains your CA's certificate.
  468. . If you want to use the predefined assets for parsing, indexing, and
  469. visualizing your data, run the following command to load these assets:
  470. +
  471. [source,shell]
  472. ----
  473. ./metricbeat setup -e
  474. ----
  475. . Start {es}, and then start {metricbeat}.
  476. +
  477. [source,shell]
  478. ----
  479. ./metricbeat -e
  480. ----
  481. +
  482. `-e` is optional and sends output to standard error instead of the configured
  483. log output.
  484. . Log in to {kib}, open the main menu, and click **Stack Monitoring**.
  485. +
  486. You’ll see cluster alerts that require your attention and a summary of the available monitoring metrics for {es}. Click any of the header links on the available cards to view additional information.