seal "transit" is supported only in a standalone Stronghold installation.

With auto-unseal, the Stronghold root key is encrypted with a key of the Transit secrets engine of another cluster, which is called the transit cluster in this example. After a restart, Stronghold decrypts the root key through the transit cluster on its own, and no unseal keys are needed. Instead of unseal keys, Stronghold creates recovery keys.

Goal

Create a key, a policy, and a token on the transit cluster, configure seal "transit" on a Stronghold server, initialize a new server with recovery keys or move an existing server from Shamir to the transit seal, and make sure Stronghold unseals itself after a restart.

Prerequisites

To follow this example, you need:

  • A standalone Stronghold server installed as described in “Installation”. In the examples, the configuration is in /opt/stronghold/config.hcl and the service is named stronghold.
  • A transit cluster: a Stronghold or HashiCorp Vault cluster that is already unsealed and reachable from the Stronghold nodes over HTTPS. In the examples, its address is https://transit.example.com:8200. Don’t use the cluster you are configuring as its own transit cluster, and don’t set cross-unsealing between two clusters.
  • A token of the transit cluster with permissions to enable secrets engines, write keys and policies, and create tokens.
  • A CA certificate of the transit cluster, if its certificate is not issued by a public CA. In the examples, it is saved on the Stronghold nodes as /etc/stronghold/transit-ca.pem.
  • To migrate an existing server: the threshold number of Shamir unseal keys and a data backup.

Step 1. Prepare the transit cluster

Run the commands on a workstation that has access to the transit cluster:

  1. Set the address and a token of the transit cluster:

    export STRONGHOLD_ADDR=https://transit.example.com:8200
    export STRONGHOLD_TOKEN=<TRANSIT_ADMIN_TOKEN>
  2. Enable the Transit secrets engine and create a key for the seal:

    stronghold secrets enable -path=transit transit
    stronghold write -f transit/keys/autounseal
  3. Create a policy that allows only encryption and decryption with this key:

    cat > autounseal.hcl <<'HCL'
    path "transit/encrypt/autounseal" {
      capabilities = ["update"]
    }
    
    path "transit/decrypt/autounseal" {
      capabilities = ["update"]
    }
    HCL

    Save the policy to the autounseal.hcl file and write it to the cluster:

    stronghold policy write autounseal autounseal.hcl
  4. Create an orphan periodic token with this policy. The default policy stays on the token, because it allows the token to renew itself:

    stronghold token create -orphan -policy=autounseal -period=24h -format=json | jq -r '.auth.client_token'

    Save the value, it is needed in the next step. If you use a Vault cluster as the transit cluster, run the same commands with the vault utility.

The -period option sets the token renewal period. Stronghold renews the token automatically when it starts and while it runs.

Step 2. Put the token on the Stronghold node

On each node of the protected cluster, save the token to a file readable only by the stronghold user. The file must contain only the token, without a trailing newline:

sudo install -m 0600 -o stronghold -g stronghold /dev/null /etc/stronghold/transit-token
printf '%s' '<TOKEN>' | sudo tee /etc/stronghold/transit-token > /dev/null

In the command, use the token from step 1 as <TOKEN>.

If the file ends with a newline, for example after echo "$TOKEN" > file, Stronghold doesn’t start and reports configured token contains non-printable characters and cannot be used.

Step 3. Add the seal stanza to the configuration

Add a seal stanza to /opt/stronghold/config.hcl on each node:

seal "transit" {
  address     = "https://transit.example.com:8200"
  token       = "file:///etc/stronghold/transit-token"
  mount_path  = "transit"
  key_name    = "autounseal"
  tls_ca_cert = "/etc/stronghold/transit-ca.pem"
}

Instead of configuration parameters, you can use environment variables. For mount_path, key_name, disable_renewal, and namespace, they take precedence over the configuration file; for address and token, the configuration file takes precedence over VAULT_ADDR and VAULT_TOKEN. The full list is in “Transit seal”.

For a new server, go to step 4. For a server already initialized with Shamir, go to step 5.

Step 4. Initialize a new server

