Skip to content

OpenBao Backups, Snapshot Check and Restore Drill

OpenBao holds every platform secret: every ExternalSecret reads from it. Without it the cluster cannot be rebuilt from Git. It is backed up by a nightly Raft snapshot in the backup store, checked after every upload, and restored into a throwaway OpenBao once a month and before every OpenBao upgrade.

The snapshot and the drill live in components/openbao/backup/ and are applied by the Flux Kustomization openbao-backup. The pre-upgrade gate and the namespace openbao-drill live in components/openbao/preupgrade/, applied by openbao-preupgrade. Both Kustomizations are in cluster/hetzner-mgmt/openbao/kustomization.yaml. The storage change is in components/openbao/base/helmrelease.yaml.

A snapshot is useless without the unseal keys

A snapshot is encrypted with OpenBao's barrier key. Restoring it needs the unseal keys (3 of the key shares). They are never written to the backup bucket. See Where the unseal keys come from.

Why Integrated Storage (Raft)

OpenBao used storage "file". A copy of that directory taken while OpenBao runs can be inconsistent. There were two options (task #1377; the decision is recorded in ADR 0019):

A: migrate to Raft, single node (chosen) B: keep file, copy it with OpenBao stopped
Consistency bao operator raft snapshot save is consistent while OpenBao is online Consistent only while OpenBao is stopped
Downtime Once, for the migration Every night. All ExternalSecret refreshes fail, and so does every login, while it runs
Restore bao operator raft snapshot restore, the documented path Copy files back into a volume
Backup credential A token whose policy reads only sys/storage/raft/snapshot Rights to scale the StatefulSet, plus read access to the data volume
Cost A one-time migration, with a rollback Nightly scale-down and scale-up logic

Raft is OpenBao's production-ready storage backend (Integrated Storage). bao operator migrate copies file to Raft offline, and it leaves the source data untouched apart from a small lock key (operator migrate). That makes a rollback simple.

These facts were checked against the bao 2.1.0 binary, the version the chart runs, before this was built: migrate file to Raft, start on Raft with the same keys, take a snapshot with the backup AppRole (it is denied every other path), restore into a fresh instance, unseal it with the original keys, and roll back to file on the untouched source.

The migration (done)

OpenBao was migrated from file to Raft on 2026-10-21 (task #1389): bao operator migrate ran in a one-time init container migrate-to-raft when openbao-0 was deleted, with about two minutes of downtime. The first snapshot and drill passed right after it.

The old file data stayed on the volume next to raft/ for a rollback until task #1390 removed it, together with migrate-to-raft. The init container prepare-data in components/openbao/base/helmrelease.yaml now runs before the server starts:

  • It creates /openbao/data/raft if it is missing. OpenBao's Raft backend does not create that directory itself, so a fresh volume needs it.
  • When /openbao/data/raft/raft/raft.db exists, it deletes everything else in /openbao/data except lost+found, and logs each deleted path. Without raft.db it deletes nothing.

The StatefulSet uses updateStrategy: OnDelete, so prepare-data first runs when openbao-0 is next deleted. Until then KubeStatefulSetUpdateNotRolledOut fires. A person runs that restart window, about two minutes of downtime: see Rolling out an OpenBao pod-template change.

Rollback: there is no file data to return to. The deletion cannot be undone, and the nightly snapshots are the only backup of OpenBao. To recover, follow Manual restore.

One-time setup in OpenBao

A person with an admin token sets this up before the PR is merged. Until then the openbao-backup ExternalSecrets are not Ready, and the CronJobs fail.

# Policy: the snapshot, and the canary the drill reads. Nothing else.
bao policy write openbao-backup - <<'HCL'
path "sys/storage/raft/snapshot" {
  capabilities = ["read"]
}
path "clusters/data/hetzner-mgmt/backup-canary" {
  capabilities = ["read"]
}
HCL

# AppRole: short-lived tokens. The secret-id does not expire, because the monthly drill logs in
# with it in the restored copy.
bao write auth/approle/role/openbao-backup \
  token_policies=openbao-backup token_ttl=15m token_max_ttl=30m secret_id_ttl=0

# Its credentials, for the ExternalSecrets in openbao and openbao-drill
bao kv put -mount=clusters hetzner-mgmt/openbao/backup-approle \
  role_id="$(bao read -field=role_id auth/approle/role/openbao-backup/role-id)" \
  secret_id="$(bao write -f -field=secret_id auth/approle/role/openbao-backup/secret-id)"

# The canary: a value that is not secret, which the drill compares with production
bao kv put -mount=clusters hetzner-mgmt/backup-canary value="canary-$(date -u +%Y%m%d)"

The snapshot endpoint needs only read (bao operator raft snapshot save issues a GET). The token is never the root token.

Also apply the Terraform stage terraform/environments/hetzner-object-storage/. Its backup_expiring_prefixes default now expires hetzner-mgmt/openbao/snapshots/ after 30 days.

Nightly snapshot and check

The CronJob openbao/openbao-snapshot runs every night at 01:30 UTC:

  1. snapshot (OpenBao image, scripts/snapshot.sh): logs in with the openbao-backup AppRole and runs bao operator raft snapshot save. It then checks the archive against its own SHA256SUMS: a snapshot is a gzip tar of meta.json, state.bin and their checksums. It records the size and SHA-256.
  2. upload (aws-cli image, scripts/store.sh upload). This step is the snapshot check, done without unsealing anything:
    • Plausible size: at least 10 KiB, and at least half the size of the previous snapshot. A much smaller snapshot more likely means OpenBao was emptied or re-initialised than that secrets were cleaned up.
    • It uploads <cluster>/openbao/snapshots/<timestamp>.snap with Content-MD5, which the object lock requires.
    • Exists: head-object must show the uploaded size.
    • Readable, matching checksum: a fresh download must have the same SHA-256.
    • Only then does it write <cluster>/openbao/latest.env (KEY, SIZE, SHA256, TAKEN). The drill restores that snapshot.

A failure leaves latest.env on the last good snapshot and fails the Job. OpenBaoSnapshotFailed fires an hour later. It also fires when no run has succeeded in 26 hours.

Monthly restore drill

The CronJob openbao-drill/openbao-restore-drill runs on the 1st of each month at 04:00 UTC. It is monthly, not weekly, because it unseals a full copy of every secret with the real keys (the owner's decision, 2026-10-20). One pod runs these steps:

  1. fetch: downloads latest.env and its snapshot, and checks the SHA-256.
  2. keys: reads key1..key3 of the Secret openbao/openbao-unseal-keys into an in-memory volume. The Role openbao/openbao-restore-drill allows get on that one Secret only.
  3. drill (scripts/drill.sh): starts a throwaway OpenBao in the container. It listens on 127.0.0.1 only, with Raft storage on an in-memory volume. The step then:

    • initialises it with a one-off key and restores the snapshot with -force;
    • restarts it. Right after a restore, OpenBao seals itself a few seconds later, and a status call made before that leaves it showing the one-off seal configuration, which rejects the real keys. A restart reads the restored one. This was found while building the drill;
    • unseals it with the real keys, logs in with the openbao-backup AppRole from the snapshot, and reads clusters/hetzner-mgmt/backup-canary. The value must equal production's (ExternalSecret openbao-backup in openbao-drill).

    When this step ends, whether it passed or failed, it stops the server and deletes the restored data, the snapshot and the keys. The pod's volumes are all in memory and go with the pod. There is no PersistentVolume to delete. 4. record: runs only if the drill passed. It writes <cluster>/openbao/drill/last-success.env (pod, time, snapshot key).

The namespace openbao-drill enforces Pod Security restricted. A NetworkPolicy denies all ingress, and there is no Service.

A failed drill, or no passing drill in 32 days, fires OpenBaoRestoreDrillFailed (critical).

Before an OpenBao upgrade the pre-upgrade gate runs the same steps on a fresh snapshot. To run a drill by hand at any other time:

kubectl --context admin@mgmt-cluster -n openbao-drill create job --from=cronjob/openbao-restore-drill openbao-restore-drill-manual
kubectl --context admin@mgmt-cluster -n openbao-drill logs -f job/openbao-restore-drill-manual --all-containers
aws s3 cp "s3://skatzi-backups/hetzner-mgmt/openbao/drill/last-success.env" -   # with the backup-store keys

The drill, snapshot and gate images (quay.io/openbao/openbao) must equal the chart's server image. Update them in the same PR as the chart (see Upgrading OpenBao).

Pre-upgrade backup gate

Following Renovate architecture §11, Flux applies a new OpenBao version only after a snapshot of the running version has been uploaded, checked and verified by restoring it. The openbao Kustomization dependsOn openbao-preupgrade, whose health check is the Job openbao-drill/openbao-preupgrade.

Why it unseals. A snapshot is encrypted with the barrier key. After a restore and a restart, the copy shows production's seal configuration and stays sealed: only unsealing it with the real keys and reading the canary proves the data decrypts. The owner decided on 2026-10-24 (#1547, option A) that the gate does this on every OpenBao upgrade, with the drill's isolation, and that OpenBao updates are not batched. The options were: A, unseal on every upgrade (chosen); B, the same with Renovate grouping OpenBao updates into one PR a month; C, restore without unsealing and require a drill in the last 32 days; D, no gate, a manual drill before each upgrade. OpenBao published releases on 14 dates between 2025-10-24 and 2026-10-24 (releases), so the gate adds roughly as many unseals a year as the monthly drill.

What the Job does. One pod in openbao-drill, with the drill's steps and a snapshot first (components/openbao/preupgrade/job.yaml):

  1. check: if bao status fails with no such host, there is no openbao Service, so the cluster is new and has nothing to back up: every later step passes without doing anything. Any other error, or a sealed OpenBao, goes on to snapshot and fails there.
  2. snapshot (scripts/snapshot.sh): saves a Raft snapshot from openbao.openbao.svc with the openbao-backup AppRole and checks the archive.
  3. upload (scripts/store.sh upload): the nightly snapshot check, unchanged: plausible size, upload, exists, same SHA-256 when read back. It then points latest.env at this snapshot, which is a checked snapshot like any other, and leaves the same pointer in the pod's /work/latest.env.
  4. keys and drill (scripts/drill.sh): restore this snapshot (/work/openbao.snap, whose SHA-256 was just read back from the store) into a throwaway OpenBao on 127.0.0.1, restart it, unseal it with the real keys and read the canary. The gate does not read latest.env from the store, because the nightly run may have replaced it meanwhile.
  5. record (scripts/store.sh preupgrade): runs only if the drill passed. It writes <cluster>/openbao/preupgrade/last-success.env with POD, PASSED, KEY, TAKEN, TARGET_CHART and TARGET_IMAGE. This is the fresh, restore-verified backup that an upgrade's evidence, or a stateful step such as the restart window, cites.

Everything runs in memory, as in the drill: the snapshot, the keys and the restored data go with the pod. A failed gate leaves the openbao Kustomization waiting and fires OpenBaoPreupgradeGateFailed. OpenBao keeps running its old version.

Which version. The Job carries the chart version about to be applied (TARGET_CHART, equal to spec.chart.spec.version of the HelmRelease) and its server image (TARGET_IMAGE). Its containers run that image, so the gate also shows that the new version opens the old version's snapshot. A change of either changes the pod template, and kustomize.toolkit.fluxcd.io/force: Enabled recreates the Job. components/openbao/preupgrade/test_versions.py fails a pull request whose chart version differs from TARGET_CHART, or whose OpenBao images differ between the server, the CronJobs and the gate. A Renovate chart bump alone therefore fails CI until the gate is updated with it.

Why the gate owns openbao-drill. external-secrets, and so backup-store and openbao-backup, depend on openbao, so openbao-preupgrade cannot depend on them. The gate uses their Secrets and Role at run time. On a new cluster they do not exist yet. Every reference in the Job is therefore optional, the namespace, its NetworkPolicy and the ServiceAccount are in components/openbao/preupgrade/, and check lets the Job pass. On a running cluster a missing Secret fails its step, so the gate never passes without a backup. The scripts ConfigMap openbao-drill/openbao-backup-scripts, which the gate and the monthly drill share, is generated by components/openbao/backup/scripts/kustomization.yaml and applied by openbao-preupgrade: owned by openbao-backup, a change to the scripts would reach the gate only after OpenBao, which waits for the gate, so the gate would run the old scripts and never pass (incident 2026-10-24, #1565). The ConfigMap in openbao for the nightly snapshot stays with openbao-backup.

First run. When this gate is first applied, the Job runs once for the current chart (0.8.0, OpenBao 2.1.0), which gives incident #1542 the restore-verified backup it waits for.

Upgrading OpenBao

A Renovate pull request for the openbao chart (class stateful) also changes, in the same pull request:

  • TARGET_CHART and TARGET_IMAGE in components/openbao/preupgrade/job.yaml;
  • every quay.io/openbao/openbao image in components/openbao/base/helmrelease.yaml (prepare-data), components/openbao/backup/cron-job.yaml and the gate Job, to the new chart's server image (helm show chart openbao --repo https://openbao.github.io/openbao-helm --version <new>, its appVersion).

The server image is the chart's appVersion, which can lag OpenBao's own release: the HelmRelease does not set server.image.tag. Renovate does not bump these images itself (a packageRule in renovate.json disables quay.io/openbao/openbao under components/openbao/). quay.io has no release timestamps, so on their own the images skip the 14-day wait that holds back the chart: Skatzi/platform#866 brought chart 0.30.4 (appVersion v2.7.1) with images 2.7.2. The new OpenBao arrives with the chart that ships it, and the images follow in the chart's pull request.

scripts/check-openbao-images.py, in the render-and-validate job of manifest CI, fails a pull request whose OpenBao images or TARGET_IMAGE differ from the server image of the rendered chart. A chart bump alone therefore fails CI until the images are updated with it, and an image bump alone fails until the chart ships that version.

Check the new chart's StatefulSet against the live one for fields Kubernetes does not let an update change (podManagementPolicy, serviceName, selector, volumeClaimTemplates): a changed default fails the Helm upgrade. The HelmRelease pins server.podManagementPolicy: Parallel, the value chart 0.8.0 created the StatefulSet with, because chart 0.20.0 changed the default to OrderedReady (#1648); components/openbao/base/test_helmrelease.py keeps the pin.

After the merge, the gate runs, then Flux upgrades the HelmRelease. The StatefulSet is OnDelete, so a new image or other pod-template change starts only in the restart window, a person task. A chart bump that leaves the pod template unchanged needs none: the HelmRelease removes the chart's helm.sh/chart label from the pod template (#3377), so the version alone no longer creates a revision. To run the gate again without a version change, delete the Job: see OpenBaoPreupgradeGateFailed.

Alerts

Alert Severity Runbook
OpenBaoSnapshotFailed warning OpenBaoSnapshotFailed
OpenBaoRestoreDrillFailed critical OpenBaoRestoreDrillFailed
OpenBaoPreupgradeGateFailed critical OpenBaoPreupgradeGateFailed

All three are in the backups group of components/prometheus-stack/config/prometheus-rules.yaml, with component: openbao and incident: "true". The first two read the CronJobs' kube_cronjob_status_* series, the third the gate Job's kube_job_failed, all from kube-state-metrics.

Retention

  • <cluster>/openbao/snapshots/: expire after 30 days (backup_expiring_prefixes in the Terraform stage). The object lock keeps each one for at least 14 days, and the bucket rule removes non-current versions 31 days after that.
  • latest.env, drill/last-success.env and preupgrade/last-success.env are outside that prefix and never expire. A gate snapshot is in snapshots/ and expires after 30 days like the nightly ones. The newest snapshot is never older than a day, so latest.env always points at one that still exists.

Where the unseal keys come from

  • OpenBao was initialised with Shamir key shares. Three of them (key1..key3) are the Terraform variable openbao_unseal_keys in terraform/environments/hetzner-mgmt-cluster/2-components (local terraform.tfvars). Terraform writes them into the Secret openbao/openbao-unseal-keys, which the server mounts to auto-unseal and the drill reads.
  • A copy outside the cluster and outside any Terraform working copy is the person task #1378 (offline storage of the unseal keys and root token). Until that is done, losing the cluster and the tfvars together means a snapshot cannot be opened.
  • The keys are never in the backup bucket, in Git or in OpenBao.

Manual restore

Use this when OpenBao's data is lost or corrupt and production must be rebuilt from a snapshot. It needs the unseal keys and a person with cluster access.

  1. Pick the snapshot. With the backup-store keys and components/openbao/backup/scripts/s3.sh sourced, as the Jobs do:

    aws s3 cp "s3://$BUCKET/hetzner-mgmt/openbao/latest.env" -          # KEY, SHA256
    aws s3 ls "s3://$BUCKET/hetzner-mgmt/openbao/snapshots/"            # older ones
    aws s3 cp "s3://$BUCKET/<KEY>" openbao.snap && sha256sum openbao.snap
    
  2. Get an OpenBao that is running on Raft and unsealed. If the data is lost, start openbao-0 on an empty data volume (prepare-data creates the raft directory), then initialise it with a one-off key:

    kubectl --context admin@mgmt-cluster -n openbao exec -it openbao-0 -- bao operator init -key-shares=1 -key-threshold=1
    kubectl --context admin@mgmt-cluster -n openbao exec -it openbao-0 -- bao operator unseal <one-off key>
    

    The auto-unseal in postStart does nothing here, because the real keys do not open a new barrier.

  3. Restore. Use the one-off root token:

    kubectl --context admin@mgmt-cluster -n openbao cp openbao.snap openbao-0:/tmp/openbao.snap
    kubectl --context admin@mgmt-cluster -n openbao exec -it openbao-0 -- env BAO_TOKEN=<one-off root token> \
      bao operator raft snapshot restore -force /tmp/openbao.snap
    
  4. Unseal with the real keys. Restart first, for the reason given under the drill: kubectl --context admin@mgmt-cluster -n openbao delete pod openbao-0. postStart then unseals it with openbao-unseal-keys. Check with kubectl --context admin@mgmt-cluster -n openbao exec openbao-0 -- bao status: it should show Sealed false. Production's root token, policies, AppRoles and secrets are back. The one-off key and token are gone.

  5. Check. kubectl --context admin@mgmt-cluster get externalsecrets -A | grep -v SecretSynced, then force a sync where needed: kubectl --context admin@mgmt-cluster -n <ns> annotate externalsecret <name> force-sync=$(date +%s) --overwrite.

Anything written to OpenBao after the snapshot was taken (at most a day) is lost: rotated agent-runner logins, for example. Those components write their values again on their next rotation.