16 KiB
OpenBao
Use this to set up OpenBao after its first deploy, unseal it after restarts, and back it up or recover it. 06-openbao runs three pods that copy their data to each other using Raft. Unsealing is manual, with one unseal key.
The main commands were tested on local OpenBao 2.7.3 servers without Kubernetes or TLS, not on the cluster. If a checkpoint doesn't match, stop.
Rules
- Only run
initonce, during first setup or on a new, empty OpenBao before a restore. After a restart, you only need to unseal. - Keep the unseal key in Bitwarden, plus a copy outside Bitwarden (on paper or an offline USB stick). If all pods restart and the key is lost, the data can't be recovered, even from snapshots.
- Never put keys, tokens or passwords in Git, chats, tickets or commands. Enter them only when prompted, in a terminal that isn't being recorded.
- Don't delete the
data-openbao-*PVCs, except when replacing a lost worker. Deleting one deletes that pod's data.
Run the commands in Bash on your workstation. Replace <domain> with your domain. In steps that use $POD, set it to the active pod first, and again whenever you open a new terminal or a pod restarts:
POD=$(kubectl -n openbao get pod -l openbao-active=true -o name); echo "$POD"
Checkpoint: it prints exactly one pod.
First setup
1. Check the deployment
-
In pfSense's DNS Resolver, point
bao.<domain>to Traefik's IP (kubeVipAddress), not the Kubernetes API address. -
Check the pods, volumes and certificates:
kubectl -n openbao get pods,pvc,certificatesCheckpoint: all three pods are
Runningbut show0/1, the PVCs areBoundand the certificates areReady. The web UI doesn't work until OpenBao is unsealed.
2. Initialise
Run this once, only on openbao-0:
kubectl -n openbao exec -it openbao-0 -- bao operator init -key-shares=1 -key-threshold=1
It shows the unseal key and initial root token only once. Save both in Bitwarden and make the second copy of the unseal key. Then clear the terminal and its scrollback. You'll delete the root token in step 7.
3. Unseal
-
Unseal
openbao-0, and paste the key when prompted:kubectl -n openbao exec -it openbao-0 -- bao operator unseal kubectl -n openbao exec openbao-0 -- bao statusCheckpoint: after a few seconds,
bao statusshowsSealed falseandHA Mode active. -
Check that
openbao-1has foundopenbao-0, then unseal it with the same key:kubectl -n openbao exec openbao-1 -- bao status kubectl -n openbao exec -it openbao-1 -- bao operator unsealCheckpoint:
bao statusshowsInitialized truebefore you unseal. Exit code 2 is normal because the pod is still sealed. If it showsInitialized false, don't runinit. Checkkubectl -n openbao logs openbao-1instead. -
Do the same for
openbao-2, then check all three:kubectl -n openbao get pods -L openbao-active,openbao-sealedCheckpoint: all pods show
1/1andopenbao-sealed=false, and only one hasopenbao-active=true.
4. Create the admin login
-
Set
$POD, then log in with the root token when prompted:kubectl -n openbao exec -it "$POD" -- bao login -no-print kubectl -n openbao exec "$POD" -- bao operator raft list-peersCheckpoint: there's one
leaderand twofollowers. All three showVoter true, which can take a moment. -
Create a policy with full access. Only use it for your admin login, never for apps:
kubectl -n openbao exec -i "$POD" -- bao policy write admin - <<'EOF' path "*" { capabilities = ["create", "read", "update", "patch", "delete", "list", "scan", "sudo"] } EOF -
Turn on username and password logins:
kubectl -n openbao exec "$POD" -- bao auth enable userpass -
Generate a strong password in Bitwarden and create the
adminuser. Run these lines one at a time, and paste the password after the first one:read -rsp 'Admin password: ' PW; echo printf %s "$PW" | kubectl -n openbao exec -i "$POD" -- bao write auth/userpass/users/admin password=- token_policies=admin token_ttl=1h token_max_ttl=8h unset PW -
Turn on a KV v2 secrets engine, which stores passwords and API keys:
kubectl -n openbao exec "$POD" -- bao secrets enable -path=secret -version=2 kv
5. Test the admin login
Open https://bao.<domain> in a private window. Choose Username as the login method and log in as admin. Then:
- Create a fake secret in
secret/, read it, then delete it. - Create a test policy, then delete it.
Checkpoint: everything works, and the browser shows no certificate warning.
6. Save the first snapshot
Follow Save a snapshot. This also checks that the admin login can make backups. Before storing real secrets, test the restore steps on a separate test cluster.
7. Revoke the root token
Only do this once steps 5 and 6 have worked. Check that Bitwarden has the admin password and that you have a copy outside it.
-
Set
$POD, then log in with the root token. Log in again even if you did so earlier, because the snapshot steps replaced the saved login:kubectl -n openbao exec -it "$POD" -- bao login -no-print kubectl -n openbao exec "$POD" -- bao read -field=policies auth/token/lookup-selfCheckpoint: it prints
[root]. If it prints anything else, don't continue, because the next command revokes whichever token is logged in. -
Revoke it and remove the saved login:
kubectl -n openbao exec "$POD" -- bao token revoke -self kubectl -n openbao exec "$POD" -- rm -f /home/openbao/.vault-token -
Check that you can still log in to the UI as
admin. Then delete the root token from Bitwarden, but keep the unseal key.
Set up backup storage
After first setup, install RustFS on TrueNAS. The runbook covers TrueNAS, Cloudflare, pfSense and RustFS. This doesn't turn on automatic backups yet, so keep saving snapshots manually.
Unseal after a restart
| What restarted | What to do |
|---|---|
| One OpenBao pod or its node | Unseal that pod. The other two keep OpenBao running. |
| All three pods | Unseal all three. OpenBao works again once two are unsealed. |
| A node without an OpenBao pod | Nothing |
-
Find the sealed pods, which show
0/1:kubectl -n openbao get pods -L openbao-active,openbao-sealed -
Unseal each one, replacing
<n>with its number:kubectl -n openbao exec -it openbao-<n> -- bao operator unseal -
Run the first command again.
Checkpoint: all pods show
1/1, and only one is active.
Restart pods after a change
Changes to the OpenBao version or its config only take effect after you restart the pods. Before an upgrade, read the release notes and save a snapshot.
-
Check that all three pods show
1/1, and note which one is active:kubectl -n openbao get pods -L openbao-active -
Restart one non-active pod, then unseal it:
kubectl -n openbao delete pod openbao-<n>Checkpoint: all three pods show
1/1before you restart the next one. -
Do the same for the other non-active pod, then restart the active pod last. Another pod takes over, which can cause a short interruption.
Save a snapshot
Do this before upgrades and after important changes. Snapshots aren't automatic yet.
-
Set
$POD, then log in asadmin:kubectl -n openbao exec -it "$POD" -- bao login -no-print -method=userpass username=admin -
Save a snapshot and copy it to your workstation:
SNAP=~/openbao-$(date +%F-%H%M).snap kubectl -n openbao exec "$POD" -- bao operator raft snapshot save /home/openbao/openbao.snap (umask 077; kubectl -n openbao exec "$POD" -- cat /home/openbao/openbao.snap > "$SNAP") kubectl -n openbao exec "$POD" -- sha256sum /home/openbao/openbao.snap sha256sum "$SNAP"Checkpoint: both checksums match.
-
Remove the copy and saved login from the pod:
kubectl -n openbao exec "$POD" -- bao token revoke -self kubectl -n openbao exec "$POD" -- rm -f /home/openbao/openbao.snap /home/openbao/.vault-token -
Move the snapshot to storage outside the cluster and restrict access to it. Don't store it with the unseal key, because someone with both can read your secrets. Note which unseal key it needs.
Restore into a new OpenBao
Use this on a separate test cluster, or if all three pods have lost their data. It replaces everything in the new OpenBao. Don't use it for a single lost pod or node. If the cluster being restored to has any working OpenBao data, stop and plan the recovery first.
You need the snapshot, the original unseal key and an admin password that was valid when the snapshot was taken. Use the same OpenBao version as the snapshot.
-
Deploy a new, empty OpenBao. Follow First setup steps 1–3, but save the new unseal key and root token as temporary. Don't replace the original key in Bitwarden.
-
Set
$POD, then log in with the temporary root token:kubectl -n openbao exec -it "$POD" -- bao login -no-print -
Check your
kubectlcontext, because-forceoverwrites the data and skips the unseal key check:kubectl config current-contextCheckpoint: it's the cluster you want to restore to. Also check that its API address is correct, because different clusters can use the same context name:
kubectl config view --minify -o jsonpath='{.clusters[0].cluster.server}'; echo -
Copy the snapshot to the pod and restore it:
kubectl -n openbao exec -i "$POD" -- sh -c 'cat > /home/openbao/restore.snap' < <snapshot-file> sha256sum <snapshot-file> kubectl -n openbao exec "$POD" -- sha256sum /home/openbao/restore.snapCheckpoint: both checksums match. Then run:
kubectl -n openbao exec "$POD" -- bao operator raft snapshot restore -force /home/openbao/restore.snap -
Wait 10 seconds, then restart all three pods. Otherwise, the non-active pods keep using the temporary key and get stuck:
kubectl -n openbao delete pod openbao-0 openbao-1 openbao-2 -
Once all three are running, unseal them with the original key. The temporary key and root token no longer work, so delete them.
-
Set
$PODagain, log in asadminand check the cluster:kubectl -n openbao exec -it "$POD" -- bao login -no-print -method=userpass username=admin kubectl -n openbao exec "$POD" -- bao operator raft list-peersCheckpoint: there's one leader and two followers, and your secrets are there. All three should show
Voter true, but this can take a moment. -
Remove the saved login:
kubectl -n openbao exec "$POD" -- bao token revoke -self kubectl -n openbao exec "$POD" -- rm -f /home/openbao/.vault-token
Replace a lost worker
Only use this if the worker can't be recovered and the other two OpenBao pods are working. If it's only offline, bring it back and unseal its pod. local-path data can't move to another node, and each OpenBao pod needs its own node.
-
Save a snapshot. Make sure the old worker can't come back online, then add its replacement to the cluster and remove the old node from Kubernetes. Wait until the replacement is
Ready. -
Set
$POD, log in asadmin, then remove the lost pod from the Raft cluster. Replace<n>with its number:kubectl -n openbao exec -it "$POD" -- bao login -no-print -method=userpass username=admin kubectl -n openbao exec "$POD" -- bao operator raft remove-peer openbao-<n> kubectl -n openbao exec "$POD" -- bao operator raft list-peersCheckpoint: only the two working pods are listed.
-
Delete only the lost pod and its PVC. Check the number first:
kubectl -n openbao delete pvc data-openbao-<n> --wait=false kubectl -n openbao delete pod openbao-<n>If the pod gets stuck in
Terminating, stop and check that the old node was removed. Don't force-delete the pod while its node could still be running. -
Wait for the new pod to show
RunningandInitialized true. Don't runinit. Unseal it and runlist-peersagain.Checkpoint: all three pods are listed with
Voter true, which can take a moment. -
Remove the saved login:
kubectl -n openbao exec "$POD" -- bao token revoke -self kubectl -n openbao exec "$POD" -- rm -f /home/openbao/.vault-token
If you lose the admin login
By default, the unseal key alone can't create a new root token. You need to temporarily turn on an older endpoint that doesn't need a login. While it's on, anyone who has the unseal key and can reach OpenBao can get full access.
-
In
06-openbao/index.ts, add this to thelistener "tcp"block. Preview the change, then deploy it:disable_unauthed_generate_root_endpoints = false -
Restart all three pods, one at a time.
-
Run this on your workstation. The
baocommand doesn't work for this without a login. Enterhttps://bao.<domain>and the unseal key when prompted. It cancels any unfinished attempt first:cat > /tmp/openbao-root.py <<'EOF' import base64, getpass, json, urllib.request url = input("OpenBao URL: ").rstrip("/") def call(method, path, data=None): body = None if data is None else json.dumps(data).encode() req = urllib.request.Request(f"{url}/v1/sys/generate-root/{path}", body, method=method) with urllib.request.urlopen(req) as res: return json.loads(res.read() or b"{}") call("DELETE", "attempt") start = call("PUT", "attempt", {}) key = getpass.getpass("Unseal key: ") done = call("PUT", "update", {"key": key, "nonce": start["nonce"]}) encoded = done["encoded_root_token"] raw = base64.b64decode(encoded + "=" * (-len(encoded) % 4)) print("Root token:", bytes(a ^ b for a, b in zip(raw, start["otp"].encode())).decode()) EOF python3 /tmp/openbao-root.py rm /tmp/openbao-root.pySave the token in Bitwarden for now, then clear the terminal and its scrollback. If the script shows
405 Method Not Allowed, the setting isn't active on the pod that answered. -
Set
$PODand log in with the new root token:kubectl -n openbao exec -it "$POD" -- bao login -no-printSet a new password with step 4.4 of First setup. Then test the login and revoke the root token.
-
Remove the setting, deploy again and restart all three pods, one at a time. Run the script again and enter any text as the key.
Checkpoint: it fails with
405 Method Not Allowed.
Certificates
cert-manager renews both the browser certificate (openbao-ingress-tls) and OpenBao's internal one (openbao-server-tls). OpenBao loads its new internal certificate without a restart, so you don't need to unseal it.
Don't delete the openbao-ca Secret. It holds the key for our internal CA. Renewing or replacing the CA doesn't immediately renew OpenBao's internal certificate. We haven't tested this, so plan and test it first. Check the certificates with:
kubectl -n openbao get certificates