docs: add OpenBao backup setup to runbooks
This commit is contained in:
1 parent
b50aca4aff
commit
d1c7412f07
2 files changed
+146
-5
No files matched your search
@@ -146,9 +146,89 @@ Only do this once steps 5 and 6 have worked. Check that Bitwarden has the admin
|
||||
|
||||
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**.
|
||||
|
||||
## Set up backup storage
|
||||
## Automatic backups
|
||||
|
||||
After first setup, [install RustFS on TrueNAS](truenas-rustfs.md). The runbook covers TrueNAS, Cloudflare, pfSense and RustFS. **This doesn't turn on automatic backups yet**, so keep [saving snapshots manually](#save-a-snapshot).
|
||||
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. 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_<date>-<time>.snapshot` file. Delete the job afterwards with `kubectl -n openbao delete job openbao-snapshot-manual`.
|
||||
|
||||
### Check backups
|
||||
|
||||
```bash
|
||||
kubectl -n openbao get cronjob openbao-snapshot
|
||||
kubectl -n openbao get jobs -l app.kubernetes.io/component=snapshot-agent
|
||||
```
|
||||
|
||||
**Checkpoint:** `LAST SCHEDULE` is less than an hour ago, and recent jobs show `Complete`. For a failed job, check its logs with `kubectl -n openbao logs job/<job-name>`.
|
||||
|
||||
### Download a backup
|
||||
|
||||
Set up the `admin` function from [step 8 of the RustFS runbook](truenas-rustfs.md#8-create-the-backup-bucket-and-user), then:
|
||||
|
||||
```bash
|
||||
admin s3api list-objects-v2 --bucket openbao-backups --query 'Contents[].[Key,LastModified,Size]' --output text | sort -k2 | tail -5
|
||||
admin s3api get-object --bucket openbao-backups --key <snapshot-file> <snapshot-file>
|
||||
```
|
||||
|
||||
The file is saved in the current folder. Use it with [Restore into a new OpenBao](#restore-into-a-new-openbao). The job doesn't check its snapshots, so a backup is only proven once a restore from it has been tested.
|
||||
|
||||
## Unseal after a restart
|
||||
|
||||
@@ -196,7 +276,7 @@ Changes to the OpenBao version or its config only take effect after you restart
|
||||
|
||||
## Save a snapshot
|
||||
|
||||
Do this before upgrades and after important changes. Snapshots aren't automatic yet.
|
||||
Do this before upgrades and after important changes, even with [automatic backups](#automatic-backups).
|
||||
|
||||
1. Set [`$POD`](#rules), then log in as `admin`:
|
||||
|
||||
|
||||
Reference in new issue
Block a user