Operations

[Enterprise] Disaster Recovery Replication Setup

It is inevitable for organizations to have a disaster recovery (DR) strategy to protect their Vault deployment against catastrophic failure of an entire cluster. Vault Enterprise supports multi-datacenter deployment where you can replicate data across datacenters for performance as well as disaster recovery.

A cluster is the basic unit of Vault Enterprise replication which follows the leader-follower model. A leader cluster is referred to as the primary cluster and is considered the system of record. Data is streamed from the primary cluster to all secondary (follower) clusters.

Replication Pattern

The Mount Filter guide provides step-by-step instructions on setting up performance replication. This guide focuses on DR replication setup.

» Prerequisites

This intermediate Vault operations guide assumes that you have some working knowledge of Vault.

You need two Vault Enterprise clusters: one behaves as the primary cluster, and another becomes the secondary.

DR Prerequisites

» Steps

This guide walk through the following operations:

  1. Enable DR Primary Replication
  2. Enable DR Secondary Replication
  3. Promote DR Secondary to Primary
  4. Demote DR Primary to Secondary
  5. Disable DR Primary

» Step 1: Enable DR Primary Replication

CLI command / API call using cURL / Web UI

» CLI command

Enable DR replication on the primary cluster.

$ vault write -f sys/replication/dr/primary/enable
WARNING! The following warnings were returned from Vault:

* This cluster is being enabled as a primary for replication. Vault will be
unavailable for a brief period and will resume service shortly.

Generate a secondary token.

$ vault write sys/replication/dr/primary/secondary-token id="secondary"

The output should look similar to:

Key                              Value
---                              -----
wrapping_token:                  eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXVCJ9.eyJhZGRyIjoiaHR0cDovLzEzLjU3LjIwLjQxOjgyMDAiLCJleHAiOjE1MjkzMzkzMzEsImlhdCI6MTUyOTMzNzUzMSwianRpIjoiZDZmMmMzZTItMTZjNS1mNTU0LWYxMzAtNzMzZDE0OWNiNTIzIiwidHlwZSI6IndyYXBwaW5nIn0.MIGIAkIArsC3s1x7GYnEbaYwAbYUj-Wgp4B3Q3kVXL0BbaKvsECySV4Pwtm--i24OSQfI9zAlsG8ZypOWJdngRa59wlhWdQCQgG22-I-aNWPehjsqmwwEADU-u37LUrR6O0MsUCqtfWYwIM9o7PFP1wMZ4JwDGftQXUH6hIrkXZDxnnGsSCJ1Vl75w
wrapping_accessor:               bab0ea36-23f6-d21d-4ca6-a9c3673766a3
wrapping_token_ttl:              30m
wrapping_token_creation_time:    2018-06-18 15:58:51.645117216 +0000 UTC
wrapping_token_creation_path:    sys/replication/dr/primary/secondary-token

» API call using cURL

Enable DR replication on the primary cluster by invoking /sys/replication/dr/primary/enable endpoint.

Example:

$ curl --header "X-Vault-Token: ..." \
      --request POST \
      --data '{}' \
      https://cluster-A.example.com:8200/v1/sys/replication/dr/primary/enable

{
  "request_id": "ef38af20-9c1f-138a-2d03-bbb6410fb0fc",
  "lease_id": "",
  "renewable": false,
  "lease_duration": 0,
  "data": null,
  "wrap_info": null,
  "warnings": [
    "This cluster is being enabled as a primary for replication. Vault will be
    unavailable for a brief period and will resume service shortly."
  ],
  "auth": null
}

Generate a secondary token by invoking /sys/replication/dr/primary/secondary-token endpoint.

Example:

$ curl --header "X-Vault-Token: ..." \
      --request POST \
      --data '{ "id": "secondary"}' \
      https://cluster-A.example.com:8200/v1/sys/replication/dr/primary/secondary-token | jq

{
  "request_id": "",
  "lease_id": "",
  "renewable": false,
  "lease_duration": 0,
  "data": null,
  "wrap_info": {
    "token": "eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXVCJ9.eyJhZGRyIjoiaHR0cDovLzEzLjU3LjIwLjQxOjgyMDAiLCJleHAiOjE1MjkzNDQzMjcsImlhdCI6MTUyOTM0MjUyNywianRpIjoiYmRiZTJiNzEtODgwMS05YjZjLTNjMTQtMzVkNDI3NDQ3MjEzIiwidHlwZSI6IndyYXBwaW5nIn0.MIGIAkIBmESVVq_83l9hixTN7Ot0v5XQMsQfi1zV9APooZWkLvbS2olBWSQnskykQQH6GskMOi-ypOlAabqxWmfoCLA8-TICQgHRdkbJGgAQtWmjc8Z-ZEgymMv8YZq6qQxbUtPXloyM-cf_1Y1qmdGDYWtjPqoF5m1Bt_WkAJl9MguVb04QMWSotw",
    "accessor": "7e56e9da-178c-119d-1d01-807a203fa0b3",
    "ttl": 1800,
    "creation_time": "2018-06-18T17:22:07.129747708Z",
    "creation_path": "sys/replication/dr/primary/secondary-token"
  },
  "warnings": null,
  "auth": null
}

