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
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 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
6 changed files with 264 additions and 12 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}`;
}
// Control-plane VIP — floating IP for API server access, ARP-announced by
// kube-vip on whichever master is alive. Added as a TLS SAN on master-1's
// cert below, then used (instead of master1Ip) for every other node's join
// URL and for the exported kubeconfig, so the cluster stays reachable
// through the loss of any single master.
// Kubernetes API address (port 6443), used by kubectl, Pulumi and joining nodes.
// pfSense holds this IP, and HAProxy forwards connections to the masters, so
// the API doesn't depend on a single master.
// This isn't kubeVipAddress in 03-k8s-infra, which is Traefik's IP for web apps.
const controlPlaneVipAddress = config.requireSecret("controlPlaneVipAddress");
// 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 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 kubeVipInterface = config.require("kubeVipInterface");
@@ -547,6 +551,7 @@ const kubeVipCloudProvider = new k8s.apps.v1.Deployment(
opts({ dependsOn: [cloudProviderClusterRoleBinding, kubeVipPool] }),
);
// Assigns kubeVipAddress to the Traefik Service that k3s creates.
new k8s.core.v1.ServicePatch(
"traefik-vip",
{
+84 -1
View File
@@ -8,9 +8,18 @@ const appsRef = new pulumi.StackReference(
`${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 domain = appsRef.requireOutput("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", {
kubeconfig,
@@ -116,6 +125,23 @@ const serversTransport = new k8s.apiextensions.CustomResource(
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(
"openbao",
{
@@ -202,6 +228,20 @@ new k8s.helm.v3.Release(
{ 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: {
@@ -254,7 +294,50 @@ audit "file" "stdout" {
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" }],
},
},
],
extraVolumeMounts: [
{ name: "openbao-ca", mountPath: "/openbao/tls", readOnly: true },
],
resources: {
requests: { cpu: "50m", memory: "64Mi" },
limits: { memory: "256Mi" },
},
},
},
},
opts({ dependsOn: [serversTransport], protect: true }),
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.
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'`.
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
+83 -3
View File
@@ -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, 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
@@ -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`:
+87 -2
View File
@@ -1,8 +1,8 @@
# 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. OpenBao's Helm chart has a backup job that can only upload to S3.
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.
> **Backups aren't set up yet.** This only covers installing RustFS. Don't create buckets, users or access keys until object lock, upload-only access, cleanup and restores have been tested. This setup was done with app catalog version `1.1.47` (RustFS `1.0.7`). DNS, HTTPS and console login work. Certificate renewal hasn't been tested. Menu names can differ between TrueNAS versions.
> 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
@@ -205,6 +205,89 @@ pfSense usually can't block devices on the same subnet from reaching TrueNAS. "E
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 |
@@ -215,6 +298,8 @@ After the certificate renews, run step 2 again. If it still shows the old expiry
| 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