| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 | [role="xpack"][testenv="basic"][[security-backup]]=== Back up a cluster's security configuration++++<titleabbrev>Back up the security configuration</titleabbrev>++++Security configuration information resides in two places:<<backup-security-file-based-configuration,files>> and<<backup-security-index-configuration,indices>>.[discrete][[backup-security-file-based-configuration]]==== Back up file-based security configuration{es} {security-features} are configured using the <<security-settings,`xpack.security` namespace>> inside the `elasticsearch.yml` and`elasticsearch.keystore` files. In addition there are several other<<security-files, extra configuration files>> inside the same `ES_PATH_CONF`directory. These files define roles and role mappings and configure the<<file-realm,file realm>>. Some of thesettings specify file paths to security-sensitive data, such as TLS keys andcertificates for the HTTP client and inter-node communication and private key files for<<ref-saml-settings, SAML>>, <<ref-oidc-settings, OIDC>> and the<<ref-kerberos-settings, Kerberos>> realms. All these are also stored inside`ES_PATH_CONF`; the path settings are relative.IMPORTANT: The `elasticsearch.keystore`, TLS keys and SAML, OIDC, and Kerberosrealms private key files require confidentiality. This is crucial when filesare copied to the backup location, as this increases the surface for malicioussnooping.To back up all this configuration you can use a <<backup-cluster-configuration,conventional file-based backup>>, as described in the previous section.[NOTE]====* File backups must run on every cluster node.* File backups will store non-security configuration as well. Backing-uponly {security-features} configuration is not supported. A backup is apoint in time record of state of the complete configuration.====[discrete][[backup-security-index-configuration]]==== Back up index-based security configuration{es} {security-features} store system configuration data inside adedicated index. This index is named `.security-6` in the {es} 6.x versions and`.security-7` in the 7.x releases. The `.security` alias always points to theappropriate index. This index contains the data which is not available inconfiguration files and *cannot* be reliably backed up using standardfilesystem tools. This data describes:* the definition of users in the native realm (including hashed passwords)* role definitions (defined via the <<security-api-put-role,create roles API>>)* role mappings (defined via the  <<security-api-put-role-mapping,create role mappings API>>)* application privileges* API keysThe `.security` index thus contains resources and definitions in addition toconfiguration information. All of that information is required in a complete{security-features} backup.Use the <<modules-snapshots, standard {es} snapshot functionality>> to backup`.security`, as you would for any <<backup-cluster-data, other data index>>.For convenience, here are the complete steps:. Create a repository that you can use to backup the `.security` index.It is preferable to have a <<backup-security-repos, dedicated repository>> forthis special index. If you wish, you can also snapshot the system indices for other {stack} components to this repository. +--[source,console]-----------------------------------PUT /_snapshot/my_backup{  "type": "fs",  "settings": {    "location": "my_backup_location"  }}-----------------------------------The user calling this API must have the elevated `manage` cluster privilege toprevent non-administrators exfiltrating data.--. Create a user and assign it only the built-in `snapshot_user` role.+--The following example creates a new user `snapshot_user` in the<<native-realm,native realm>>, but it is not important whichrealm the user is a member of:[source,console]--------------------------------------------------POST /_security/user/snapshot_user{  "password" : "secret",  "roles" : [ "snapshot_user" ]}--------------------------------------------------// TEST[skip:security is not enabled in this fixture]--. Create incremental snapshots authorized as `snapshot_user`.+--The following example shows how to use the create snapshot API to backupthe `.security` index to the `my_backup` repository:[source,console]--------------------------------------------------PUT /_snapshot/my_backup/snapshot_1{  "indices": ".security",  "include_global_state": true <1>}--------------------------------------------------// TEST[continued]<1> This parameter value captures all the persistent settings stored in theglobal cluster metadata as well as other configurations such as aliases andstored scripts. Note that this includes non-security configuration and that it complements but does not replace the<<backup-cluster-configuration, filesystem configuration files backup>>.--IMPORTANT: The index format is only compatible within a single major version,and cannot be restored onto a version earlier than the version from which itoriginated. For example, you can restore a security snapshot from 6.6.0 into a6.7.0 cluster, but you cannot restore it to a cluster running {es} 6.5.0 or 7.0.0.[discrete][[backup-security-repos]]===== Controlling access to the backup repositoryThe snapshot of the security index will typically contain sensitive data suchas user names and password hashes. Because passwords are stored using<<hashing-settings, cryptographic hashes>>, the disclosure of a snapshot wouldnot automatically enable a third party to authenticate as one of your users oruse API keys. However, it would disclose confidential information.It is also important that you protect the integrity of these backups in caseyou ever need to restore them. If a third party is able to modify the storedbackups, they may be able to install a back door that would grant access if thesnapshot is loaded into an {es} cluster.We recommend that you:* Snapshot the `.security` index in a dedicated repository, where read and writeaccess is strictly restricted and audited.* If there are indications that the snapshot has been read, change the passwordsof the users in the native realm and revoke API keys.* If there are indications that the snapshot has been tampered with, do notrestore it. There is currently no option for the restore process to detectmalicious tampering.[[restore-security-configuration]]=== Restore a cluster's security configuration++++<titleabbrev>Restore the security configuration</titleabbrev>++++NOTE: You can restore a snapshot of the `.security` index only if it wascreated in a previous minor version in the same major version. The last minorversion of every major release can convert and read formats of the index forboth its major version and the next one.When you restore security configuration you have the option of doing a completerestore of *all* configurations, including non-security ones, or to only restorethe contents of the `.security` index. As described in<<backup-security-index-configuration>>, the second option comprises onlyresource-type configurations. The first option has the advantage of restoringa cluster to a clearly defined state from a past point in time. The second optiontouches only security configuration resources, but it does not completely restorethe {security-features}.To restore your security configuration from a backup, first make sure that therepository holding `.security` snapshots is installed:[source,console]--------------------------------------------------GET /_snapshot/my_backup--------------------------------------------------// TEST[continued][source,console]--------------------------------------------------GET /_snapshot/my_backup/snapshot_1--------------------------------------------------// TEST[continued]Then log into one of the node hosts, navigate to {es} installation directory,and follow these steps:. Add a new user with the `superuser` built-in role to the<<file-realm,file realm>>.+--For example, create a user named `restore_user`:[source,shell]--------------------------------------------------bin/elasticsearch-users useradd restore_user -p password -r superuser----------------------------------------------------. Using the previously created user, delete the existing `.security-6` or`.security-7` index.+--[source,shell]--------------------------------------------------curl -u restore_user -X DELETE "localhost:9200/.security-*"--------------------------------------------------// NOTCONSOLEWARNING: After this step any authentication that relies on the `.security`index will not work. This means that all API calls that authenticate withnative or reserved users will fail, as will any user that relies on a native role.The file realm user we created in the step above will continue to workbecause it is not stored in the `.security` index and uses the built-in`superuser` role.--. Using the same user, restore the `.security` index from the snapshot.+--[source,shell]-------------------------------------------------- curl -u restore_user -X POST "localhost:9200/_snapshot/my_backup/snapshot_1/_restore" -H 'Content-Type: application/json' -d' {    "indices": ".security-*",    "include_global_state": true <1> } '--------------------------------------------------// NOTCONSOLE<1> The `include_global_state: true` is mandatory only for a complete restore.This will restore the global cluster metadata, which contains configurationinformation for the complete cluster. If you set this to `false`, it recoversonly the contents of the `.security` index, such as usernames and passwordhashes, API keys, application privileges, role and role mapping definitions.--. Optionally, if you need to review and override the settings that were includedin the snapshot (by the `include_global_state` flag), cherry-pick and<<cluster-update-settings,apply the persistent settings>> that you<<backup-cluster-configuration, have extracted>> with the`GET _cluster/settings` API.. If you pursue a complete point in time restore of the cluster, you also haveto restore configuration files. Again, this will restore non-security settings aswell.+--This entails a straight-up filesystem copy of the backed up configuration files,overwriting the contents of `$ES_PATH_CONF`, and restarting the node. Thisneeds to be done on *every node*. Depending on the extent of the differencesbetween your current cluster configuration and the restored configuration, youmay not be able to perform a rolling restart. If you are performing a fullrestore of your configuration directory, we recommend a full cluster restart asthe safest option. Alternatively, you may wish to restore your configurationfiles to a separate location on disk and use file comparison tools to reviewthe differences between your existing configuration and the restoredconfiguration.--
 |