backup-and-restore-security-config.asciidoc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. Security configuration information resides in two places:
  9. <<backup-security-file-based-configuration,files>> and
  10. <<backup-security-index-configuration,indices>>.
  11. [discrete]
  12. [[backup-security-file-based-configuration]]
  13. ==== Back up file-based security configuration
  14. {es} {security-features} are configured using the <<security-settings,
  15. `xpack.security` namespace>> inside the `elasticsearch.yml` and
  16. `elasticsearch.keystore` files. In addition there are several other
  17. <<security-files, extra configuration files>> inside the same `ES_PATH_CONF`
  18. directory. These files define roles and role mappings and
  19. <<configuring-file-realm, configure the file realm>>. Some of the
  20. settings specify file paths to security-sensitive data, such as TLS keys and
  21. certificates for the HTTP client and inter-node communication and private key files for
  22. <<ref-saml-settings, SAML>>, <<ref-oidc-settings, OIDC>> and the
  23. <<ref-kerberos-settings, Kerberos>> realms. All these are also stored inside
  24. `ES_PATH_CONF`; the path settings are relative.
  25. IMPORTANT: The `elasticsearch.keystore`, TLS keys and SAML, OIDC, and Kerberos
  26. realms private key files require confidentiality. This is crucial when files
  27. are copied to the backup location, as this increases the surface for malicious
  28. snooping.
  29. To back up all this configuration you can use a <<backup-cluster-configuration,
  30. conventional file-based backup>>, as described in the previous section.
  31. [NOTE]
  32. ====
  33. * File backups must run on every cluster node.
  34. * File backups will store non-security configuration as well. Backing-up
  35. only {security-features} configuration is not supported. A backup is a
  36. point in time record of state of the complete configuration.
  37. ====
  38. [discrete]
  39. [[backup-security-index-configuration]]
  40. ==== Back up index-based security configuration
  41. {es} {security-features} store system configuration data inside a
  42. dedicated index. This index is named `.security-6` in the {es} 6.x versions and
  43. `.security-7` in the 7.x releases. The `.security` alias always points to the
  44. appropriate index. This index contains the data which is not available in
  45. configuration files and *cannot* be reliably backed up using standard
  46. filesystem tools. This data describes:
  47. * the definition of users in the native realm (including hashed passwords)
  48. * role definitions (defined via the <<security-api-put-role,create roles API>>)
  49. * role mappings (defined via the
  50. <<security-api-put-role-mapping,create role mappings API>>)
  51. * application privileges
  52. * API keys
  53. The `.security` index thus contains resources and definitions in addition to
  54. configuration information. All of that information is required in a complete
  55. {security-features} backup.
  56. Use the <<modules-snapshots, standard {es} snapshot functionality>> to backup
  57. `.security`, as you would for any <<backup-cluster-data, other data index>>.
  58. For convenience, here are the complete steps:
  59. . Create a repository that you can use to backup the `.security` index.
  60. It is preferable to have a <<backup-security-repos, dedicated repository>> for
  61. this special index. If you wish, you can also snapshot the system indices for other {stack} components to this repository.
  62. +
  63. --
  64. [source,js]
  65. -----------------------------------
  66. PUT /_snapshot/my_backup
  67. {
  68. "type": "fs",
  69. "settings": {
  70. "location": "my_backup_location"
  71. }
  72. }
  73. -----------------------------------
  74. // CONSOLE
  75. The user calling this API must have the elevated `manage` cluster privilege to
  76. prevent non-administrators exfiltrating data.
  77. --
  78. . Create a user and assign it only the built-in `snapshot_user` role.
  79. +
  80. --
  81. The following example creates a new user `snapshot_user` in the
  82. {stack-ov}/native-realm.html[native realm], but it is not important which
  83. realm the user is a member of:
  84. [source,js]
  85. --------------------------------------------------
  86. POST /_security/user/snapshot_user
  87. {
  88. "password" : "secret",
  89. "roles" : [ "snapshot_user" ]
  90. }
  91. --------------------------------------------------
  92. // CONSOLE
  93. // TEST[skip:security is not enabled in this fixture]
  94. --
  95. . Create incremental snapshots authorized as `snapshot_user`.
  96. +
  97. --
  98. The following example shows how to use the create snapshot API to backup
  99. the `.security` index to the `my_backup` repository:
  100. [source,js]
  101. --------------------------------------------------
  102. PUT /_snapshot/my_backup/snapshot_1
  103. {
  104. "indices": ".security",
  105. "include_global_state": true <1>
  106. }
  107. --------------------------------------------------
  108. // CONSOLE
  109. // TEST[continued]
  110. <1> This parameter value captures all the persistent settings stored in the
  111. global cluster metadata as well as other configurations such as aliases and
  112. stored scripts. Note that this includes non-security configuration and that it complements but does not replace the
  113. <<backup-cluster-configuration, filesystem configuration files backup>>.
  114. --
  115. IMPORTANT: The index format is only compatible within a single major version,
  116. and cannot be restored onto a version earlier than the version from which it
  117. originated. For example, you can restore a security snapshot from 6.6.0 into a
  118. 6.7.0 cluster, but you cannot restore it to a cluster running {es} 6.5.0 or 7.0.0.
  119. [discrete]
  120. [[backup-security-repos]]
  121. ===== Controlling access to the backup repository
  122. The snapshot of the security index will typically contain sensitive data such
  123. as user names and password hashes. Because passwords are stored using
  124. <<hashing-settings, cryptographic hashes>>, the disclosure of a snapshot would
  125. not automatically enable a third party to authenticate as one of your users or
  126. use API keys. However, it would disclose confidential information.
  127. It is also important that you protect the integrity of these backups in case
  128. you ever need to restore them. If a third party is able to modify the stored
  129. backups, they may be able to install a back door that would grant access if the
  130. snapshot is loaded into an {es} cluster.
  131. We recommend that you:
  132. * Snapshot the `.security` index in a dedicated repository, where read and write
  133. access is strictly restricted and audited.
  134. * If there are indications that the snapshot has been read, change the passwords
  135. of the users in the native realm and revoke API keys.
  136. * If there are indications that the snapshot has been tampered with, do not
  137. restore it. There is currently no option for the restore process to detect
  138. malicious tampering.
  139. [[restore-security-configuration]]
  140. === Restore a cluster's security configuration
  141. ++++
  142. <titleabbrev>Restore the security configuration</titleabbrev>
  143. ++++
  144. NOTE: You can restore a snapshot of the `.security` index only if it was
  145. created in a previous minor version in the same major version. The last minor
  146. version of every major release can convert and read formats of the index for
  147. both its major version and the next one.
  148. When you restore security configuration you have the option of doing a complete
  149. restore of *all* configurations, including non-security ones, or to only restore
  150. the contents of the `.security` index. As described in
  151. <<backup-security-index-configuration>>, the second option comprises only
  152. resource-type configurations. The first option has the advantage of restoring
  153. a cluster to a clearly defined state from a past point in time. The second option
  154. touches only security configuration resources, but it does not completely restore
  155. the {security-features}.
  156. To restore your security configuration from a backup, first make sure that the
  157. repository holding `.security` snapshots is installed:
  158. [source,js]
  159. --------------------------------------------------
  160. GET /_snapshot/my_backup
  161. --------------------------------------------------
  162. // CONSOLE
  163. // TEST[continued]
  164. [source,js]
  165. --------------------------------------------------
  166. GET /_snapshot/my_backup/snapshot_1
  167. --------------------------------------------------
  168. // CONSOLE
  169. // TEST[continued]
  170. Then log into one of the node hosts, navigate to {es} installation directory,
  171. and follow these steps:
  172. . Add a new user with the `superuser` built-in role to the
  173. {stack-ov}/file-realm.html[file realm].
  174. +
  175. --
  176. For example, create a user named `restore_user`:
  177. [source,shell]
  178. --------------------------------------------------
  179. bin/elasticsearch-users useradd restore_user -p password -r superuser
  180. --------------------------------------------------
  181. --
  182. . Using the previously created user, delete the existing `.security-6` or
  183. `.security-7` index.
  184. +
  185. --
  186. [source,shell]
  187. --------------------------------------------------
  188. curl -u restore_user -X DELETE "localhost:9200/.security-*"
  189. --------------------------------------------------
  190. // NOTCONSOLE
  191. WARNING: After this step any authentication that relies on the `.security`
  192. index will not work. This means that all API calls that authenticate with
  193. native or reserved users will fail, as will any user that relies on a native role.
  194. The file realm user we created in the step above will continue to work
  195. because it is not stored in the `.security` index and uses the built-in
  196. `superuser` role.
  197. --
  198. . Using the same user, restore the `.security` index from the snapshot.
  199. +
  200. --
  201. [source,shell]
  202. --------------------------------------------------
  203. curl -u restore_user -X POST "localhost:9200/_snapshot/my_backup/snapshot_1/_restore" -H 'Content-Type: application/json' -d'
  204. {
  205. "indices": ".security-*",
  206. "include_global_state": true <1>
  207. }
  208. '
  209. --------------------------------------------------
  210. // NOTCONSOLE
  211. <1> The `include_global_state: true` is mandatory only for a complete restore.
  212. This will restore the global cluster metadata, which contains configuration
  213. information for the complete cluster. If you set this to `false`, it recovers
  214. only the contents of the `.security` index, such as usernames and password
  215. hashes, API keys, application privileges, role and role mapping definitions.
  216. --
  217. . Optionally, if you need to review and override the settings that were included
  218. in the snapshot (by the `include_global_state` flag), cherry-pick and
  219. <<cluster-update-settings,apply the persistent settings>> that you
  220. <<backup-cluster-configuration, have extracted>> with the
  221. `GET _cluster/settings` API.
  222. . If you pursue a complete point in time restore of the cluster, you also have
  223. to restore configuration files. Again, this will restore non-security settings as
  224. well.
  225. +
  226. --
  227. This entails a straight-up filesystem copy of the backed up configuration files,
  228. overwriting the contents of `$ES_PATH_CONF`, and restarting the node. This
  229. needs to be done on *every node*. Depending on the extent of the differences
  230. between your current cluster configuration and the restored configuration, you
  231. may not be able to perform a rolling restart. If you are performing a full
  232. restore of your configuration directory, we recommend a full cluster restart as
  233. the safest option. Alternatively, you may wish to restore your configuration
  234. files to a separate location on disk and use file comparison tools to review
  235. the differences between your existing configuration and the restored
  236. configuration.
  237. --