Start and initialize a new server with the transit seal:

  1. Start Stronghold:

    sudo systemctl start stronghold

    If the transit cluster is unavailable, the token has no permissions, or the key doesn’t exist, the service doesn’t start. The cause is described in the log, see “Troubleshooting”.

  2. Initialize Stronghold. With auto-unseal, recovery keys are created instead of unseal keys:

    stronghold operator init -recovery-shares=5 -recovery-threshold=3

    Distribute the recovery keys among key holders and store the root token. Recovery keys do not unseal Stronghold, but they are required to generate a root token, rekey, and migrate the seal.

    The server unseals automatically right after initialization.

  3. For an HA cluster, start the other nodes with the same seal stanza. They join the cluster through retry_join and unseal automatically.

Step 5. Move an existing server from Shamir to the transit seal

Seal migration requires brief downtime. Both the Shamir keys and the transit cluster must be available during the migration.

  1. Take a Raft snapshot:

    stronghold operator raft snapshot save pre-seal-migration.snap
  2. Add the seal "transit" stanza to the configuration (step 3) and restart Stronghold:

    sudo systemctl restart stronghold

    The log shows a migration mode message:

    journalctl -u stronghold.service | grep "seal migration"
    core: entering seal migration mode; Stronghold will not automatically unseal even if using an autoseal: from_barrier_type=shamir to_barrier_type=transit
  3. Unseal the cluster using the -migrate flag, entering the threshold number of unseal keys:

    stronghold operator unseal -migrate

    Once the threshold is reached, the Shamir unseal keys become recovery keys. The status shows Seal Migration in Progress until the migration is complete.

For an HA cluster, migrate node by node starting with standby nodes, and step down the active node as described in “Seal migration”.

Verification

Check the result:

  1. Check the status:

    stronghold status

    Expected values:

    Recovery Seal Type       shamir
    Initialized              true
    Sealed                   false
    Total Recovery Shares    5
    Threshold                3

    With auto-unseal, the status shows the recovery keys: the Recovery prefix and the number of recovery key shares.

  2. Restart the service and make sure Stronghold unseals without entering keys:

    sudo systemctl restart stronghold
    sleep 10
    stronghold status -format=json | jq '{sealed, recovery_seal}'

    The sealed field must be false, and recovery_seal must be true.

  3. The startup banner and the log show which transit cluster is used (Transit Address, Transit Mount Path, Transit Key Name):

    journalctl -u stronghold.service --since "10 minutes ago" | grep "Transit"
  4. Check that the recovery keys work by starting and cancelling root token generation:

    stronghold operator generate-root -init
    stronghold operator generate-root -cancel

Troubleshooting

If Stronghold doesn’t start, the log contains a message that starts with Error parsing Seal configuration. The cause is at the end of the message:

MessageCause and fix
dial tcp ...: connect: connection refusedThe transit cluster is unavailable or address is wrong. Check the address, the network, and the state of the transit cluster
Code: 403 ... permission deniedThe token has no permission for transit/encrypt/<KEY> or transit/decrypt/<KEY>, the token has expired, or mount_path or key_name is wrong: Transit answers with 403 when the path is not covered by the policy. Check the token and the policy
configured token contains non-printable characters and cannot be usedThe token file ends with a newline. Recreate it as in step 2
mount_path is required or key_name is requiredThe parameter is missing from the configuration and from the environment

Operations

During operation, take the following into account:

  • The transit cluster must be available every time a node starts. Back it up, and unseal it independently of the clusters it protects.
  • You can rotate the key on the transit cluster, but don’t delete the key or its old versions: the root key may still be encrypted with an old version.
  • To move from the transit seal back to Shamir, add disabled = "true" to the seal "transit" stanza, restart Stronghold, and run stronghold operator unseal -migrate, entering the recovery keys. Details are in “Transit seal”.
  • Rekeying and storing recovery keys are described in “Key management operations”.

Cleanup

For a test environment:

  1. Stop Stronghold and delete its data.
  2. On the transit cluster, revoke the token (stronghold token revoke <TOKEN>) and delete the policy (stronghold policy delete autounseal).
  3. Delete the key only after deleting the Stronghold data encrypted with it. Allow deletion first: stronghold write transit/keys/autounseal/config deletion_allowed=true, then stronghold delete transit/keys/autounseal.

Additional resources