|
| 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 | +-- |
0 commit comments