# 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 `init` once, 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](#replace-a-lost-worker). Deleting one deletes that pod's data. Run the commands in Bash on your workstation. Replace `` 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: ```bash 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 1. In pfSense's DNS Resolver, point `bao.` to Traefik's IP (`kubeVipAddress`), not the Kubernetes API address. 2. Check the pods, volumes and certificates: ```bash kubectl -n openbao get pods,pvc,certificates ``` **Checkpoint:** all three pods are `Running` but show `0/1`, the PVCs are `Bound` and the certificates are `Ready`. The web UI doesn't work until OpenBao is unsealed. ### 2. Initialise Run this **once, only on `openbao-0`**: ```bash 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 1. Unseal `openbao-0`, and paste the key when prompted: ```bash kubectl -n openbao exec -it openbao-0 -- bao operator unseal kubectl -n openbao exec openbao-0 -- bao status ``` **Checkpoint:** after a few seconds, `bao status` shows `Sealed false` and `HA Mode active`. 2. Check that `openbao-1` has found `openbao-0`, then unseal it with the same key: ```bash kubectl -n openbao exec openbao-1 -- bao status kubectl -n openbao exec -it openbao-1 -- bao operator unseal ``` **Checkpoint:** `bao status` shows `Initialized true` before you unseal. Exit code 2 is normal because the pod is still sealed. If it shows `Initialized false`, don't run `init`. Check `kubectl -n openbao logs openbao-1` instead. 3. Do the same for `openbao-2`, then check all three: ```bash kubectl -n openbao get pods -L openbao-active,openbao-sealed ``` **Checkpoint:** all pods show `1/1` and `openbao-sealed=false`, and only one has `openbao-active=true`. ### 4. Create the admin login 1. Set [`$POD`](#rules), then log in with the root token when prompted: ```bash kubectl -n openbao exec -it "$POD" -- bao login -no-print kubectl -n openbao exec "$POD" -- bao operator raft list-peers ``` **Checkpoint:** there's one `leader` and two `follower`s. All three show `Voter true`, which can take a moment. 2. Create a policy with **full access**. Only use it for your admin login, never for apps: ```bash kubectl -n openbao exec -i "$POD" -- bao policy write admin - <<'EOF' path "*" { capabilities = ["create", "read", "update", "patch", "delete", "list", "scan", "sudo"] } EOF ``` 3. Turn on username and password logins: ```bash kubectl -n openbao exec "$POD" -- bao auth enable userpass ``` 4. Generate a strong password in Bitwarden and create the `admin` user. Run these lines one at a time, and paste the password after the first one: ```bash 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 ``` 5. Turn on a KV v2 secrets engine, which stores passwords and API keys: ```bash kubectl -n openbao exec "$POD" -- bao secrets enable -path=secret -version=2 kv ``` ### 5. Test the admin login Open `https://bao.` in a private window. Choose **Username** as the login method and log in as `admin`. Then: 1. Create a fake secret in `secret/`, read it, then delete it. 2. 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](#save-a-snapshot). This also checks that the admin login can make backups. Before storing real secrets, test the [restore steps](#restore-into-a-new-openbao) 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. 1. Set [`$POD`](#rules), then log in with the **root token**. Log in again even if you did so earlier, because the snapshot steps replaced the saved login: ```bash kubectl -n openbao exec -it "$POD" -- bao login -no-print kubectl -n openbao exec "$POD" -- bao read -field=policies auth/token/lookup-self ``` **Checkpoint:** it prints `[root]`. If it prints anything else, **don't continue**, because the next command revokes whichever token is logged in. 2. Revoke it and remove the saved login: ```bash kubectl -n openbao exec "$POD" -- bao token revoke -self kubectl -n openbao exec "$POD" -- rm -f /home/openbao/.vault-token ``` 3. Check that you can still log in to the UI as `admin`. Then delete the root token from Bitwarden, but **keep the unseal key**. ## Automatic backups A CronJob from the OpenBao Helm chart saves a Raft snapshot every hour and uploads it to the `openbao-backups` bucket in RustFS on TrueNAS. Object lock keeps each backup for 30 days, and a lifecycle rule deletes it after about 32 days. The job logs in with Kubernetes auth and can only read snapshots. Its RustFS key can only upload. > Missed or failed backups don't trigger alerts yet. Check the job now and then, and still [save a snapshot](#save-a-snapshot) before upgrades. ### Set up backups Do these in order. Otherwise, the hourly job fails until its login exists. 1. Set up RustFS, then create the bucket and upload-only user. Follow [the RustFS runbook](truenas-rustfs.md), including step 8. 2. Add the backup user's key to the stack's config. Run these from the repo root, and paste each value when prompted: ```bash pulumi config set --secret --cwd 06-openbao snapshotS3AccessKeyId pulumi config set --secret --cwd 06-openbao snapshotS3SecretAccessKey ``` Commit and push the change in the private config repo, because CI uses the pushed version. 3. Set [`$POD`](#rules) and log in as `admin`. Run the login **by itself**, not pasted with the next steps, or the password prompt may not work. Then check it: ```bash kubectl -n openbao exec -it "$POD" -- bao login -no-print -method=userpass username=admin kubectl -n openbao exec "$POD" -- bao read -field=policies auth/token/lookup-self ``` **Checkpoint:** it prints `[admin default]`. If it doesn't, stop. The next steps fail with `permission denied` without a valid login. 4. Turn on Kubernetes logins. OpenBao uses its own service account and the cluster's CA to check logins: ```bash kubectl -n openbao exec "$POD" -- bao auth enable kubernetes kubectl -n openbao exec "$POD" -- bao write auth/kubernetes/config kubernetes_host=https://kubernetes.default.svc:443 ``` 5. Create the backup policy and role. The role only accepts the `openbao-snapshot` service account in the `openbao` namespace: ```bash kubectl -n openbao exec -i "$POD" -- bao policy write openbao-snapshot - <<'EOF' path "sys/storage/raft/snapshot" { capabilities = ["read"] } EOF kubectl -n openbao exec "$POD" -- bao write auth/kubernetes/role/openbao-snapshot bound_service_account_names=openbao-snapshot bound_service_account_namespaces=openbao token_policies=openbao-snapshot token_ttl=10m token_max_ttl=10m ``` 6. Remove the saved login: ```bash kubectl -n openbao exec "$POD" -- bao token revoke -self kubectl -n openbao exec "$POD" -- rm -f /home/openbao/.vault-token ``` 7. Deploy `06-openbao`. Then start a backup without waiting for the hourly run: ```bash kubectl -n openbao create job --from=cronjob/openbao-snapshot openbao-snapshot-manual kubectl -n openbao wait --for=condition=complete job/openbao-snapshot-manual --timeout=5m kubectl -n openbao logs job/openbao-snapshot-manual ``` **Checkpoint:** the job completes, and the log ends with an `upload:` line for a `bao_-