Compare commits

...
Author SHA1 Message Date
kasun e416e6a555 docs: add RustFS backup cleanup and policy checks to runbooks
Secret Scan / Betterleaks (pull_request) Successful in 7s
Object lock only blocks deletion; it never removes old backups, and the
RustFS console has no lifecycle screen, so the rule is set with the AWS
CLI. Also note that a new policy must be attached to the user, which
caused the first backup job's AccessDenied.
2026-12-03 03:34:53 +01:00
kasun 063688746e Merge pull request 'Feature: Back up OpenBao to RustFS every hour' (#80) from feature/automate-openbao-backups into main
Deploy Openbao / Pulumi Preview (push) Skipped
Deploy Openbao / Pulumi Deploy (push) Successful in 43s
Secret Scan / Betterleaks (push) Successful in 5s
Reviewed-on: #80
2026-12-02 14:55:48 +01:00
kasun 86af2c6fcb docs: remove trailing space in CLAUDE.md
Deploy Openbao / Pulumi Deploy (pull_request) Skipped
Deploy Openbao / Pulumi Preview (pull_request) Successful in 1m29s
Secret Scan / Betterleaks (pull_request) Successful in 10s
2026-12-02 04:39:29 +01:00
kasun d1c7412f07 docs: add OpenBao backup setup to runbooks
Secret Scan / Betterleaks (pull_request) Successful in 6s
Deploy Openbao / Pulumi Deploy (pull_request) Skipped
Deploy Openbao / Pulumi Preview (pull_request) Successful in 43s
2026-12-02 04:29:17 +01:00
kasun b50aca4aff feature: back up OpenBao to RustFS every hour
Turns on the Helm chart's snapshot CronJob. It logs in with Kubernetes auth and uploads with an upload-only RustFS key, so it can't read or delete backups. Its own pruning is off because it would need delete access; object lock and RustFS lifecycle rules handle retention.
2026-12-02 04:29:16 +01:00
kasun 22d2320e3d docs: remove PR-only limit for Gitea script 2026-12-01 18:44:57 +01:00
kasun 0f3d4dcb22 docs: add RustFS on TrueNAS runbook 2026-12-01 18:44:57 +01:00
claude-bot Bot 2091607f0d Merge pull request 'Feature: Deploy OpenBao with high availability' (#79) from feature/deploy-openbao-ha into main
Deploy Openbao / Pulumi Preview (push) Skipped
Deploy Openbao / Pulumi Deploy (push) Successful in 41s
Secret Scan / Betterleaks (push) Successful in 5s
2026-12-01 04:48:17 +01:00
kasun 39d3e6cb6f docs: add OpenBao to rebuild runbook
Deploy k8s Infra / Pulumi Preview (pull_request) Successful in 39s
Deploy Monitoring / Pulumi Preview (pull_request) Successful in 39s
Deploy Openbao / Pulumi Preview (pull_request) Successful in 37s
Secret Scan / Betterleaks (pull_request) Successful in 5s
Deploy Proxmox Infra / Pulumi Preview (pull_request) Successful in 50s
Deploy Proxmox Infra / Pulumi Deploy (pull_request) Skipped
Deploy k8s Infra / Pulumi Deploy (pull_request) Skipped
Deploy k8s Apps / Pulumi Preview (pull_request) Successful in 34s
Deploy k8s Apps / Pulumi Deploy (pull_request) Skipped
Deploy Monitoring / Pulumi Deploy (pull_request) Skipped
Deploy Openbao / Pulumi Deploy (pull_request) Skipped
2026-12-01 04:35:39 +01:00
kasun d815334b04 Merge pull request 'Chore: Clarify Traefik and Kubernetes API addresses' (#78) from chore/clarify-vip-comments into main
Deploy k8s Infra / Pulumi Preview (push) Skipped
Deploy k8s Infra / Pulumi Deploy (push) Successful in 46s
Secret Scan / Betterleaks (push) Successful in 8s
Reviewed-on: #78
2026-12-01 04:29:42 +01:00
kasun 4ae597cfc4 chore: clarify Traefik and Kubernetes API addresses
Deploy k8s Bootstrap / Bootstrap k3s Cluster (pull_request) Skipped
Deploy k8s Infra / Pulumi Deploy (pull_request) Skipped
Deploy k8s Bootstrap / Pulumi Preview (pull_request) Successful in 35s
Deploy k8s Infra / Pulumi Preview (pull_request) Successful in 41s
Secret Scan / Betterleaks (pull_request) Successful in 6s
2026-12-01 04:25:14 +01:00
kasun 967bbeadc6 docs: add OpenBao runbook 2026-12-01 04:24:24 +01:00
7 changed files with 887 additions and 17 deletions

No files matched your search

+4 -5
View File
@@ -74,11 +74,10 @@ function k3sInstallScript(
return pulumi.interpolate`set -euo pipefail; IFS= read -r K3S_TOKEN || true; export K3S_TOKEN; curl -sfL ${k3sInstallerUrl} | sudo --preserve-env=K3S_TOKEN INSTALL_K3S_VERSION='${k3sVersion}' ${installEnv} sh -s - ${installArgs}`; return pulumi.interpolate`set -euo pipefail; IFS= read -r K3S_TOKEN || true; export K3S_TOKEN; curl -sfL ${k3sInstallerUrl} | sudo --preserve-env=K3S_TOKEN INSTALL_K3S_VERSION='${k3sVersion}' ${installEnv} sh -s - ${installArgs}`;
} }
// Control-plane VIP — floating IP for API server access, ARP-announced by // Kubernetes API address (port 6443), used by kubectl, Pulumi and joining nodes.
// kube-vip on whichever master is alive. Added as a TLS SAN on master-1's // pfSense holds this IP, and HAProxy forwards connections to the masters, so
// cert below, then used (instead of master1Ip) for every other node's join // the API doesn't depend on a single master.
// URL and for the exported kubeconfig, so the cluster stays reachable // This isn't kubeVipAddress in 03-k8s-infra, which is Traefik's IP for web apps.
// through the loss of any single master.
const controlPlaneVipAddress = config.requireSecret("controlPlaneVipAddress"); const controlPlaneVipAddress = config.requireSecret("controlPlaneVipAddress");
// VM IDs and CI runner SSH key — read from proxmox-infra stack outputs // VM IDs and CI runner SSH key — read from proxmox-infra stack outputs
+5
View File
@@ -16,6 +16,10 @@ const truenasNfsPath = config.requireSecret("truenasNfsPath");
const cloudflareToken = config.requireSecret("cloudflareApiToken"); const cloudflareToken = config.requireSecret("cloudflareApiToken");
const letsencryptEmail = config.requireSecret("letsencryptEmail"); const letsencryptEmail = config.requireSecret("letsencryptEmail");
// Traefik's IP for web apps (ports 80 and 443). kube-vip announces it on the
// LAN, and the app domains in pfSense's DNS Resolver must point to it.
// This isn't the Kubernetes API address. That's controlPlaneVipAddress in
// 02-k8s-bootstrap, which is provided by pfSense and HAProxy.
const kubeVipAddress = config.requireSecret("kubeVipAddress"); const kubeVipAddress = config.requireSecret("kubeVipAddress");
const kubeVipInterface = config.require("kubeVipInterface"); const kubeVipInterface = config.require("kubeVipInterface");
@@ -547,6 +551,7 @@ const kubeVipCloudProvider = new k8s.apps.v1.Deployment(
opts({ dependsOn: [cloudProviderClusterRoleBinding, kubeVipPool] }), opts({ dependsOn: [cloudProviderClusterRoleBinding, kubeVipPool] }),
); );
// Assigns kubeVipAddress to the Traefik Service that k3s creates.
new k8s.core.v1.ServicePatch( new k8s.core.v1.ServicePatch(
"traefik-vip", "traefik-vip",
{ {
+84 -1
View File
@@ -8,9 +8,18 @@ const appsRef = new pulumi.StackReference(
`${pulumi.getOrganization()}/k8s-apps/dev`, `${pulumi.getOrganization()}/k8s-apps/dev`,
); );
const config = new pulumi.Config();
const snapshotS3AccessKeyId = config.requireSecret("snapshotS3AccessKeyId");
const snapshotS3SecretAccessKey = config.requireSecret(
"snapshotS3SecretAccessKey",
);
const kubeconfig = bootstrapRef.requireOutput("kubeconfig"); const kubeconfig = bootstrapRef.requireOutput("kubeconfig");
const domain = appsRef.requireOutput("domain"); const domain = appsRef.requireOutput("domain");
const openbaoHost = pulumi.interpolate`bao.${domain}`; const openbaoHost = pulumi.interpolate`bao.${domain}`;
// RustFS on TrueNAS, see docs/runbooks/truenas-rustfs.md.
const snapshotS3Host = pulumi.interpolate`rustfs.${domain}:30292`;
const snapshotBucket = "openbao-backups";
const k8sProvider = new k8s.Provider("k3s", { const k8sProvider = new k8s.Provider("k3s", {
kubeconfig, kubeconfig,
@@ -116,6 +125,23 @@ const serversTransport = new k8s.apiextensions.CustomResource(
opts({ dependsOn: [serverCert] }), opts({ dependsOn: [serverCert] }),
); );
// Upload-only RustFS key for the snapshot CronJob. Object lock on the bucket
// keeps uploaded snapshots from being deleted or overwritten.
const snapshotS3Credentials = new k8s.core.v1.Secret(
"openbao-snapshot-s3",
{
metadata: {
name: "openbao-snapshot-s3",
namespace: openbaoNs.metadata.name,
},
stringData: {
AWS_ACCESS_KEY_ID: snapshotS3AccessKeyId,
AWS_SECRET_ACCESS_KEY: snapshotS3SecretAccessKey,
},
},
opts(),
);
new k8s.helm.v3.Release( new k8s.helm.v3.Release(
"openbao", "openbao",
{ {
@@ -202,6 +228,20 @@ new k8s.helm.v3.Release(
{ port: 8201, protocol: "TCP" }, { port: 8201, protocol: "TCP" },
], ],
}, },
{
from: [
{
podSelector: {
matchLabels: {
"app.kubernetes.io/name": "openbao",
"app.kubernetes.io/instance": "openbao",
"app.kubernetes.io/component": "snapshot-agent",
},
},
},
],
ports: [{ port: 8200, protocol: "TCP" }],
},
], ],
}, },
ha: { ha: {
@@ -254,7 +294,50 @@ audit "file" "stdout" {
size: "2Gi", size: "2Gi",
}, },
}, },
// Hourly Raft snapshots to RustFS. The job logs in to OpenBao with
// Kubernetes auth, set up by hand in docs/runbooks/openbao.md.
snapshotAgent: {
enabled: true,
schedule: "0 * * * *",
s3CredentialsSecret: "openbao-snapshot-s3",
config: {
s3Host: snapshotS3Host,
// s3cmd's --host-bucket. Using the host itself keeps requests
// path-style, so DNS doesn't need a record per bucket.
s3Bucket: snapshotS3Host,
s3Uri: `s3://${snapshotBucket}`,
// Empty turns off the agent's own pruning, which would need delete
// access. RustFS lifecycle rules handle retention instead.
s3ExpireDays: "",
// RustFS rejects s3cmd's default signing region, "US".
s3cmdExtraFlag: "-v --region=us-east-1",
baoAuthPath: "kubernetes",
baoRole: "openbao-snapshot",
},
extraEnvironmentVars: {
BAO_CACERT: "/openbao/tls/ca.crt",
},
extraVolumes: [
{
name: "openbao-ca",
secret: {
secretName: "openbao-server-tls",
items: [{ key: "ca.crt", path: "ca.crt" }],
}, },
}, },
opts({ dependsOn: [serversTransport], protect: true }), ],
extraVolumeMounts: [
{ name: "openbao-ca", mountPath: "/openbao/tls", readOnly: true },
],
resources: {
requests: { cpu: "50m", memory: "64Mi" },
limits: { memory: "256Mi" },
},
},
},
},
opts({
dependsOn: [serversTransport, snapshotS3Credentials],
protect: true,
}),
); );
+1 -1
View File
@@ -36,7 +36,7 @@ Branch names, commit messages and PR titles follow @CONVENTIONS.md. The commit-m
Only commit when I explicitly say "commit" for that change. A yes to a question that also mentioned committing is not enough; when unsure, ask. Only commit when I explicitly say "commit" for that change. A yes to a question that also mentioned committing is not enough; when unsure, ask.
The remote is a self-hosted Gitea, so `gh` doesn't work. For PRs and their CI status use `.claude/scripts/gitea.sh` (acts as `claude-bot`), e.g. `.claude/scripts/gitea.sh GET '/repos/kasun/homelab-infrastructure-as-code/pulls?state=open'`. Use it for PRs only, and ask before opening or merging one. The remote is a self-hosted Gitea, so `gh` doesn't work. For PRs and their CI status use `.claude/scripts/gitea.sh` (acts as `claude-bot`), e.g. `.claude/scripts/gitea.sh GET '/repos/kasun/homelab-infrastructure-as-code/pulls?state=open'`.
## Live infrastructure ## Live infrastructure
+11 -10
View File
@@ -7,17 +7,17 @@ Use this to rebuild the k3s cluster from new VMs. **It destroys everything store
## Why a normal `pulumi up` isn't enough ## Why a normal `pulumi up` isn't enough
- **`02-k8s-bootstrap` commands run once.** They are recorded as done in state, so after new VMs appear, `pulumi up` would report them unchanged and install nothing. - **`02-k8s-bootstrap` commands run once.** They are recorded as done in state, so after new VMs appear, `pulumi up` would report them unchanged and install nothing.
- **`03`–`05` state describes the old cluster.** The fixed `clusterIdentifier` tells Pulumi it is still the same cluster, so it would try to update resources that no longer exist. - **`03`–`06` state describes the old cluster.** The fixed `clusterIdentifier` tells Pulumi it is still the same cluster, so it would try to update resources that no longer exist.
## Before you start ## Before you start
1. **Save your data.** Longhorn has no backup target configured, so its volumes are lost with the VMs. That includes `heimdall-config` and the Prometheus metrics. Grafana's database is external and is not affected. 1. **Save your data.** Longhorn has no backup target configured, so its volumes are lost with the VMs. That includes `heimdall-config` and the Prometheus metrics. Grafana's database is external and is not affected. OpenBao's data is lost too, so [save a snapshot](openbao.md#save-a-snapshot) outside the cluster and keep its unseal key and admin password.
2. **Stop automatic deploys.** In Gitea's **Actions** tab, disable the `01`, `03`, `04` and `05` workflows, and don't merge anything until the last step. 2. **Stop automatic deploys.** In Gitea's **Actions** tab, disable the `01`, `03`, `04`, `05` and `06` workflows, and don't merge anything until the last step.
3. **Back up all state.** Run this from the repo root: 3. **Back up all state.** Run this from the repo root:
```bash ```bash
mkdir -p ~/state-backups/rebuild mkdir -p ~/state-backups/rebuild
for S in 01-proxmox-infra 02-k8s-bootstrap 03-k8s-infra 04-k8s-apps 05-monitoring; do for S in 01-proxmox-infra 02-k8s-bootstrap 03-k8s-infra 04-k8s-apps 05-monitoring 06-openbao; do
pulumi stack export --stack dev --cwd "$S" --file ~/state-backups/rebuild/$S.json pulumi stack export --stack dev --cwd "$S" --file ~/state-backups/rebuild/$S.json
done done
``` ```
@@ -57,17 +57,17 @@ Use this to rebuild the k3s cluster from new VMs. **It destroys everything store
pulumi up --stack dev --cwd 01-proxmox-infra pulumi up --stack dev --cwd 01-proxmox-infra
``` ```
## 2. Clear the state of `02`–`05` ## 2. Clear the state of `02`–`06`
Only do this after the old VMs are gone. It removes Pulumi's records and doesn't touch real resources or `Pulumi.dev.yaml`. `--force` is needed because `05-monitoring` protects its namespace and Helm release, so check that the old cluster is really gone before running it. Only do this after the old VMs are gone. It removes Pulumi's records and doesn't touch real resources or `Pulumi.dev.yaml`. `--force` is needed because `05-monitoring` and `06-openbao` protect their namespaces and Helm releases, so check that the old cluster is really gone before running it.
```bash ```bash
for S in 05-monitoring 04-k8s-apps 03-k8s-infra 02-k8s-bootstrap; do for S in 06-openbao 05-monitoring 04-k8s-apps 03-k8s-infra 02-k8s-bootstrap; do
pulumi state delete --all --force --yes --stack dev --cwd "$S" pulumi state delete --all --force --yes --stack dev --cwd "$S"
done done
``` ```
Previews of `03`–`05` fail until step 3 is done, because `02` has no `kubeconfig` output yet. Previews of `03`–`06` fail until step 3 is done, because `02` has no `kubeconfig` output yet.
## 3. Bootstrap k3s (`02-k8s-bootstrap`) ## 3. Bootstrap k3s (`02-k8s-bootstrap`)
@@ -89,13 +89,14 @@ Secret encryption is configured with `secretbox`.
**Checkpoint:** all six nodes are `Ready`. Then replace your normal kubeconfig with this file, because the old one no longer works. **Checkpoint:** all six nodes are `Ready`. Then replace your normal kubeconfig with this file, because the old one no longer works.
## 4. Deploy `03`, `04` and `05` ## 4. Deploy `03`–`06`
Deploy these through Gitea, because the runners have the `helm` CLI that `03` needs. Re-enable each workflow as you reach it, and wait for each run to finish. Deploy these through Gitea, because the runners have the `helm` CLI that `03` needs. Re-enable each workflow as you reach it, and wait for each run to finish.
1. Run the **Deploy k8s Infra** workflow manually. 1. Run the **Deploy k8s Infra** workflow manually.
2. Run the **Deploy k8s Apps** workflow manually. 2. Run the **Deploy k8s Apps** workflow manually.
3. Run the **Deploy Monitoring** workflow manually. 3. Run the **Deploy Monitoring** workflow manually.
4. Run the **Deploy Openbao** workflow manually, then [restore the OpenBao snapshot](openbao.md#restore-into-a-new-openbao).
## 5. Verify ## 5. Verify
@@ -109,4 +110,4 @@ kubectl get certificates -A
**Checkpoint:** nodes are `Ready`, no pods are unhealthy, PVCs are `Bound`, and certificates become `Ready`. New certificates come from Let's Encrypt, which rate-limits repeated requests for the same hostnames, so avoid repeated rebuilds in a short period. **Checkpoint:** nodes are `Ready`, no pods are unhealthy, PVCs are `Bound`, and certificates become `Ready`. New certificates come from Let's Encrypt, which rate-limits repeated requests for the same hostnames, so avoid repeated rebuilds in a short period.
Run `pulumi preview --stack dev --cwd <stack>` for all five stacks. None should show changes. Re-enable the `01` workflow, restore any data you saved, and delete `~/k3s-rebuilt.yaml` and `~/state-backups/rebuild`. Run `pulumi preview --stack dev --cwd <stack>` for all six stacks. None should show changes. Re-enable the `01` workflow, restore any data you saved, and delete `~/k3s-rebuilt.yaml` and `~/state-backups/rebuild`.
+473
View File
@@ -0,0 +1,473 @@
# 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 `<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:
```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.<domain>` 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.<domain>` 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_<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
| 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 |
1. Find the sealed pods, which show `0/1`:
```bash
kubectl -n openbao get pods -L openbao-active,openbao-sealed
```
2. Unseal each one, replacing `<n>` with its number:
```bash
kubectl -n openbao exec -it openbao-<n> -- bao operator unseal
```
3. 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](#save-a-snapshot).
1. Check that all three pods show `1/1`, and note which one is active:
```bash
kubectl -n openbao get pods -L openbao-active
```
2. Restart one **non-active** pod, then [unseal it](#unseal-after-a-restart):
```bash
kubectl -n openbao delete pod openbao-<n>
```
**Checkpoint:** all three pods show `1/1` before you restart the next one.
3. 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, even with [automatic backups](#automatic-backups).
1. Set [`$POD`](#rules), then log in as `admin`:
```bash
kubectl -n openbao exec -it "$POD" -- bao login -no-print -method=userpass username=admin
```
2. Save a snapshot and copy it to your workstation:
```bash
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.
3. Remove the copy and saved login from the pod:
```bash
kubectl -n openbao exec "$POD" -- bao token revoke -self
kubectl -n openbao exec "$POD" -- rm -f /home/openbao/openbao.snap /home/openbao/.vault-token
```
4. 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.
1. Deploy a new, empty OpenBao. Follow [First setup](#first-setup) steps 1–3, but save the new unseal key and root token as **temporary**. Don't replace the original key in Bitwarden.
2. Set [`$POD`](#rules), then log in with the **temporary root token**:
```bash
kubectl -n openbao exec -it "$POD" -- bao login -no-print
```
3. Check your `kubectl` context, because `-force` overwrites the data and skips the unseal key check:
```bash
kubectl config current-context
```
**Checkpoint:** 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:
```bash
kubectl config view --minify -o jsonpath='{.clusters[0].cluster.server}'; echo
```
4. Copy the snapshot to the pod and restore it:
```bash
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.snap
```
**Checkpoint:** both checksums match. Then run:
```bash
kubectl -n openbao exec "$POD" -- bao operator raft snapshot restore -force /home/openbao/restore.snap
```
5. Wait 10 seconds, then restart **all three** pods. Otherwise, the non-active pods keep using the temporary key and get stuck:
```bash
kubectl -n openbao delete pod openbao-0 openbao-1 openbao-2
```
6. Once all three are running, [unseal them](#unseal-after-a-restart) with the **original key**. The temporary key and root token no longer work, so delete them.
7. Set [`$POD`](#rules) again, log in as `admin` and check the cluster:
```bash
kubectl -n openbao exec -it "$POD" -- bao login -no-print -method=userpass username=admin
kubectl -n openbao exec "$POD" -- bao operator raft list-peers
```
**Checkpoint:** there's one leader and two followers, and your secrets are there. All three should show `Voter true`, but this can take a moment.
8. 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
```
## 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.
1. [Save a snapshot](#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`.
2. Set [`$POD`](#rules), log in as `admin`, then remove the lost pod from the Raft cluster. Replace `<n>` with its number:
```bash
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-peers
```
**Checkpoint:** only the two working pods are listed.
3. Delete **only the lost pod** and its PVC. Check the number first:
```bash
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.
4. Wait for the new pod to show `Running` and `Initialized true`. Don't run `init`. [Unseal it](#unseal-after-a-restart) and run `list-peers` again.
**Checkpoint:** all three pods are listed with `Voter true`, which can take a moment.
5. 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
```
## 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.
1. In `06-openbao/index.ts`, add this to the `listener "tcp"` block. Preview the change, then deploy it:
```hcl
disable_unauthed_generate_root_endpoints = false
```
2. [Restart all three pods](#restart-pods-after-a-change), one at a time.
3. Run this on your workstation. The `bao` command doesn't work for this without a login. Enter `https://bao.<domain>` and the unseal key when prompted. It cancels any unfinished attempt first:
```bash
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.py
```
Save 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.
4. Set [`$POD`](#rules) and log in with the new root token:
```bash
kubectl -n openbao exec -it "$POD" -- bao login -no-print
```
Set a new password with step 4.4 of [First setup](#4-create-the-admin-login). Then [test the login](#5-test-the-admin-login) and [revoke the root token](#7-revoke-the-root-token).
5. **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:
```bash
kubectl -n openbao get certificates
```
## References
- [OpenBao: Running on Kubernetes](https://openbao.org/docs/platform/k8s/helm/run/)
- [OpenBao: Raft commands](https://openbao.org/docs/commands/operator/raft/)
- [OpenBao: Raft API](https://openbao.org/docs/api/system/storage/raft/)
- [OpenBao: Username and password login](https://openbao.org/docs/auth/userpass/)
- [OpenBao: Generate a root token](https://openbao.org/docs/commands/operator/generate-root/)
- [OpenBao: Listener settings](https://openbao.org/docs/configuration/listener/tcp/)
+309
View File
@@ -0,0 +1,309 @@
# TrueNAS: RustFS for OpenBao backups (one-time setup)
Do this after the [first OpenBao setup](openbao.md#first-setup). It installs RustFS, an S3-compatible storage server, on TrueNAS and sets up HTTPS. Then it creates the bucket and upload-only user for [OpenBao's automatic backups](openbao.md#automatic-backups). OpenBao's Helm chart has a backup job that can only upload to S3.
> This setup was done on TrueNAS 25.10 with app catalog version `1.1.47` (RustFS `1.0.7`). These were tested on a temporary bucket: upload-only access, object lock (even the admin can't delete a locked version), uploads from OpenBao's backup image, and restoring RustFS data from a ZFS snapshot. **Not tested yet:** automatic cleanup of old backups, and certificate renewal. Menu names can differ between TrueNAS versions.
## Placeholders
| Placeholder | Meaning |
|---|---|
| `<domain>` | Your domain, with DNS managed by Cloudflare |
| `<truenas-ip>` | TrueNAS's fixed local IP |
| `<pool>` | The TrueNAS pool that stores the backups |
| `<email>` | An email address you own |
| `<timezone>` | Your timezone |
## Rules
- **Don't expose RustFS to the internet.** Don't forward its ports in pfSense, and don't create an A, AAAA or CNAME record for `rustfs.<domain>` in Cloudflare.
- **Never give the cluster admin access to TrueNAS or RustFS.** Don't use the RustFS admin login for backups.
- **Don't share the RustFS dataset over NFS or SMB**, and don't add it to other apps. Anyone who can write to its files can bypass RustFS's access rules and object lock.
- Save passwords and tokens in Bitwarden. Never put them in Git, tickets, chats or commands.
- **Don't use the MinIO app.** TrueNAS has removed it from its catalog, and the open-source version no longer gets updates.
## 1. Check TrueNAS
1. Use a stable TrueNAS release, not a beta or release candidate. The current app catalog needs 24.10 or newer. If you need to upgrade, [back up the config with its secret seed](https://www.truenas.com/docs/scale/25.10/scaletutorials/systemsettings/updatescale/) and follow the [official upgrade path](https://www.truenas.com/docs/truenasupgrades/). **Don't upgrade the ZFS pools at the same time.** Older TrueNAS versions may not be able to open them afterwards.
2. Check that the pools are healthy and the existing NFS and SMB shares work.
3. Go to **Apps > Configuration > Settings**. Under **Preferred Trains**, select **community** and keep **stable** selected. Save.
4. Go to **Apps > Discover Apps**, refresh the catalog and search for **RustFS**. Don't install it yet.
**Checkpoint:** RustFS is listed, and its **app version** is `1.0.7` or newer. This is different from the catalog version, such as `1.1.47`. Check the [RustFS security advisories](https://github.com/rustfs/rustfs/security/advisories) before installing or updating it.
## 2. Create the dataset
Don't use the dataset for the [`truenas-nfs` share](truenas-nfs.md), or create this one inside it. The k3s nodes have root access to that share, so a compromised node could change or delete the backups directly.
1. Go to **Datasets**, select the top level of `<pool>`, and click **Add Dataset**:
| Setting | Value |
|---|---|
| Name | `rustfs` |
| Dataset Preset | **Apps** |
| Quota | None for now. Set one once you know how much space the backups and ZFS snapshots need. New backups fail if it's too low. |
The path is `/mnt/<pool>/rustfs`.
2. Select `rustfs` and click **Edit** under **Permissions**. RustFS runs as TrueNAS's built-in `apps` user and group, both with ID `568`. Check that `apps` has **Modify** access. If it doesn't, add this NFSv4 ACL entry:
| Setting | Value |
|---|---|
| Who | **User** |
| User | `apps` |
| Type | **Allow** |
| Permissions | **Modify** |
| Flags | Keep the default inheritance setting, so new files and folders get the same access |
Don't add access for `everyone@`, use `777`, or change permissions on the top level of the pool. If the dataset is new and empty, you don't need to apply the ACL recursively. If TrueNAS shows **Read / Write / Execute** instead, stop. The dataset uses a different permission type.
**Checkpoint:** `apps` has **Modify** access. No NFS or SMB share includes `/mnt/<pool>/rustfs`, not even a share for a parent folder such as `/mnt/<pool>`.
This dataset **doesn't protect the backups if the whole pool fails**.
## 3. Add the pfSense DNS entry
Go to **Services > DNS Resolver > General Settings**. Under **Host Overrides**, click **Add**:
| Setting | Value |
|---|---|
| Host | `rustfs` |
| Domain | `<domain>` |
| IP Address | `<truenas-ip>`, **not** Traefik's IP |
| Description | `RustFS on TrueNAS` |
Save, then click **Apply Changes**. Check it from your workstation:
```bash
getent ahostsv4 rustfs.<domain>
```
**Checkpoint:** it only shows `<truenas-ip>`.
## 4. Create the Cloudflare token
Let's Encrypt uses a temporary DNS TXT record to check that you own the domain. TrueNAS adds it through Cloudflare, so RustFS doesn't need to be available from the internet. The hostname will appear in public certificate logs.
Use a separate token from pfSense and cert-manager. That way, you can replace or revoke it without breaking their certificates.
1. In Cloudflare, go to **My Profile > API Tokens > Create Token**. Use the **Edit zone DNS** template or create a custom token:
| Setting | Value |
|---|---|
| Token name | `truenas-acme` |
| Permission 1 | `Zone` → `DNS` → `Edit` |
| Permission 2 | `Zone` → `Zone` → `Read` |
| Zone Resources | `Include` → `Specific zone` → `<domain>` |
| Client IP Address Filtering | Empty. A filter can stop renewals if your public IP changes. |
| TTL | Empty. The certificate can't renew once the token expires. |
If you can't limit the token to `<domain>`, stop. Don't choose **All zones** to get around this.
2. Check the summary, then create the token. Save it in Bitwarden, because Cloudflare **only shows it once**. Don't run Cloudflare's test command with the real token in it, because it could be saved in your shell history.
## 5. Create the certificate in TrueNAS
1. Go to **Credentials > Certificates**. Under **ACME DNS-Authenticators**, click **Add**:
| Setting | Value |
|---|---|
| Name | `cloudflare` |
| Authenticator | `cloudflare` |
| Cloudflare Email | Empty |
| API Key | Empty. This is for the global API key. |
| API Token | The `truenas-acme` token |
2. Under **Certificate Signing Requests**, click **Add**:
| Setting | Value |
|---|---|
| Name | `rustfs`. This is only a label in TrueNAS. |
| Type | **Certificate Signing Request** |
| Profile | **HTTPS RSA Certificate** |
| Key Type / Key Length | **RSA** / `2048` |
| Digest Algorithm | **SHA256** |
| Common Name | `rustfs.<domain>` |
| Subject Alternative Name (SAN) | `rustfs.<domain>` |
| Email | `<email>` |
| Country, state, city and organisation | Fill in the required fields. Let's Encrypt doesn't include them in the certificate. |
| Basic Constraints | **Critical Extension** only. Don't select **CA**, because this certificate doesn't need to sign others. |
| Extended Key Usage | `SERVER_AUTH` only, with **Critical Extension** selected. `CLIENT_AUTH` isn't needed. |
| Key Usage | **Critical Extension**, **Digital Signature**, **Key Encipherment** and **Key Agreement**. Key Agreement isn't needed, but it's part of the tested setup. |
Enter only the hostname in **Common Name** and **SAN**, without `https://` or a port. Both must be **exactly the same**. Check the summary, then save.
3. Click the wrench icon next to the `rustfs` request to create an ACME certificate:
| Setting | Value |
|---|---|
| Identifier | `rustfs-le` |
| ACME Server Directory URI | Let's Encrypt **production**, not staging |
| Terms of Service | Accept |
| Renew Certificate Days | Default |
| Authenticator for `rustfs.<domain>` | `cloudflare` |
It can take a few minutes. If it fails, check the error before trying again, because Let's Encrypt has rate limits.
**Checkpoint:** `rustfs-le` is listed under **Certificates**, with Let's Encrypt as the issuer.
## 6. Install RustFS
Go to **Apps > Discover Apps**, select **RustFS** and click **Install**. Enter these settings:
| Section | Setting | Value |
|---|---|---|
| General | Application Name | `rustfs` |
| General | Version | `1.1.47`, or a newer version you've checked. This is the catalog version. |
| RustFS | Timezone | `<timezone>` |
| RustFS | Deployment Mode | **SNSD (Single Node Single Disk)**. RustFS uses one data location, so only the ZFS pool can protect against disk failures. |
| RustFS | Account Name | `rustfs-admin` |
| RustFS | Secret Key | A unique password with 40 random letters and numbers, saved in Bitwarden. Leaving out symbols such as `$` avoids possible config problems. |
| RustFS | Additional Environment Variables | None |
| User and Group | User ID / Group ID | `568` / `568` |
| Network | API Port | **Publish port on the host for external access**, port `30292` |
| Network | WebUI Port | **Publish port on the host for external access**, port `30293` |
| Network | Host IPs (both ports) | None. RustFS listens on all TrueNAS addresses. |
| Network | Networks | None |
| Network | Host Network | Off |
| Network | Certificate | `rustfs-le`. Don't choose **No Certificate** or the default TrueNAS certificate. |
| Storage | Data Disks | Keep one data disk and change its type from **ixVolume** to **Host Path** |
| Storage | Enable ACL | Off. The permissions were set in [step 2](#2-create-the-dataset). |
| Storage | Host Path | `/mnt/<pool>/rustfs` |
| Storage | Additional Storage | None |
| Labels | Labels | None |
| Resources | CPUs / Memory | `2` / `4096` MB. These are limits, not reserved resources. |
Before you click **Install**, check that the type is **Host Path** and the certificate is `rustfs-le`. **If you've already installed RustFS with an ixVolume, don't just change the path.** Its data, settings and users may not move with it.
pfSense usually can't block devices on the same subnet from reaching TrueNAS. "External access" here means access from outside the app's container. It doesn't expose the ports to the internet unless you also forward them.
**Checkpoint:** the app is **Running**. If it isn't, check its logs for permission or certificate errors. Don't use `777` to fix permission errors.
## 7. Check RustFS
1. Check both ports from your workstation:
```bash
curl -sS -o /dev/null -w 'S3: HTTP %{http_code}, TLS check %{ssl_verify_result}\n' https://rustfs.<domain>:30292/
curl -sS -o /dev/null -w 'Console: HTTP %{http_code}, TLS check %{ssl_verify_result}\n' https://rustfs.<domain>:30293/rustfs/console/
```
**Checkpoint:** S3 shows `HTTP 403`, which is expected without a login. The console shows `HTTP 200`. Both show `TLS check 0`, and there are no `curl` errors.
2. Check the certificate:
```bash
openssl s_client -connect rustfs.<domain>:30292 -servername rustfs.<domain> </dev/null 2>/dev/null \
| openssl x509 -noout -subject -issuer -enddate -ext subjectAltName
```
**Checkpoint:** the issuer is Let's Encrypt, and the SAN is `rustfs.<domain>`. Note the expiry date.
3. Open `https://rustfs.<domain>:30293/rustfs/console/` and log in as `rustfs-admin` with the Secret Key.
**Checkpoint:** the login works, and there's no certificate warning. Bookmark this link.
After the certificate renews, run step 2 again. If it still shows the old expiry date, RustFS hasn't loaded the new certificate. Restart the app, then check again.
## 8. Create the backup bucket and user
Object lock can only be turned on when a bucket is created. OpenBao's backup job uploads with an upload-only key, so it can't read, list, delete or unlock backups.
1. On your workstation, set up the AWS CLI in Docker. Paste the RustFS admin login when prompted. Nothing appears as you paste.
```bash
mkdir -p ~/rustfs && cd ~/rustfs
EP=https://rustfs.<domain>:30292
s3() { docker run --rm -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_REGION=us-east-1 -e AWS_ENDPOINT_URL="$EP" -v "$PWD:/aws:Z" docker.io/amazon/aws-cli:latest "$@"; }
read -rsp 'RustFS admin account name: ' A_ID; echo
read -rsp 'RustFS admin secret key: ' A_KEY; echo
admin() ( export AWS_ACCESS_KEY_ID="$A_ID" AWS_SECRET_ACCESS_KEY="$A_KEY"; s3 "$@" )
```
The functions and keys only exist in this terminal. In a new terminal, run this step again. RustFS expects the region `us-east-1`.
2. Create the bucket with a default lock of 30 days:
```bash
admin s3api create-bucket --bucket openbao-backups --object-lock-enabled-for-bucket
admin s3api put-object-lock-configuration --bucket openbao-backups --object-lock-configuration '{"ObjectLockEnabled":"Enabled","Rule":{"DefaultRetention":{"Mode":"GOVERNANCE","Days":30}}}'
admin s3api get-bucket-versioning --bucket openbao-backups
admin s3api get-object-lock-configuration --bucket openbao-backups
```
**Checkpoint:** versioning shows `Enabled`, and the lock shows `GOVERNANCE` with `30` days. `GOVERNANCE` means the backup user can't remove the lock. Unlike `COMPLIANCE`, an admin can still remove it to fix a mistake.
3. In the RustFS console, go to **Identity > Policies** and create `openbao-backups-upload`:
```json
{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["s3:PutObject"],"Resource":["arn:aws:s3:::openbao-backups/*"]}]}
```
4. Go to **Identity > Users** and create the backup user:
| Setting | Value |
|---|---|
| Name / access key | `openbao-snapshot` |
| Secret key | 40 random letters and numbers, saved in Bitwarden |
| Groups | **None.** A group would add its own policies. |
| Policies | **Only** `openbao-backups-upload`. Don't use built-in policies such as `writeonly` or `readwrite`, because they cover every bucket. |
5. Check the user's access:
```bash
read -rsp 'openbao-snapshot secret key: ' P_KEY; echo
prod() ( export AWS_ACCESS_KEY_ID=openbao-snapshot AWS_SECRET_ACCESS_KEY="$P_KEY"; s3 "$@" )
echo check > check.txt; prod s3api put-object --bucket openbao-backups --key setup-check.txt --body check.txt
prod s3api list-objects-v2 --bucket openbao-backups
prod s3api delete-object --bucket openbao-backups --key setup-check.txt
```
**Checkpoint:** the upload works, and listing and deleting both fail with `AccessDenied`. The test file stays locked for 30 days.
6. Protect the RustFS data with ZFS snapshots. Go to **Data Protection > Periodic Snapshot Tasks** and check that a task covers `<pool>/rustfs`, either directly or through a recursive task on its parent. Keep snapshots for at least 30 days. They protect backups if someone misuses the RustFS admin login. They don't protect against losing the pool.
7. Delete old backups automatically. The lock from step 2 only stops deletion for 30 days; it doesn't delete anything. Old snapshots also contain old secrets, so don't keep them forever. The RustFS console has no lifecycle screen, so set the rule with the AWS CLI:
```bash
cat > lifecycle.json <<'EOF'
{"Rules":[
{"ID":"expire-after-31-days","Status":"Enabled","Filter":{"Prefix":""},
"Expiration":{"Days":31},
"NoncurrentVersionExpiration":{"NoncurrentDays":1}},
{"ID":"remove-delete-markers","Status":"Enabled","Filter":{"Prefix":""},
"Expiration":{"ExpiredObjectDeleteMarker":true}}
]}
EOF
admin s3api put-bucket-lifecycle-configuration --bucket openbao-backups --lifecycle-configuration file://lifecycle.json
admin s3api get-bucket-lifecycle-configuration --bucket openbao-backups
```
**Checkpoint:** both rules show `"Status": "Enabled"`.
The bucket is versioned, so the rule needs three parts. After 31 days, when the lock has ended, a backup gets a delete marker. One day later, its data is deleted. Then the leftover delete marker is removed. Each backup is kept for about 32 days. Lifecycle rules respect the lock, so a backup can't be deleted early even if the rule is wrong.
About 32 days after the first backup, check that cleanup works. The oldest date shown should be at most about 32 days ago:
```bash
admin s3api list-object-versions --bucket openbao-backups --query 'Versions[].LastModified' --output text | tr '\t' '\n' | sort | head -3
```
## Troubleshooting
| Problem | What to do |
|---|---|
| TrueNAS links to `0.0.0.0` | This means RustFS listens on all addresses. It isn't an address you can open. Use the full console link from step 7, and leave **Host IPs** empty. |
| An `http://` link doesn't open | RustFS uses HTTPS on both ports. Use `https://`. |
| `https://rustfs.<domain>:30293/` shows `403` | Add the console path: `/rustfs/console/` |
| The browser shows a certificate warning | Use the hostname, not the IP. Then check that the app uses `rustfs-le` and that the SAN is correct. |
| The hostname doesn't work | Check the pfSense host override. If you've just added it, close and reopen the browser. You don't need to reinstall RustFS. |
| The certificate request fails | Check that **Common Name** and **SAN** are the same full hostname. Then check the Cloudflare token's permissions and domain. |
| `s3cmd` fails with `invalid credential region: "US"` | Add `--region=us-east-1`. The backup job already sets it. |
| Podman fails with `mkdir /run/user/<id>: permission denied` | Podman may have saved an old user ID. Use Docker instead, or fix Podman separately. |
## References
- [TrueNAS: RustFS app](https://apps.truenas.com/catalog/rustfs_community/)
- [TrueNAS: app setup](https://apps.truenas.com/getting-started/initial-setup)
- [RustFS: TLS](https://docs.rustfs.com/en/integration/tls-configured)
- [OpenBao: snapshot agent for Kubernetes](https://github.com/openbao/openbao-snapshot-agent/tree/main/kubernetes)