Skip to content

Commit 018d946

Browse files
albertzaharovitslcawltvernum
committed
[DOC] Backup & Restore Security Configuration (#42970)
This commit documents the backup and restore of a cluster's security configuration. It is not possible to only backup (or only restore) security configuration, independent to the rest of the cluster's conf, so this describes how a full configuration backup&restore will include security as well. Moreover, it explains how part of the security conf data resides on the special .security index and how to backup that using regular data snapshot API. Co-Authored-By: Lisa Cawley <[email protected]> Co-Authored-By: Tim Vernum <[email protected]>
1 parent 9567f33 commit 018d946

File tree

8 files changed

+423
-17
lines changed

8 files changed

+423
-17
lines changed

docs/reference/administering.asciidoc

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,4 @@ cluster.
99

1010
--
1111

12-
[[backup-cluster]]
13-
== Back up a cluster
14-
15-
As with any software that stores data, it is important to routinely back up your
16-
data. {es} replicas provide high availability during runtime; they enable you to
17-
tolerate sporadic node loss without an interruption of service.
18-
19-
Replicas do not provide protection from catastrophic failure, however. For that,
20-
you need a real backup of your cluster—a complete copy in case something goes
21-
wrong.
22-
23-
To back up your cluster, you can use the <<modules-snapshots,snapshot API>>.
24-
25-
include::{es-repo-dir}/modules/snapshots.asciidoc[tag=snapshot-intro]
12+
include::administering/backup-cluster.asciidoc[]
Lines changed: 281 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
1+
[role="xpack"]
2+
[testenv="basic"]
3+
[[security-backup]]
4+
=== Back up a cluster's security configuration
5+
++++
6+
<titleabbrev>Back up the security configuration</titleabbrev>
7+
++++
8+
9+
Security configuration information resides in two places:
10+
<<backup-security-file-based-configuration,files>> and
11+
<<backup-security-index-configuration,indices>>.
12+
13+
[discrete]
14+
[[backup-security-file-based-configuration]]
15+
==== Back up file-based security configuration
16+
17+
{es} {security-features} are configured using the <<security-settings,
18+
`xpack.security` namespace>> inside the `elasticsearch.yml` and
19+
`elasticsearch.keystore` files. In addition there are several other
20+
<<security-files, extra configuration files>> inside the same `ES_PATH_CONF`
21+
directory. These files define roles and role mappings and
22+
<<configuring-file-realm, configure the file realm>>. Some of the
23+
settings specify file paths to security-sensitive data, such as TLS keys and
24+
certificates for the HTTP client and inter-node communication and private key files for
25+
<<ref-saml-settings, SAML>>, <<ref-oidc-settings, OIDC>> and the
26+
<<ref-kerberos-settings, Kerberos>> realms. All these are also stored inside
27+
`ES_PATH_CONF`; the path settings are relative.
28+
29+
IMPORTANT: The `elasticsearch.keystore`, TLS keys and SAML, OIDC, and Kerberos
30+
realms private key files require confidentiality. This is crucial when files
31+
are copied to the backup location, as this increases the surface for malicious
32+
snooping.
33+
34+
To back up all this configuration you can use a <<backup-cluster-configuration,
35+
conventional file-based backup>>, as described in the previous section.
36+
37+
[NOTE]
38+
====
39+
40+
* File backups must run on every cluster node.
41+
* File backups will store non-security configuration as well. Backing-up
42+
only {security-features} configuration is not supported. A backup is a
43+
point in time record of state of the complete configuration.
44+
45+
====
46+
47+
[discrete]
48+
[[backup-security-index-configuration]]
49+
==== Back up index-based security configuration
50+
51+
{es} {security-features} store system configuration data inside a
52+
dedicated index. This index is named `.security-6` in the {es} 6.x versions and
53+
`.security-7` in the 7.x releases. The `.security` alias always points to the
54+
appropriate index. This index contains the data which is not available in
55+
configuration files and *cannot* be reliably backed up using standard
56+
filesystem tools. This data describes:
57+
58+
* the definition of users in the native realm (including hashed passwords)
59+
* role definitions (defined via the <<security-api-put-role,create roles API>>)
60+
* role mappings (defined via the
61+
<<security-api-put-role-mapping,create role mappings API>>)
62+
* application privileges
63+
* API keys
64+
65+
The `.security` index thus contains resources and definitions in addition to
66+
configuration information. All of that information is required in a complete
67+
{security-features} backup.
68+
69+
Use the <<modules-snapshots, standard {es} snapshot functionality>> to backup
70+
`.security`, as you would for any <<backup-cluster-data, other data index>>.
71+
For convenience, here are the complete steps:
72+
73+
. Create a repository that you can use to backup the `.security` index.
74+
It is preferable to have a <<backup-security-repos, dedicated repository>> for
75+
this special index. If you wish, you can also snapshot the system indices for other {stack} components to this repository.
76+
+
77+
--
78+
[source,js]
79+
-----------------------------------
80+
PUT /_snapshot/my_backup
81+
{
82+
"type": "fs",
83+
"settings": {
84+
"location": "my_backup_location"
85+
}
86+
}
87+
-----------------------------------
88+
// CONSOLE
89+
90+
The user calling this API must have the elevated `manage` cluster privilege to
91+
prevent non-administrators exfiltrating data.
92+
93+
--
94+
95+
. Create a user and assign it only the built-in `snapshot_user` role.
96+
+
97+
--
98+
The following example creates a new user `snapshot_user` in the
99+
{stack-ov}/native-realm.html[native realm], but it is not important which
100+
realm the user is a member of:
101+
102+
[source,js]
103+
--------------------------------------------------
104+
POST /_security/user/snapshot_user
105+
{
106+
"password" : "secret",
107+
"roles" : [ "snapshot_user" ]
108+
}
109+
--------------------------------------------------
110+
// CONSOLE
111+
// TEST[skip:security is not enabled in this fixture]
112+
113+
--
114+
115+
. Create incremental snapshots authorized as `snapshot_user`.
116+
+
117+
--
118+
The following example shows how to use the create snapshot API to backup
119+
the `.security` index to the `my_backup` repository:
120+
121+
[source,js]
122+
--------------------------------------------------
123+
PUT /_snapshot/my_backup/snapshot_1
124+
{
125+
"indices": ".security",
126+
"include_global_state": true <1>
127+
}
128+
--------------------------------------------------
129+
// CONSOLE
130+
// TEST[continued]
131+
132+
<1> This parameter value captures all the persistent settings stored in the
133+
global cluster metadata as well as other configurations such as aliases and
134+
stored scripts. Note that this includes non-security configuration and that it complements but does not replace the
135+
<<backup-cluster-configuration, filesystem configuration files backup>>.
136+
137+
--
138+
139+
IMPORTANT: The index format is only compatible within a single major version,
140+
and cannot be restored onto a version earlier than the version from which it
141+
originated. For example, you can restore a security snapshot from 6.6.0 into a
142+
6.7.0 cluster, but you cannot restore it to a cluster running {es} 6.5.0 or 7.0.0.
143+
144+
[discrete]
145+
[[backup-security-repos]]
146+
===== Controlling access to the backup repository
147+
148+
The snapshot of the security index will typically contain sensitive data such
149+
as user names and password hashes. Because passwords are stored using
150+
<<hashing-settings, cryptographic hashes>>, the disclosure of a snapshot would
151+
not automatically enable a third party to authenticate as one of your users or
152+
use API keys. However, it would disclose confidential information.
153+
154+
It is also important that you protect the integrity of these backups in case
155+
you ever need to restore them. If a third party is able to modify the stored
156+
backups, they may be able to install a back door that would grant access if the
157+
snapshot is loaded into an {es} cluster.
158+
159+
We recommend that you:
160+
161+
* Snapshot the `.security` index in a dedicated repository, where read and write
162+
access is strictly restricted and audited.
163+
* If there are indications that the snapshot has been read, change the passwords
164+
of the users in the native realm and revoke API keys.
165+
* If there are indications that the snapshot has been tampered with, do not
166+
restore it. There is currently no option for the restore process to detect
167+
malicious tampering.
168+
169+
[[restore-security-configuration]]
170+
=== Restore a cluster's security configuration
171+
++++
172+
<titleabbrev>Restore the security configuration</titleabbrev>
173+
++++
174+
175+
NOTE: You can restore a snapshot of the `.security` index only if it was
176+
created in a previous minor version in the same major version. The last minor
177+
version of every major release can convert and read formats of the index for
178+
both its major version and the next one.
179+
180+
When you restore security configuration you have the option of doing a complete
181+
restore of *all* configurations, including non-security ones, or to only restore
182+
the contents of the `.security` index. As described in
183+
<<backup-security-index-configuration>>, the second option comprises only
184+
resource-type configurations. The first option has the advantage of restoring
185+
a cluster to a clearly defined state from a past point in time. The second option
186+
touches only security configuration resources, but it does not completely restore
187+
the {security-features}.
188+
189+
To restore your security configuration from a backup, first make sure that the
190+
repository holding `.security` snapshots is installed:
191+
192+
[source,js]
193+
--------------------------------------------------
194+
GET /_snapshot/my_backup
195+
--------------------------------------------------
196+
// CONSOLE
197+
// TEST[continued]
198+
199+
[source,js]
200+
--------------------------------------------------
201+
GET /_snapshot/my_backup/snapshot_1
202+
--------------------------------------------------
203+
// CONSOLE
204+
// TEST[continued]
205+
206+
Then log into one of the node hosts, navigate to {es} installation directory,
207+
and follow these steps:
208+
209+
. Add a new user with the `superuser` built-in role to the
210+
{stack-ov}/file-realm.html[file realm].
211+
+
212+
--
213+
For example, create a user named `restore_user`:
214+
[source,shell]
215+
--------------------------------------------------
216+
bin/elasticsearch-users useradd restore_user -p password -r superuser
217+
--------------------------------------------------
218+
--
219+
220+
. Using the previously created user, delete the existing `.security-6` or
221+
`.security-7` index.
222+
+
223+
--
224+
[source,shell]
225+
--------------------------------------------------
226+
curl -u restore_user -X DELETE "localhost:9200/.security-*"
227+
--------------------------------------------------
228+
// NOTCONSOLE
229+
230+
WARNING: After this step any authentication that relies on the `.security`
231+
index will not work. This means that all API calls that authenticate with
232+
native or reserved users will fail, as will any user that relies on a native role.
233+
The file realm user we created in the step above will continue to work
234+
because it is not stored in the `.security` index and uses the built-in
235+
`superuser` role.
236+
237+
--
238+
239+
. Using the same user, restore the `.security` index from the snapshot.
240+
+
241+
--
242+
[source,shell]
243+
--------------------------------------------------
244+
curl -u restore_user -X POST "localhost:9200/_snapshot/my_backup/snapshot_1/_restore" -H 'Content-Type: application/json' -d'
245+
{
246+
"indices": ".security-*",
247+
"include_global_state": true <1>
248+
}
249+
'
250+
--------------------------------------------------
251+
// NOTCONSOLE
252+
253+
<1> The `include_global_state: true` is mandatory only for a complete restore.
254+
This will restore the global cluster metadata, which contains configuration
255+
information for the complete cluster. If you set this to `false`, it recovers
256+
only the contents of the `.security` index, such as usernames and password
257+
hashes, API keys, application privileges, role and role mapping definitions.
258+
--
259+
260+
. Optionally, if you need to review and override the settings that were included
261+
in the snapshot (by the `include_global_state` flag), cherry-pick and
262+
<<cluster-update-settings,apply the persistent settings>> that you
263+
<<backup-cluster-configuration, have extracted>> with the
264+
`GET _cluster/settings` API.
265+
266+
. If you pursue a complete point in time restore of the cluster, you also have
267+
to restore configuration files. Again, this will restore non-security settings as
268+
well.
269+
+
270+
--
271+
This entails a straight-up filesystem copy of the backed up configuration files,
272+
overwriting the contents of `$ES_PATH_CONF`, and restarting the node. This
273+
needs to be done on *every node*. Depending on the extent of the differences
274+
between your current cluster configuration and the restored configuration, you
275+
may not be able to perform a rolling restart. If you are performing a full
276+
restore of your configuration directory, we recommend a full cluster restart as
277+
the safest option. Alternatively, you may wish to restore your configuration
278+
files to a separate location on disk and use file comparison tools to review
279+
the differences between your existing configuration and the restored
280+
configuration.
281+
--
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
[[backup-cluster-configuration]]
2+
=== Back up a cluster's configuration
3+
++++
4+
<titleabbrev>Back up the cluster configuration</titleabbrev>
5+
++++
6+
7+
In addition to backing up the data in a cluster, it is important to back up its configuration--especially when the cluster becomes large and difficult to
8+
reconstruct.
9+
10+
Configuration information resides in
11+
<<config-files-location, regular text files>> on every cluster node. Sensitive
12+
setting values such as passwords for the {watcher} notification servers, are
13+
specified inside a binary secure container, the
14+
<<secure-settings, elasticsearch.keystore>> file. Some setting values are
15+
file paths to the associated configuration data, such as the ingest geo ip
16+
database. All these files are contained inside the `ES_PATH_CONF` directory.
17+
18+
NOTE: All changes to configuration files are done by manually editing the files
19+
or using command line utilities, but *not* through APIs. In practice, these
20+
changes are infrequent after the initial setup.
21+
22+
We recommend that you take regular (ideally, daily) backups of your {es} config
23+
(`$ES_PATH_CONF`) directory using the file backup software of your choice.
24+
25+
TIP: We recommend that you have a configuration management plan for these
26+
configuration files. You may wish to check them into version control, or
27+
provision them though your choice of configuration management tool.
28+
29+
Some of these files may contain sensitive data such as passwords and TLS keys,
30+
therefore you should investigate whether your backup software and/or storage
31+
solution are able to encrypt this data.
32+
33+
Some settings in configuration files might be overridden by
34+
<<cluster-update-settings,cluster settings>>. You can capture these settings in
35+
a *data* backup snapshot by specifying the `include_global_state: true` (default)
36+
parameter for the snapshot API. Alternatively, you can extract these
37+
configuration values in text format by using the
38+
<<cluster-get-settings, get settings API>>:
39+
40+
[source,js]
41+
--------------------------------------------------
42+
GET _cluster/settings?pretty&flat_settings&filter_path=persistent
43+
--------------------------------------------------
44+
//CONSOLE
45+
//TEST
46+
47+
You can store the output of this as a file together with the rest of
48+
configuration files.
49+
50+
[NOTE]
51+
====
52+
53+
* Transient settings are not considered for backup.
54+
* {es} {security-features} store configuration data such as role definitions and
55+
API keys inside a dedicate special index. This "system" data,
56+
complements the <<secure-settings, security settings>> configuration and should
57+
be <<backup-security-index-configuration, backed up as well>>.
58+
* Other {stack} components, like Kibana and {ml-cap}, store their configuration
59+
data inside other dedicated indices. From the {es} perspective these are just data
60+
so you can use the regular <<backup-cluster-data, data backup>> process.
61+
62+
====

0 commit comments

Comments
 (0)