Skip to main content
When you deploy OpenBao with HSM auto-unseal, initialization generates a root key on the HSM and a set of recovery keys derived from an internal recovery key split by Shamir’s Secret Sharing (en.wikipedia.org/wiki/Shamir%27s_secret_sharing). Recovery keys replace the unseal keys used in a standard Shamir-only deployment. Because the HSM handles unsealing automatically, recovery keys are not used to unseal OpenBao. They exist solely for privileged operator operations, such as generating a new root token or rotating recovery keys. You might want to regenerate the recovery keys in cases such as the following:
  • Someone joins or leaves the organization.
  • Security wants to change the number of shares or the threshold.
  • Compliance mandates that you rotate the keys at regular intervals.
In addition to rekeying the recovery keys, you might need to rotate the underlying encryption key that OpenBao uses to encrypt data at rest. In OpenBao, rekeying and rotating are two separate operations:
  • Rekeying generates a new set of recovery key shares.
  • Key rotation generates a new encryption key for OpenBao.
Recent OpenBao releases disable the sys/generate-root/* and sys/generate-recovery-token/* endpoints by default, because they previously allowed unauthenticated access that could be exploited to disrupt rekey operations. The authenticated approach requires a token with sudo capabilities on the rotation paths. You must configure this token before you revoke the initial root token. Confirm the exact behavior against the release notes for your OpenBao version.

Prerequisite: Create a rotation operator token

Before you revoke the initial root token after setup, create a dedicated rotation operator token with the permissions required to perform recovery key rotation. This token serves as a break-glass credential. Store it as securely as the recovery key shares.
1
Using your root token, create a policy file that grants sudo access to the rotation paths.If you have not set the root token as an environment variable, set it now.
Shell
Then create the policy file.
This is an example policy file that creates an operator able to perform all the operations listed here. Adjust the paths and permissions to fit your organization’s security structure.
The paths let the rotation operator perform the following:
  • Rotation operations on the recovery and root keys (sys/rotate/*).
  • Encryption keyring rotation through bao operator rotate (sys/rotate, sys/key-status).
  • Recovery token generation for break-glass root token generation (sys/generate-recovery-token/*).
  • Look up, renew, and revoke their own token (auth/token/lookup-self, auth/token/renew-self, auth/token/revoke-self).
  • Check their own capabilities on any path (sys/capabilities-self).
Shell
2
Create a token attached to that policy. Replace <DURATION> with the desired token period, such as 768h for 32 days. Your OpenBao configuration may already have a TTL cap that limits this value.
Shell
The output is similar to the following.
Save this token securely. Treat it with the same care as the recovery key shares.
3
Revoke the root token to complete the initial setup, following best practice. Once revoked, the rotation operator token authorizes all future rotation operations.
Shell
Confirm that the root token is no longer active.
Shell
With no token set, this returns a permission-denied error, which confirms that the root token was successfully revoked.

Rekey the OpenBao recovery keys

To rekey the recovery keys when HSM auto-unseal is configured, use the bao operator rotate-keys command with the -target=recovery flag. This generates a new set of recovery keys and invalidates all existing shares. It does not generate a new root key on the HSM. The process can optionally modify the total number of recovery key shares or the recovery key threshold. Recovery keys cannot decrypt the root key; they exist purely for authorization.
You cannot replace a single recovery key share. Rekeying invalidates all existing shares and generates a completely new set. Every keyholder receives a new share after the operation completes.
1
Export the rotation operator token to authenticate the operation.
Shell
2
Initialize the rekeying operation, modifying the key shares and key threshold values as needed.
Shell
This command generates a nonce value and starts the rekeying process. All recovery key holders must provide this nonce value when they submit their share. The nonce is not a secret and is safe to distribute over insecure channels such as chat or email.
3
Each key holder runs the following command, entering their recovery key share when prompted. Replace <NONCE> with the nonce value from the previous step.
Shell
OpenBao prompts for the share.
The output after each submission is similar to the following.
Repeat this step for each keyholder until the threshold is met. You only need the threshold number of current keyholders to participate, for example, 3 of 5 existing holders.
4
When the final required key share is submitted, OpenBao outputs the new recovery keys.
All previous recovery key shares are now cryptographically invalid. Distribute the new shares immediately and confirm receipt from each keyholder.
5
Clear the rotation operator token from the environment when the operation is complete.
Shell
If something goes wrong before the operation completes, cancel the rotation to preserve the existing keys.
Shell

Generate a new root token

If the root token was revoked and a privileged operation requires one, such as mounting a new secrets engine or modifying policies, you can generate a new root token by using a quorum of recovery key shares.
Recent OpenBao releases disable the root token generation endpoints by default. To temporarily re-enable them, add the following line to the listener stanza in /etc/openbao/openbao.hcl.
/etc/openbao/openbao.hcl
Set this parameter to false only for the short period required to generate a new root token. Remove it and restart OpenBao as soon as the operation is complete.
1
After you add the parameter to /etc/openbao/openbao.hcl, restart OpenBao.
Shell
2
Generate a one-time password (OTP) to encode the resulting root token.
Shell
Save the OTP value. You need it to decode the final root token.
3
Initialize the root token generation. Replace <OTP> with the value from the previous step.
Shell
Save the Nonce value for the next step.
4
Each keyholder submits their recovery key share. Replace <NONCE> with the value from the previous step. Repeat until the threshold is met.
Shell
OpenBao prompts for the recovery key share. The output after each submission is similar to the following.
5
When the threshold is reached, OpenBao outputs an encoded token.
Decode it with the following command. Replace <ENCODED-TOKEN> and <OTP> with the values from the previous steps.
Shell
This outputs the decoded root token.
6
Export the decoded root token and perform the required privileged operations.
Shell
7
Revoke the root token when all operations are complete.
Shell
8
Remove disable_unauthed_generate_root_endpoints = false from the listener stanza in /etc/openbao/openbao.hcl to re-disable the unauthenticated root generation endpoints, then restart OpenBao.
Shell

Rotate the encryption key

Unlike rekeying the recovery keys, rotating the OpenBao encryption key does not require a quorum of recovery keys. Any token with the proper permissions can perform encryption key rotation. You can rotate keys automatically or manually.
OpenBao automatically rotates the backend encryption key before it reaches 2^32 encryption operations, in adherence with NIST SP 800-38D guidelines.

Adjust automatic key rotation

1
Export the rotation operator token to authenticate the operation.
Shell
2
View the current automatic rotation policy.
Shell
This returns the current status and configuration of automatic encryption key rotation.
3
Configure a time interval for automatic key rotation.
Shell
4
Configure the maximum number of encryption operations per key.
Shell

Perform manual key rotation

Trigger a key rotation.
Shell
This adds a new key to the keyring. The new key encrypts all new values written to the storage backend.

Continuity of operations

As with Shamir’s Secret Sharing, both rekeying and rotating operations with HSM auto-unseal are fully online operations. OpenBao continues to service requests uninterrupted during these processes.