2017-11-10 12:33:56 -05:00
|
|
|
[role="xpack"]
|
|
|
|
[[configuring-tls-docker]]
|
2018-12-19 17:53:37 -05:00
|
|
|
=== Encrypting communications in an {es} Docker Container
|
2017-11-10 12:33:56 -05:00
|
|
|
|
2019-05-20 09:06:42 -04:00
|
|
|
Unless you are using a trial license, {stack} {security-features} require
|
|
|
|
SSL/TLS encryption for the transport networking layer.
|
2017-11-10 12:33:56 -05:00
|
|
|
|
|
|
|
This section demonstrates an easy path to get started with SSL/TLS for both
|
2018-07-18 03:07:31 -04:00
|
|
|
HTTPS and transport using the {es} Docker image. The example uses
|
|
|
|
Docker Compose to manage the containers.
|
2017-11-10 12:33:56 -05:00
|
|
|
|
2019-10-07 18:23:19 -04:00
|
|
|
For further details, see
|
|
|
|
<<encrypting-communications>> and
|
2017-11-10 12:33:56 -05:00
|
|
|
https://www.elastic.co/subscriptions[available subscriptions].
|
|
|
|
|
|
|
|
[float]
|
|
|
|
==== Prepare the environment
|
|
|
|
|
2017-11-14 07:25:52 -05:00
|
|
|
<<docker,Install {es} with Docker>>.
|
2017-11-10 12:33:56 -05:00
|
|
|
|
2018-07-18 03:07:31 -04:00
|
|
|
Inside a new, empty directory, create the following four files:
|
2017-11-10 12:33:56 -05:00
|
|
|
|
|
|
|
`instances.yml`:
|
|
|
|
["source","yaml"]
|
|
|
|
----
|
|
|
|
instances:
|
|
|
|
- name: es01
|
|
|
|
dns:
|
|
|
|
- es01 <1>
|
|
|
|
- localhost
|
|
|
|
ip:
|
|
|
|
- 127.0.0.1
|
2018-07-18 03:07:31 -04:00
|
|
|
|
2017-11-10 12:33:56 -05:00
|
|
|
- name: es02
|
|
|
|
dns:
|
|
|
|
- es02
|
|
|
|
- localhost
|
|
|
|
ip:
|
|
|
|
- 127.0.0.1
|
|
|
|
----
|
|
|
|
<1> Allow use of embedded Docker DNS server names.
|
|
|
|
|
|
|
|
`.env`:
|
|
|
|
[source,yaml]
|
|
|
|
----
|
2019-07-01 08:33:34 -04:00
|
|
|
COMPOSE_PROJECT_NAME=es <1>
|
|
|
|
CERTS_DIR=/usr/share/elasticsearch/config/certificates <2>
|
|
|
|
ELASTIC_PASSWORD=PleaseChangeMe <3>
|
2017-11-10 12:33:56 -05:00
|
|
|
----
|
2019-07-01 08:33:34 -04:00
|
|
|
<1> Use an `es_` prefix for all volumes and networks created by docker-compose.
|
|
|
|
<2> The path, inside the Docker image, where certificates are expected to be found.
|
|
|
|
<3> Initial password for the `elastic` user.
|
2017-11-10 12:33:56 -05:00
|
|
|
|
|
|
|
[[getting-starter-tls-create-certs-composefile]]
|
|
|
|
`create-certs.yml`:
|
|
|
|
ifeval::["{release-state}"=="unreleased"]
|
|
|
|
|
|
|
|
WARNING: Version {version} of {es} has not yet been released, so a
|
|
|
|
`create-certs.yml` is not available for this version.
|
|
|
|
|
|
|
|
endif::[]
|
|
|
|
|
|
|
|
ifeval::["{release-state}"!="unreleased"]
|
|
|
|
["source","yaml",subs="attributes"]
|
|
|
|
----
|
|
|
|
version: '2.2'
|
2018-07-18 03:07:31 -04:00
|
|
|
|
2017-11-10 12:33:56 -05:00
|
|
|
services:
|
|
|
|
create_certs:
|
|
|
|
container_name: create_certs
|
2018-11-29 12:33:08 -05:00
|
|
|
image: {docker-image}
|
2017-11-10 12:33:56 -05:00
|
|
|
command: >
|
|
|
|
bash -c '
|
2019-07-01 08:33:34 -04:00
|
|
|
if [[ ! -f /certs/bundle.zip ]]; then
|
|
|
|
bin/elasticsearch-certutil cert --silent --pem --in config/certificates/instances.yml -out /certs/bundle.zip;
|
|
|
|
unzip /certs/bundle.zip -d /certs; <1>
|
2017-11-10 12:33:56 -05:00
|
|
|
fi;
|
2019-07-01 08:33:34 -04:00
|
|
|
chown -R 1000:0 /certs
|
2017-11-10 12:33:56 -05:00
|
|
|
'
|
2019-07-01 08:33:34 -04:00
|
|
|
user: "0"
|
2017-11-10 12:33:56 -05:00
|
|
|
working_dir: /usr/share/elasticsearch
|
2019-07-01 08:33:34 -04:00
|
|
|
volumes: ['certs:/certs', '.:/usr/share/elasticsearch/config/certificates']
|
|
|
|
|
|
|
|
volumes: {"certs"}
|
2017-11-10 12:33:56 -05:00
|
|
|
----
|
|
|
|
|
2019-07-01 08:33:34 -04:00
|
|
|
<1> The new node certificates and CA certificate+key are placed in a docker volume `es_certs`.
|
2017-11-10 12:33:56 -05:00
|
|
|
endif::[]
|
|
|
|
|
|
|
|
[[getting-starter-tls-create-docker-compose]]
|
|
|
|
`docker-compose.yml`:
|
|
|
|
ifeval::["{release-state}"=="unreleased"]
|
|
|
|
|
|
|
|
WARNING: Version {version} of {es} has not yet been released, so a
|
|
|
|
`docker-compose.yml` is not available for this version.
|
|
|
|
|
|
|
|
endif::[]
|
|
|
|
|
|
|
|
ifeval::["{release-state}"!="unreleased"]
|
|
|
|
["source","yaml",subs="attributes"]
|
|
|
|
----
|
|
|
|
version: '2.2'
|
2018-07-18 03:07:31 -04:00
|
|
|
|
2017-11-10 12:33:56 -05:00
|
|
|
services:
|
|
|
|
es01:
|
|
|
|
container_name: es01
|
2018-11-29 12:33:08 -05:00
|
|
|
image: {docker-image}
|
2017-11-10 12:33:56 -05:00
|
|
|
environment:
|
|
|
|
- node.name=es01
|
2019-07-01 08:33:34 -04:00
|
|
|
- discovery.seed_hosts=es01,es02
|
2018-12-20 08:02:44 -05:00
|
|
|
- cluster.initial_master_nodes=es01,es02
|
2017-11-10 12:33:56 -05:00
|
|
|
- ELASTIC_PASSWORD=$ELASTIC_PASSWORD <1>
|
|
|
|
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
|
2018-07-18 03:07:31 -04:00
|
|
|
- xpack.license.self_generated.type=trial <2>
|
|
|
|
- xpack.security.enabled=true
|
2017-11-10 12:33:56 -05:00
|
|
|
- xpack.security.http.ssl.enabled=true
|
2019-01-14 16:06:22 -05:00
|
|
|
- xpack.security.http.ssl.key=$CERTS_DIR/es01/es01.key
|
|
|
|
- xpack.security.http.ssl.certificate_authorities=$CERTS_DIR/ca/ca.crt
|
|
|
|
- xpack.security.http.ssl.certificate=$CERTS_DIR/es01/es01.crt
|
2017-11-10 12:33:56 -05:00
|
|
|
- xpack.security.transport.ssl.enabled=true
|
2018-07-18 03:07:31 -04:00
|
|
|
- xpack.security.transport.ssl.verification_mode=certificate <3>
|
2019-01-14 16:06:22 -05:00
|
|
|
- xpack.security.transport.ssl.certificate_authorities=$CERTS_DIR/ca/ca.crt
|
|
|
|
- xpack.security.transport.ssl.certificate=$CERTS_DIR/es01/es01.crt
|
|
|
|
- xpack.security.transport.ssl.key=$CERTS_DIR/es01/es01.key
|
2019-07-01 08:33:34 -04:00
|
|
|
volumes: ['data01:/usr/share/elasticsearch/data', 'certs:$CERTS_DIR']
|
2017-11-10 12:33:56 -05:00
|
|
|
ports:
|
|
|
|
- 9200:9200
|
|
|
|
healthcheck:
|
|
|
|
test: curl --cacert $CERTS_DIR/ca/ca.crt -s https://localhost:9200 >/dev/null; if [[ $$? == 52 ]]; then echo 0; else echo 1; fi
|
|
|
|
interval: 30s
|
|
|
|
timeout: 10s
|
|
|
|
retries: 5
|
2018-07-18 03:07:31 -04:00
|
|
|
|
2017-11-10 12:33:56 -05:00
|
|
|
es02:
|
|
|
|
container_name: es02
|
2018-11-29 12:33:08 -05:00
|
|
|
image: {docker-image}
|
2017-11-10 12:33:56 -05:00
|
|
|
environment:
|
|
|
|
- node.name=es02
|
2019-07-01 08:33:34 -04:00
|
|
|
- discovery.seed_hosts=es01,es02
|
2018-12-20 08:02:44 -05:00
|
|
|
- cluster.initial_master_nodes=es01,es02
|
|
|
|
- ELASTIC_PASSWORD=$ELASTIC_PASSWORD
|
2017-11-10 12:33:56 -05:00
|
|
|
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
|
2018-07-18 03:07:31 -04:00
|
|
|
- xpack.license.self_generated.type=trial
|
|
|
|
- xpack.security.enabled=true
|
2017-11-10 12:33:56 -05:00
|
|
|
- xpack.security.http.ssl.enabled=true
|
2019-01-14 16:06:22 -05:00
|
|
|
- xpack.security.http.ssl.key=$CERTS_DIR/es02/es02.key
|
|
|
|
- xpack.security.http.ssl.certificate_authorities=$CERTS_DIR/ca/ca.crt
|
|
|
|
- xpack.security.http.ssl.certificate=$CERTS_DIR/es02/es02.crt
|
2017-11-10 12:33:56 -05:00
|
|
|
- xpack.security.transport.ssl.enabled=true
|
2019-01-14 16:06:22 -05:00
|
|
|
- xpack.security.transport.ssl.verification_mode=certificate <3>
|
|
|
|
- xpack.security.transport.ssl.certificate_authorities=$CERTS_DIR/ca/ca.crt
|
|
|
|
- xpack.security.transport.ssl.certificate=$CERTS_DIR/es02/es02.crt
|
|
|
|
- xpack.security.transport.ssl.key=$CERTS_DIR/es02/es02.key
|
2019-07-01 08:33:34 -04:00
|
|
|
volumes: ['data02:/usr/share/elasticsearch/data', 'certs:$CERTS_DIR']
|
2018-07-18 03:07:31 -04:00
|
|
|
|
2017-11-10 12:33:56 -05:00
|
|
|
wait_until_ready:
|
2018-11-29 12:33:08 -05:00
|
|
|
image: {docker-image}
|
2017-11-10 12:33:56 -05:00
|
|
|
command: /usr/bin/true
|
|
|
|
depends_on: {"es01": {"condition": "service_healthy"}}
|
2018-07-18 03:07:31 -04:00
|
|
|
|
2019-07-01 08:33:34 -04:00
|
|
|
volumes: {"data01", "data02", "certs"}
|
2017-11-10 12:33:56 -05:00
|
|
|
----
|
|
|
|
|
2018-07-18 03:07:31 -04:00
|
|
|
<1> Bootstrap `elastic` with the password defined in `.env`. See
|
2019-10-07 18:23:19 -04:00
|
|
|
<<bootstrap-elastic-passwords>>.
|
2018-07-18 03:07:31 -04:00
|
|
|
<2> Automatically generate and apply a trial subscription, in order to enable
|
2018-12-19 17:53:37 -05:00
|
|
|
{security-features}.
|
2018-07-18 03:07:31 -04:00
|
|
|
<3> Disable verification of authenticity for inter-node communication. Allows
|
2017-11-10 12:33:56 -05:00
|
|
|
creating self-signed certificates without having to pin specific internal IP addresses.
|
|
|
|
endif::[]
|
|
|
|
|
|
|
|
[float]
|
|
|
|
==== Run the example
|
|
|
|
. Generate the certificates (only needed once):
|
|
|
|
+
|
|
|
|
--
|
|
|
|
["source","sh"]
|
|
|
|
----
|
2019-07-01 08:33:34 -04:00
|
|
|
docker-compose -f create-certs.yml run --rm create_certs
|
2017-11-10 12:33:56 -05:00
|
|
|
----
|
|
|
|
--
|
|
|
|
. Start two {es} nodes configured for SSL/TLS:
|
|
|
|
+
|
|
|
|
--
|
|
|
|
["source","sh"]
|
|
|
|
----
|
|
|
|
docker-compose up -d
|
|
|
|
----
|
|
|
|
--
|
|
|
|
. Access the {es} API over SSL/TLS using the bootstrapped password:
|
|
|
|
+
|
|
|
|
--
|
2019-07-01 08:33:34 -04:00
|
|
|
["source","sh",subs="attributes"]
|
2017-11-10 12:33:56 -05:00
|
|
|
----
|
2019-07-01 08:33:34 -04:00
|
|
|
docker run --rm -v es_certs:/certs --network=es_default {docker-image} curl --cacert /certs/ca/ca.crt -u elastic:PleaseChangeMe https://es01:9200
|
2017-11-10 12:33:56 -05:00
|
|
|
----
|
|
|
|
// NOTCONSOLE
|
|
|
|
--
|
2018-04-11 11:21:15 -04:00
|
|
|
. The `elasticsearch-setup-passwords` tool can also be used to generate random
|
|
|
|
passwords for all users:
|
2017-11-10 12:33:56 -05:00
|
|
|
+
|
|
|
|
--
|
2017-11-14 07:25:52 -05:00
|
|
|
WARNING: Windows users not running PowerShell will need to remove `\` and join lines in the snippet below.
|
2017-11-10 12:33:56 -05:00
|
|
|
["source","sh"]
|
|
|
|
----
|
2018-04-11 11:21:15 -04:00
|
|
|
docker exec es01 /bin/bash -c "bin/elasticsearch-setup-passwords \
|
2017-11-14 07:25:52 -05:00
|
|
|
auto --batch \
|
|
|
|
--url https://localhost:9200"
|
2017-11-10 12:33:56 -05:00
|
|
|
----
|
|
|
|
--
|
2019-07-01 08:33:34 -04:00
|
|
|
|
|
|
|
[float]
|
|
|
|
==== Tear everything down
|
|
|
|
To remove all the Docker resources created by the example, issue:
|
|
|
|
--
|
|
|
|
["source","sh"]
|
|
|
|
----
|
|
|
|
docker-compose down -v
|
|
|
|
----
|
|
|
|
--
|