Skip to content

Commit 663fc0b

Browse files
Add documentation for keystore startup prompting (#50821)
When a keystore is password-protected, Elasticsearch will prompt at startup. This commit adds documentation for this prompt for the archive, systemd, and Docker cases. Co-authored-by: Lisa Cawley <[email protected]>
1 parent 93ca7e6 commit 663fc0b

File tree

6 files changed

+103
-12
lines changed

6 files changed

+103
-12
lines changed

docs/reference/commands/keystore.asciidoc

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ in the {es} keystore.
1111
[source,shell]
1212
--------------------------------------------------
1313
bin/elasticsearch-keystore
14-
([add <setting>] [--stdin] |
15-
[add-file <setting> <path>] | [create] |
16-
[list] | [remove <setting>] | [upgrade])
14+
([add <setting>] [-f] [--stdin] |
15+
[add-file <setting> <path>] | [create] [-p] |
16+
[list] | [passwd] | [remove <setting>] | [upgrade])
1717
[-h, --help] ([-s, --silent] | [-v, --verbose])
1818
--------------------------------------------------
1919

@@ -26,6 +26,9 @@ IMPORTANT: This command should be run as the user that will run {es}.
2626
Currently, all secure settings are node-specific settings that must have the
2727
same value on every node. Therefore you must run this command on every node.
2828

29+
When the keystore is password-protected, you must supply the password each time
30+
{es} starts.
31+
2932
Modifications to the keystore do not take effect until you restart {es}.
3033

3134
Only some settings are designed to be read from the keystore. However, there
@@ -38,17 +41,36 @@ keystore, see the setting reference.
3841
=== Parameters
3942

4043
`add <setting>`:: Adds settings to the keystore. By default, you are prompted
41-
for the value of the setting.
44+
for the value of the setting. If the keystore is password protected, you are
45+
also prompted to enter the password. If the setting already exists in the
46+
keystore, you must confirm that you want to overwrite the current value. If the
47+
keystore does not exist, you must confirm that you want to create a keystore. To
48+
avoid these two confirmation prompts, use the `-f` parameter.
4249

4350
`add-file <setting> <path>`:: Adds a file to the keystore.
4451

4552
`create`:: Creates the keystore.
4653

54+
`-f`:: When used with the `add` parameter, the command no longer prompts you
55+
before overwriting existing entries in the keystore. Also, if you haven't
56+
created a keystore yet, it creates a keystore that is obfuscated but not
57+
password protected.
58+
4759
`-h, --help`:: Returns all of the command parameters.
4860

49-
`list`:: Lists the settings in the keystore.
61+
`list`:: Lists the settings in the keystore. If the keystore is password
62+
protected, you are prompted to enter the password.
63+
64+
`-p`:: When used with the `create` parameter, the command prompts you to enter a
65+
keystore password. If you don't specify the `-p` flag or if you enter an empty
66+
password, the keystore is obfuscated but not password protected.
67+
68+
`passwd`:: Changes or sets the keystore password. If the keystore is password
69+
protected, you are prompted to enter the current password and the new one. You
70+
can optionally use an empty string to remove the password. If the keystore is
71+
not password protected, you can use this command to set a password.
5072

51-
`remove <setting>:: Removes a setting from the keystore.
73+
`remove <setting>`:: Removes a setting from the keystore.
5274

5375
`-s, --silent`:: Shows minimal output.
5476

@@ -71,11 +93,26 @@ To create the `elasticsearch.keystore`, use the `create` command:
7193

7294
[source,sh]
7395
----------------------------------------------------------------
74-
bin/elasticsearch-keystore create
96+
bin/elasticsearch-keystore create -p
97+
----------------------------------------------------------------
98+
99+
You are prompted to enter the keystore password. A password-protected
100+
`elasticsearch.keystore` file is created alongside the `elasticsearch.yml` file.
101+
102+
[discrete]
103+
[[changing-keystore-password]]
104+
==== Change the password of the keystore
105+
106+
To change the password of the `elasticsearch.keystore`, use the `passwd` command:
107+
108+
[source,sh]
109+
----------------------------------------------------------------
110+
bin/elasticsearch-keystore passwd
75111
----------------------------------------------------------------
76112

77-
A `elasticsearch.keystore` file is created alongside the `elasticsearch.yml`
78-
file.
113+
If the {es} keystore is password protected, you are prompted to enter the
114+
current password and then enter the new one. If it is not password protected,
115+
you are prompted to set a password.
79116

80117
[discrete]
81118
[[list-settings]]
@@ -88,6 +125,9 @@ To list the settings in the keystore, use the `list` command.
88125
bin/elasticsearch-keystore list
89126
----------------------------------------------------------------
90127

128+
If the {es} keystore is password protected, you are prompted to enter the
129+
password.
130+
91131
[discrete]
92132
[[add-string-to-keystore]]
93133
==== Add settings to the keystore
@@ -100,8 +140,10 @@ can be added with the `add` command:
100140
bin/elasticsearch-keystore add the.setting.name.to.set
101141
----------------------------------------------------------------
102142

103-
You are prompted to enter the value of the setting. To pass the value
104-
through standard input (stdin), use the `--stdin` flag:
143+
You are prompted to enter the value of the setting. If the {es} keystore is
144+
password protected, you are also prompted to enter the password.
145+
146+
To pass the setting value through standard input (stdin), use the `--stdin` flag:
105147

106148
[source,sh]
107149
----------------------------------------------------------------
@@ -121,6 +163,9 @@ after the setting name.
121163
bin/elasticsearch-keystore add-file the.setting.name.to.set /path/example-file.json
122164
----------------------------------------------------------------
123165

166+
If the {es} keystore is password protected, you are prompted to enter the
167+
password.
168+
124169
[discrete]
125170
[[remove-settings]]
126171
==== Remove settings from the keystore
@@ -132,6 +177,9 @@ To remove a setting from the keystore, use the `remove` command:
132177
bin/elasticsearch-keystore remove the.setting.name.to.remove
133178
----------------------------------------------------------------
134179

180+
If the {es} keystore is password protected, you are prompted to enter the
181+
password.
182+
135183
[discrete]
136184
[[keystore-upgrade]]
137185
==== Upgrade the keystore

docs/reference/setup/install/docker.asciidoc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,25 @@ IMPORTANT: The container **runs {es} as user `elasticsearch` using
360360
uid:gid `1000:0`**. Bind mounted host directories and files must be accessible by this user,
361361
and the data and log directories must be writable by this user.
362362

363+
[[docker-keystore-bind-mount]]
364+
===== Mounting an {es} keystore
365+
366+
By default, {es} will auto-generate a keystore file for secure settings. This
367+
file is obfuscated but not encrypted. If you want to encrypt your
368+
<<secure-settings,secure settings>> with a password, you must use the
369+
`elasticsearch-keystore` utility to create a password-protected keystore and
370+
bind-mount it to the container as
371+
`/usr/share/elasticsearch/config/elasticsearch.keystore`. In order to provide
372+
the Docker container with the password at startup, set the Docker environment
373+
value `KEYSTORE_PASSWORD` to the value of your password. For example, a `docker
374+
run` command might have the following options:
375+
376+
[source, sh]
377+
--------------------------------------------
378+
-v full_path_to/elasticsearch.keystore:/usr/share/elasticsearch/config/elasticsearch.keystore
379+
-E KEYSTORE_PASSWORD=mypassword
380+
--------------------------------------------
381+
363382
[[_c_customized_image]]
364383
===== Using custom Docker images
365384
In some environments, it might make more sense to prepare a custom image that contains

docs/reference/setup/install/systemd.asciidoc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ These commands provide no feedback as to whether Elasticsearch was started
2121
successfully or not. Instead, this information will be written in the log
2222
files located in `/var/log/elasticsearch/`.
2323

24+
If you have password-protected your {es} keystore, you will need to provide
25+
`systemd` with the keystore password using a local file and systemd environment
26+
variables. This local file should be protected while it exists and may be
27+
safely deleted once Elasticsearch is up and running.
28+
29+
[source,sh]
30+
-----------------------------------------------------------------------------------
31+
echo "keystore_password" > /path/to/my_pwd_file.tmp
32+
chmod 600 /path/to/my_pwd_file.tmp
33+
sudo systemctl set-environment ES_KEYSTORE_PASSPHRASE_FILE=/path/to/my_pwd_file.tmp
34+
sudo systemctl start elasticsearch.service
35+
-----------------------------------------------------------------------------------
36+
2437
By default the Elasticsearch service doesn't log information in the `systemd`
2538
journal. To enable `journalctl` logging, the `--quiet` option must be removed
2639
from the `ExecStart` command line in the `elasticsearch.service` file.

docs/reference/setup/install/targz-daemon.asciidoc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ the process ID in a file using the `-p` option:
88
./bin/elasticsearch -d -p pid
99
--------------------------------------------
1010

11+
If you have password-protected the {es} keystore, you will be prompted
12+
to enter the keystore's password. See <<secure-settings>> for more
13+
details.
14+
1115
Log messages can be found in the `$ES_HOME/logs/` directory.
1216

1317
To shut down Elasticsearch, kill the process ID recorded in the `pid` file:
1418

1519
[source,sh]
1620
--------------------------------------------
17-
pkill -F pid
21+
pkill -F pid
1822
--------------------------------------------
1923

2024
NOTE: The startup scripts provided in the <<rpm,RPM>> and <<deb,Debian>>

docs/reference/setup/install/targz-start.asciidoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ Elasticsearch can be started from the command line as follows:
77
./bin/elasticsearch
88
--------------------------------------------
99

10+
If you have password-protected the {es} keystore, you will be prompted
11+
to enter the keystore's password. See <<secure-settings>> for more
12+
details.
13+
1014
By default, Elasticsearch runs in the foreground, prints its logs to the
1115
standard output (`stdout`), and can be stopped by pressing `Ctrl-C`.
1216

docs/reference/setup/install/zip-windows-start.asciidoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ Elasticsearch can be started from the command line as follows:
77
.\bin\elasticsearch.bat
88
--------------------------------------------
99

10+
If you have password-protected the {es} keystore, you will be prompted to
11+
enter the keystore's password. See <<secure-settings>> for more details.
12+
1013
By default, Elasticsearch runs in the foreground, prints its logs to `STDOUT`,
1114
and can be stopped by pressing `Ctrl-C`.

0 commit comments

Comments
 (0)