Compare commits
12
Commits
39d3e6cb6f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f6c71c3a3a | ||
|
|
6108d6dbf5 | ||
|
|
7586d8af31 | ||
|
|
063688746e | ||
|
|
86af2c6fcb | ||
|
|
d1c7412f07 | ||
|
|
b50aca4aff | ||
|
|
22d2320e3d | ||
|
|
0f3d4dcb22 | ||
|
|
2091607f0d | ||
|
|
d815334b04 | ||
|
|
4ae597cfc4 |
No files matched your search
+104
-9
@@ -26,6 +26,12 @@ const worker2Ip = config.requireSecret("worker2Ip");
|
||||
const worker3Ip = config.requireSecret("worker3Ip");
|
||||
|
||||
const ansibleIp = config.requireSecret("ansibleIp");
|
||||
const runnerIp = config.requireSecret("runnerIp");
|
||||
// Generated on the Ansible node and used only for the runner VM, so access to
|
||||
// the runner (and the CI credentials on it) can be revoked on its own.
|
||||
const runnerAnsibleSshPublicKey = config.requireSecret(
|
||||
"runnerAnsibleSshPublicKey",
|
||||
);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// VM templates — one per node, cloned from the downloaded cloud image.
|
||||
@@ -332,21 +338,21 @@ k3sVms.forEach((vmResource, i) => {
|
||||
// boot; otherwise its first DHCP lease could come from the dynamic pool.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const ansibleHost = hostFor("pve-b550");
|
||||
const proxmoHost = hostFor("pve-b550");
|
||||
const ansibleMac = "02:A5:1B:00:01:54";
|
||||
|
||||
const ansibleTemplate = new proxmox.download.File(
|
||||
const ubuntuTemplate = new proxmox.download.File(
|
||||
"ubuntu-resolute-lxc-pve-b550",
|
||||
{
|
||||
nodeName: ansibleHost.nodeName,
|
||||
datastoreId: ansibleHost.isoStore,
|
||||
nodeName: proxmoHost.nodeName,
|
||||
datastoreId: proxmoHost.isoStore,
|
||||
contentType: "vztmpl",
|
||||
fileName: "ubuntu-26.04-standard_26.04-1_amd64.tar.zst",
|
||||
url: "https://download.proxmox.com/images/system/ubuntu-26.04-standard_26.04-1_amd64.tar.zst",
|
||||
overwrite: false,
|
||||
overwriteUnmanaged: true,
|
||||
},
|
||||
{ provider: ansibleHost.provider },
|
||||
{ provider: proxmoHost.provider },
|
||||
);
|
||||
|
||||
const ansibleDhcp = new pfsense.Dhcpv4Staticmapping(
|
||||
@@ -363,18 +369,18 @@ const ansibleDhcp = new pfsense.Dhcpv4Staticmapping(
|
||||
new proxmox.ContainerLegacy( // NOSONAR typescript:S1848
|
||||
"ansible",
|
||||
{
|
||||
nodeName: ansibleHost.nodeName,
|
||||
nodeName: proxmoHost.nodeName,
|
||||
description: "Ansible control node — managed by Pulumi",
|
||||
tags: ["ansible"],
|
||||
unprivileged: true,
|
||||
features: { nesting: true },
|
||||
operatingSystem: {
|
||||
templateFileId: ansibleTemplate.id,
|
||||
templateFileId: ubuntuTemplate.id,
|
||||
type: "ubuntu",
|
||||
},
|
||||
cpu: { cores: 1 },
|
||||
memory: { dedicated: 1024, swap: 0 },
|
||||
disk: { datastoreId: ansibleHost.dataStore, size: 8 },
|
||||
disk: { datastoreId: proxmoHost.dataStore, size: 8 },
|
||||
networkInterfaces: [
|
||||
{ name: "eth0", bridge: "vmbr0", macAddress: ansibleMac },
|
||||
],
|
||||
@@ -394,13 +400,102 @@ new proxmox.ContainerLegacy( // NOSONAR typescript:S1848
|
||||
protection: true,
|
||||
},
|
||||
{
|
||||
provider: ansibleHost.provider,
|
||||
provider: proxmoHost.provider,
|
||||
dependsOn: ansibleDhcp,
|
||||
retainOnDelete: true,
|
||||
protect: true,
|
||||
},
|
||||
);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Gitea Runner — VM with a pfSense DHCP reservation.
|
||||
// A VM rather than an LXC: jobs run in Docker, and Docker in an LXC needs
|
||||
// nesting + keyctl, which widens the shared-kernel attack surface towards the
|
||||
// Proxmox host. The runner holds the most powerful credentials (Proxmox,
|
||||
// pfSense, Pulumi), so it gets its own kernel. Fixed MAC for the same reason
|
||||
// as the Ansible node: the reservation exists before the first boot.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const runnerMac = "02:A5:1B:00:01:55";
|
||||
|
||||
const runnerDhcp = new pfsense.Dhcpv4Staticmapping(
|
||||
"runner-dhcp",
|
||||
{
|
||||
interface: "lan",
|
||||
macAddress: runnerMac,
|
||||
ipAddress: runnerIp,
|
||||
hostname: "runner",
|
||||
},
|
||||
{ provider: pfSenseProvider, protect: true },
|
||||
);
|
||||
|
||||
new proxmox.VmLegacy( // NOSONAR typescript:S1848
|
||||
"runner",
|
||||
{
|
||||
nodeName: proxmoHost.nodeName,
|
||||
name: "runner",
|
||||
description: "Gitea Runner — managed by Pulumi",
|
||||
tags: ["runner"],
|
||||
clone: {
|
||||
vmId: proxmoHost.pveTemplate.vmId,
|
||||
full: true,
|
||||
datastoreId: proxmoHost.dataStore,
|
||||
},
|
||||
cpu: {
|
||||
cores: 2,
|
||||
sockets: 1,
|
||||
type: "host",
|
||||
numa: true,
|
||||
},
|
||||
memory: {
|
||||
dedicated: 4096,
|
||||
floating: 0,
|
||||
},
|
||||
disks: [
|
||||
{
|
||||
interface: "scsi0",
|
||||
datastoreId: proxmoHost.dataStore,
|
||||
size: 20,
|
||||
ssd: true,
|
||||
discard: "on",
|
||||
},
|
||||
],
|
||||
initialization: {
|
||||
datastoreId: proxmoHost.dataStore,
|
||||
ipConfigs: [{ ipv4: { address: "dhcp" } }],
|
||||
// Key-only login: no password, unlike the k3s nodes.
|
||||
userAccount: {
|
||||
username: "ubuntu",
|
||||
keys: [
|
||||
pve1SshPublicKey.apply((k) => k.trim()),
|
||||
pve2SshPublicKey.apply((k) => k.trim()),
|
||||
pve3SshPublicKey.apply((k) => k.trim()),
|
||||
runnerAnsibleSshPublicKey.apply((k) => k.trim()),
|
||||
],
|
||||
},
|
||||
},
|
||||
networkDevices: [
|
||||
{ bridge: "vmbr0", model: "virtio", macAddress: runnerMac },
|
||||
],
|
||||
scsiHardware: "virtio-scsi-pci",
|
||||
serialDevices: [{}],
|
||||
vga: { type: "serial0" },
|
||||
agent: { enabled: true, timeout: "30s" },
|
||||
cdrom: { fileId: "none" },
|
||||
started: true,
|
||||
onBoot: true,
|
||||
protection: true,
|
||||
rebootAfterUpdate: false,
|
||||
},
|
||||
{
|
||||
provider: proxmoHost.provider,
|
||||
dependsOn: runnerDhcp,
|
||||
retainOnDelete: true,
|
||||
protect: true,
|
||||
ignoreChanges: ["clone", "disks[0].speed"],
|
||||
},
|
||||
);
|
||||
|
||||
export const vmIds = {
|
||||
master1: k3sVms[0].vmId,
|
||||
master2: k3sVms[1].vmId,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
@@ -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,
|
||||
}),
|
||||
);
|
||||
@@ -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'`. 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
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ pulumi up --yes
|
||||
|
||||
Stack-specific notes:
|
||||
|
||||
1. **proxmox-infra** — set Proxmox API tokens, pfSense credentials, VM credentials/SSH public key, and a static IP per node.
|
||||
1. **proxmox-infra** — set Proxmox API tokens, pfSense credentials, VM credentials/SSH public key, and a static IP per node. The CI runner VM needs `runnerIp` and `runnerAnsibleSshPublicKey`, see [the runbook](docs/runbooks/ci-runner-vm.md).
|
||||
2. **k8s-bootstrap** — set `k3sToken` (e.g. `openssl rand -hex 32`) and `controlPlaneVipAddress` (secret; a free IP outside the DHCP pool, fronted by pfSense + HAProxy, see [the runbook](docs/runbooks/pfsense-control-plane-vip.md)). Node IPs, Proxmox credentials and the SSH key come automatically from `proxmox-infra`.
|
||||
3. **k8s-infra** — before deploying, create an NFS dataset/share on TrueNAS (POSIX ACLs, `root`/`root` maproot, restricted to your k3s nodes). Set `truenasHost`, `truenasNfsPath`, `cloudflareApiToken`, `letsencryptEmail`, `kubeVipAddress` (all secrets) and `kubeVipInterface`.
|
||||
4. **k8s-apps** — set `domain`, the base domain used for ingress hostnames.
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
# 0002: CI runner on a dedicated VM with Docker job containers
|
||||
|
||||
Status: accepted (December 2026)
|
||||
|
||||
## Context
|
||||
|
||||
The Gitea runner ran as a container on the shared Docker host, next to Gitea and Postgres, with the Docker socket mounted. A job that reached the socket had root on that host. Jobs in this repo also hold the most powerful credentials in the homelab: the Proxmox API tokens, pfSense access and the Pulumi passphrase.
|
||||
|
||||
## Decision
|
||||
|
||||
The runner runs on its own VM (`runner`, defined in `01-proxmox-infra`), outside the k3s cluster:
|
||||
|
||||
- act_runner runs as a systemd service, installed and configured by Ansible.
|
||||
- Each job runs in a fresh Docker container that is removed afterwards. Job containers don't get the Docker socket (`container.docker_host: "-"`), and `capacity: 1`.
|
||||
- The registration token is entered by hand at registration time and isn't stored anywhere.
|
||||
- SSH is key-only. Ansible uses a key that exists only for this VM.
|
||||
|
||||
## Alternatives considered
|
||||
|
||||
- **Unprivileged LXC with Docker:** Docker in an LXC needs `nesting` and `keyctl`, which widens the shared-kernel attack surface towards the Proxmox host. Proxmox itself recommends running Docker in a VM. For the host holding the strongest credentials, a separate kernel is worth the extra RAM.
|
||||
- **Host mode (no Docker):** jobs would leave files and tools behind for the next job and could read the runner's own credential (`.runner`). The security gain is small, because deploy secrets are in the job environment in either mode.
|
||||
- **Runner pods in k3s:** `01` and `02` create and repair the cluster, so the runner can't depend on it. Gitea also has no mature per-job pod autoscaler.
|
||||
|
||||
## Consequences
|
||||
|
||||
- When everything is down, recovery doesn't go through CI. You run `pulumi up` from the workstation instead.
|
||||
- Deploy secrets are still readable by any job. The real protection is scoping the credentials and filtering the runner's outbound traffic, both tracked separately.
|
||||
- Access to the runner VM is as sensitive as the CI credentials themselves. That includes the Ansible node, through its dedicated key.
|
||||
@@ -0,0 +1,27 @@
|
||||
# CI runner VM: first-time setup
|
||||
|
||||
The `runner` VM is defined in `01-proxmox-infra`. For the design, see [decision 0002](../decisions/0002-ci-runner-on-a-vm.md). Do this once, before the first deploy that creates the VM.
|
||||
|
||||
1. On the Ansible node, create a key that is used only for the runner VM:
|
||||
|
||||
```bash
|
||||
ssh-keygen -t ed25519 -f ~/.ssh/runner_vm -C ansible-runner-vm
|
||||
```
|
||||
|
||||
2. Set the config from the repo root, then commit and push it in the private config repo:
|
||||
|
||||
```bash
|
||||
cd 01-proxmox-infra
|
||||
pulumi config set --secret runnerIp <free IP outside the DHCP pool>
|
||||
pulumi config set --secret runnerAnsibleSshPublicKey "$(cat runner_vm.pub)" # copy of ~/.ssh/runner_vm.pub from the Ansible node
|
||||
```
|
||||
|
||||
3. Deploy `01-proxmox-infra`. Pulumi creates the pfSense DHCP reservation and the VM.
|
||||
|
||||
4. Check that the Ansible node can log in: `ssh -i ~/.ssh/runner_vm ubuntu@<runnerIp>`.
|
||||
|
||||
5. Install and register act_runner with the runner playbook in the Ansible repo. The playbook asks for a registration token: create one in Gitea, then reset it right after registering.
|
||||
|
||||
## Revoke access
|
||||
|
||||
To lock the Ansible node out of the runner VM, remove its key from `~ubuntu/.ssh/authorized_keys` on the VM. Changing the config alone isn't enough, because cloud-init only applies keys on the first boot.
|
||||
@@ -146,6 +146,90 @@ 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**.
|
||||
|
||||
## 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. 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 |
|
||||
@@ -192,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`:
|
||||
|
||||
|
||||
@@ -0,0 +1,285 @@
|
||||
# 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.
|
||||
|
||||
Old backups aren't cleaned up automatically yet. The bucket keeps growing until a cleanup rule has been tested and added.
|
||||
|
||||
## 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)
|
||||
Reference in new issue
Block a user