» Web UI

Open a web browser and launch the Vault UI (e.g. https://cluster-A.example.com:8200/ui) and then login.

  1. Select Replication and check the Disaster Recovery (DR) radio button. DR Replication - primary

  2. Click Enable replication.

  3. Select the Secondaries tab, and then click Add. DR Replication - primary

  4. Populate the Secondary ID field, and click Generate token. DR Replication - primary

  5. Click Copy to copy the token which you will need to enable the DR secondary cluster. DR Replication - primary

» Step 2: Enable DR Secondary Replication

The following operations must be performed on the DR secondary cluster.

CLI command / API call using cURL / Web UI

» CLI command

Enable DR replication on the secondary cluster.

$ vault write sys/replication/dr/secondary/enable token="..."

Where the token is the wrapping_token obtained from the primary cluster.

Expected output:

WARNING! The following warnings were returned from Vault:

* Vault has successfully found secondary information; it may take a while to
perform setup tasks. Vault will be unavailable until these tasks and initial
sync complete.

» API call using cURL

Enable DR replication on the secondary cluster.

$ tee payload.json <<EOF
{
 "token": "..."
}
EOF

$ curl --header "X-Vault-Token: ..." \
      --request POST \
      --data @payload.json \
      https://cluster-B.example.com:8200/v1/sys/replication/dr/secondary/enable | jq

{
  "request_id": "7a9730c1-b6fc-6557-5c0a-081e1f89ed2d",
  "lease_id": "",
  "renewable": false,
  "lease_duration": 0,
  "data": null,
  "wrap_info": null,
  "warnings": [
    "Vault has successfully found secondary information; it may take a while
    to perform setup tasks. Vault will be unavailable until these tasks and
    initial sync complete."
  ],
  "auth": null
}

Where the token in payload.json is the token obtained from the primary cluster.

» Web UI

  1. Now, launch the Vault UI for the secondary cluster (e.g. https://cluster-B.example.com:8200/ui) and click Replication.

  2. Check the Disaster Recovery (DR) radio button and select secondary under the Cluster mode. Paste the token you copied from the primary in the Secondary activation token field. DR Replication - secondary

  3. Click Enable replication. DR Replication - secondary

» Step 3: Promote DR Secondary to Primary

This step walks you through the promotion of the secondary cluster to become the new primary when a catastrophic failure causes the primary cluster to be inoperable. Refer to the Important Note about Automated DR Failover section for more background information.

First, you must generate a DR operation token which you need to promote the secondary cluster. The process, outlined below using API calls, is the similar to Generating a Root Token (via CLI).

CLI command / Web UI

» CLI command

Start the DR operation token generation process.

$ vault operator generate-root -dr-token -init

The generated output would look like:

A One-Time-Password has been generated for you and is shown in the OTP field.
You will need this value to decode the resulting root token, so keep it safe.
Nonce         b4738404-0a11-63aa-2cb6-e77dfd96946f
Started       true
Progress      0/3
Complete      false
OTP           EYHAkPQYvvz93e8iI3pg1maQ
OTP Length    24

In order to generate a DR operation token, the following operation must be executed by each unseal key holder.

Example:

$ vault operator generate-root -dr-token \
        -nonce=b4738404-0a11-63aa-2cb6-e77dfd96946f \
        <primary_unseal_key_1>

Nonce            b4738404-0a11-63aa-2cb6-e77dfd96946f
Started          true
Progress         1/3
Complete         true
Encoded Token    djw4BR1iaDUFIBxaAwpiCC1YGhQHHDMf

Once the threshold has been reached, the output will contain the encoded DR operation token.

Example:

$ vault operator generate-root -dr-token \
        -nonce=b4738404-0a11-63aa-2cb6-e77dfd96946f \
        <primary_unseal_key_3>

Nonce            b4738404-0a11-63aa-2cb6-e77dfd96946f
Started          true
Progress         3/3
Complete         true
Encoded Token    djw4BR1iaDUFIBxaAwpiCC1YGhQHHDMf

Decode the generated DR operation token (Encoded Token).

Example:

$ vault operator generate-root -dr-token \
        -decode="djw4BR1iaDUFIBxaAwpiCC1YGhQHHDMf" \
        -otp="EYHAkPQYvvz93e8iI3pg1maQ"

3epDv29lsVfc0oZadkjs6qRN

Finally, promote the DR secondary to become the primary. The request must pass the DR operation token.

Example:

$ vault write /sys/replication/dr/secondary/promote \
        dr_operation_token=3epDv29lsVfc0oZadkjs6qRN

WARNING! The following warnings were returned from Vault:

  * This cluster is being promoted to a replication primary. Vault will be
  unavailable for a brief period and will resume service shortly.

» Web UI

  1. Click on Generate OTP to generate an OTP. Then click Copy OTP. DR Replication - secondary

  2. Click Generate Operation Token.

  3. A quorum of unseal keys must be entered to create a new operation token for the DR secondary.

    DR Replication - secondary

  4. Once the quorum has been reached, the output displays the encoded DR operation token. Click Copy CLI command.

    DR Replication - secondary

  5. Execute the CLI command from a terminal to generate a DR operation token using the OTP generated earlier. (Be sure to enter your OTP in the command.)

    Example: DR Replication - secondary

  6. Now, click Promote tab, and then enter the generated DR operation token.

    DR Replication - secondary

  7. Click Promote cluster.

    When you prompted, "Are you sure you want to promote this cluster?", click Promote cluster again to complete.

    DR Replication - secondary

» Step 4: Demote DR Primary to Secondary

If the original DR primary cluster becomes operational again, you may want to utilize the cluster by making it a DR secondary cluster. This step explains how to demote the original DR primary cluster to a secondary.


CLI command / API call using cURL / Web UI

» CLI command

Execute the following command to demote the original DR primary cluster to a secondary.

$ vault write -f sys/replication/dr/primary/demote

WARNING! The following warnings were returned from Vault:

  * This cluster is being demoted to a replication secondary. Vault will be
  unavailable for a brief period and will resume service shortly.

This secondary cluster will not attempt to connect to a primary (see the update-primary call), but will maintain knowledge of its cluster ID and can be reconnected to the same DR replication set without wiping local storage.

» API call using cURL

Invoke the sys/replication/dr/secondary/enable endpoint to demote the original DR primary cluster to a secondary.

$ curl --header "X-Vault-Token: ..." \
       --request POST \
       https://cluster-A.example.com:8200/v1/sys/replication/dr/primary/demote | jq

{
   "request_id": "8a40adac-6eb7-c798-48d0-f7cdd25fdd6f",
   "lease_id": "",
   "renewable": false,
   "lease_duration": 0,
   "data": null,
   "wrap_info": null,
   "warnings": [
     "This cluster is being demoted to a replication secondary. Vault will be unavailable for a brief period and will resume service shortly."
   ],
   "auth": null
}

This secondary cluster will not attempt to connect to a primary (see the update-primary call), but will maintain knowledge of its cluster ID and can be reconnected to the same DR replication set without wiping local storage.

» Web UI

Select Replication and click Demote cluster.

DR Replication - demotion

When you prompted, "Are you sure you want to demote this cluster?", click Demote cluster again to complete.

DR Replication - demotion

» Step 5: Disable DR Primary

Once the DR secondary cluster was promoted to be the new primary, you may want to disable the DR replication on the original primary when it becomes operational again.


CLI command / API call using cURL / Web UI

» CLI command

Execute the following command to disable DR replication.

$ vault write -f sys/replication/dr/primary/disable

WARNING! The following warnings were returned from Vault:

  * This cluster is having replication disabled. Vault will be unavailable for
    a brief period and will resume service shortly.

Any secondaries will no longer be able to connect.

» API call using cURL

Invoke the sys/replication/dr/primary/disable endpoint to disable DR replication.

$ curl --header "X-Vault-Token: ..." \
       --request POST \
       https://cluster-A.example.com:8200/v1/sys/replication/dr/primary/disable | jq

{
   "request_id": "92a5f57a-2f7b-11be-b9dd-0f028396fba8",
   "lease_id": "",
   "renewable": false,
   "lease_duration": 0,
   "data": null,
   "wrap_info": null,
   "warnings": [
     "This cluster is having replication disabled. Vault will be unavailable for a brief period and will resume service shortly."
   ],
   "auth": null
}

Any secondaries will no longer be able to connect.

» Web UI

Select Replication and click Disable replication.

DR Replication - demotion

When you prompted, "Are you sure you want to disable replication on this cluster?", click Disable again to complete.

DR Replication - demotion

Any secondaries will no longer be able to connect.

» Important Note about Automated DR Failover

Vault does not support an automatic failover/promotion of a DR secondary cluster, and this is a deliberate choice due to the difficulty in accurately evaluating why a failover should or shouldn't happen. For example, imagine a DR secondary loses its connection to the primary. Is it because the primary is down, or is it because networking between the two has failed?

If the DR secondary promotes itself and clients start connecting to it, you now have two active clusters whose data sets will immediately start diverging. There's no way to understand simply from one perspective or the other which one of them is right.

Vault's API supports programmatically performing various replication operations which allows the customer to write their own logic about automating some of these operations based on experience within their own environments. You can review the available replication APIs at the following links:

» Help and Reference