backup(portal): barman-cloud PITR via a Linode-side Garage WAL archive #19
12 changed files with 801 additions and 9 deletions
|
|
@ -24,6 +24,52 @@ spec:
|
||||||
memory: 256Mi
|
memory: 256Mi
|
||||||
limits:
|
limits:
|
||||||
memory: 1Gi
|
memory: 1Gi
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Point-in-time recovery: continuous WAL archiving + daily base backups into
|
||||||
|
# Garage on the Linode hub (10.10.0.5), i.e. a different power and internet
|
||||||
|
# domain from this primary. Companion object: ScheduledBackup portal-daily.
|
||||||
|
#
|
||||||
|
# Credentials live in Secret sirius-growth/portal-wal-s3 (created out of band
|
||||||
|
# from the Garage key `cnpg-portal-wal`, id GK7f2b4bb1fc9abaec50fde37b, scope
|
||||||
|
# read+write on bucket `pg-wal-archive` only). Never commit the key values.
|
||||||
|
#
|
||||||
|
# This uses the operator's in-tree barman-cloud integration rather than the
|
||||||
|
# CNPG-I barman-cloud plugin: same barman-cloud binaries, no extra Deployment
|
||||||
|
# and TLS plugin registration to keep alive on a 3-node homelab. The plugin is
|
||||||
|
# the migration path when 1.30's in-tree support is finally removed.
|
||||||
|
#
|
||||||
|
# `pg_dump` in forgejo/cluster-backup still runs nightly for this database as
|
||||||
|
# a second, logical copy: a dump survives a barman-format regression or a
|
||||||
|
# store that has been emptied, and it is the only copy that is readable
|
||||||
|
# without barman. Belt and braces, not redundancy theatre — the RPO comes
|
||||||
|
# from the WAL archive, not from the dump.
|
||||||
|
backup:
|
||||||
|
retentionPolicy: "14d"
|
||||||
|
barmanObjectStore:
|
||||||
|
# Bucket root, not bucket/portal: barman appends the server name (which
|
||||||
|
# defaults to the Cluster name), so the archive lives at
|
||||||
|
# s3://pg-wal-archive/portal/{base,wals}/... — one prefix per cluster,
|
||||||
|
# which is what lets forgejo/pg share this bucket later without colliding.
|
||||||
|
destinationPath: s3://pg-wal-archive
|
||||||
|
endpointURL: http://10.10.0.5:3900
|
||||||
|
s3Credentials:
|
||||||
|
accessKeyId:
|
||||||
|
name: portal-wal-s3
|
||||||
|
key: ACCESS_KEY_ID
|
||||||
|
secretAccessKey:
|
||||||
|
name: portal-wal-s3
|
||||||
|
key: ACCESS_SECRET_KEY
|
||||||
|
region:
|
||||||
|
name: portal-wal-s3
|
||||||
|
key: REGION
|
||||||
|
# gzip on both: this is a WAL stream over the WireGuard mesh to a fixed
|
||||||
|
# 20 GB store, so bytes on the wire and in the bucket are the cost.
|
||||||
|
wal:
|
||||||
|
compression: gzip
|
||||||
|
maxParallel: 2
|
||||||
|
data:
|
||||||
|
compression: gzip
|
||||||
|
jobs: 2
|
||||||
# Scraped via podmonitor.yaml in this directory (hand-written; see the comment
|
# Scraped via podmonitor.yaml in this directory (hand-written; see the comment
|
||||||
# in apps/base/forgejo/podmonitor.yaml for why enablePodMonitor is false).
|
# in apps/base/forgejo/podmonitor.yaml for why enablePodMonitor is false).
|
||||||
# Only the operator's default query set here — this database needs no custom
|
# Only the operator's default query set here — this database needs no custom
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ resources:
|
||||||
- service-portal-gate.yaml
|
- service-portal-gate.yaml
|
||||||
- httproute.yaml
|
- httproute.yaml
|
||||||
- cluster.yaml
|
- cluster.yaml
|
||||||
|
- scheduled-backup.yaml
|
||||||
- podmonitor.yaml
|
- podmonitor.yaml
|
||||||
- pvc-leadgen.yaml
|
- pvc-leadgen.yaml
|
||||||
- cronjob-leadgen.yaml
|
- cronjob-leadgen.yaml
|
||||||
|
|
|
||||||
19
apps/base/sirius-growth/scheduled-backup.yaml
Normal file
19
apps/base/sirius-growth/scheduled-backup.yaml
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
apiVersion: postgresql.cnpg.io/v1
|
||||||
|
kind: ScheduledBackup
|
||||||
|
metadata:
|
||||||
|
name: portal-daily
|
||||||
|
namespace: sirius-growth
|
||||||
|
spec:
|
||||||
|
# Six-field cron (seconds first — CNPG, not standard cron). 03:20 UTC, clear
|
||||||
|
# of the 02:37 forgejo/cluster-backup CronJob so the two do not fight for the
|
||||||
|
# primary's I/O on a laptop disk.
|
||||||
|
schedule: "0 20 3 * * *"
|
||||||
|
cluster:
|
||||||
|
name: portal
|
||||||
|
# `self`: the Backup objects are owned by this ScheduledBackup, so deleting the
|
||||||
|
# schedule (or the namespace) does not leave orphaned Backups pointing at the
|
||||||
|
# cluster. Retention/cleanup of the archive itself is the Cluster's
|
||||||
|
# spec.backup.retentionPolicy (14d), enforced by barman-cloud on each backup.
|
||||||
|
backupOwnerReference: self
|
||||||
|
method: barmanObjectStore
|
||||||
|
immediate: false
|
||||||
|
|
@ -311,6 +311,28 @@ Neither hostname is in the cloudflared ingress list, and `*.lab.internal` resolv
|
||||||
|
|
||||||
**What breaks:** anything that assumes `127.0.0.1:3902` (the removed static web endpoint) is reachable from inside the pod network. It never was — a pod's `127.0.0.1` is its own netns — and the listener is now gone. Kubernetes workloads must use the `10.10.0.1:3900` S3 endpoint, or the in-image `/photos/` alias baked into the site images as a fallback. That alias is a deliberate fallback, **not** evidence the bucket is gone.
|
**What breaks:** anything that assumes `127.0.0.1:3902` (the removed static web endpoint) is reachable from inside the pod network. It never was — a pod's `127.0.0.1` is its own netns — and the listener is now gone. Kubernetes workloads must use the `10.10.0.1:3900` S3 endpoint, or the in-image `/photos/` alias baked into the site images as a fallback. That alias is a deliberate fallback, **not** evidence the bucket is gone.
|
||||||
|
|
||||||
|
### 5.1 A *second*, unrelated Garage node: the WAL archive on the Linode
|
||||||
|
|
||||||
|
`infrastructure/garage-linode/` (not Flux-applied, like the Pi's) runs a
|
||||||
|
single-node Garage on the **Linode hub** and holds exactly one bucket,
|
||||||
|
`pg-wal-archive`, for CloudNativePG point-in-time recovery (§8.1, §8.3).
|
||||||
|
|
||||||
|
| Property | Value |
|
||||||
|
|---|---|
|
||||||
|
| Where | Linode VPS (`linode` node), **podman** + quadlet `/etc/containers/systemd/garage.container` — there is no Docker on a kubelet node |
|
||||||
|
| Node | `994fd2f42ae72da6`, zone `dc1`, capacity **20 GB**, `replication_factor = 1` — a separate store with its own `node_key`, **not** a peer of the Pi's node |
|
||||||
|
| Endpoint | `http://10.10.0.5:3900` (S3) — the dummy-k8s WireGuard address, reachable from every pod over the mesh. `:3903` metrics, mesh-only, not scraped yet |
|
||||||
|
| Config | `garage.toml` binds those two addresses explicitly (no `0.0.0.0`), RPC secret from `/etc/garage/garage.env` (0600, not in git) |
|
||||||
|
| Firewall | nft `inet wal_archive_guard`, PREROUTING priority -140: accept `lo`/`wg0` (+ pod CIDR), drop everything else. ufw on this host is unrelated and stays as it is |
|
||||||
|
| State | `/var/lib/garage/{meta,data}`, covered by the nightly cluster-backup tree on the same host |
|
||||||
|
| Bucket | `pg-wal-archive` — private (`Website access: false`, anonymous GET → 403) |
|
||||||
|
| Keys | `cnpg-portal-wal` (`GK7f2b4bb1fc9abaec50fde37b`, RW on that bucket only) → Secret `sirius-growth/portal-wal-s3` |
|
||||||
|
|
||||||
|
This node exists **because of where it is**, not because the estate needed a
|
||||||
|
second S3 service: a WAL archive on the Pi would sit in the same building, power
|
||||||
|
domain and uplink as the CNPG primary on siriussec. Off-site or it is not a
|
||||||
|
backup.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 6. Workloads
|
## 6. Workloads
|
||||||
|
|
@ -492,11 +514,11 @@ StorageClass `local-path` (default, `WaitForFirstConsumer`, no expansion), provi
|
||||||
|
|
||||||
**Dind growth hazard.** The amd64 runner's PVC is nominally 20 Gi and currently sits at **~22 G**: it has previously grown to ~50 GB from heavy Android/Rust builds and pushed the node into `DiskPressure`, which evicted the runner and left Forgejo and `pg-1` Pending. Docker image GC does not reclaim the data-root. Rule: when it approaches the cap, scale the runner to 0 **first**, then wipe `.../docker/*` (keeping `runner.ini` beside it), then scale back and re-pull the job image — wiping it under a live or restarting pod leaves `dockerd` half-initialised and every pull fails. Note the data-root also hosts the named volumes CI depends on (`cargo-target`, Android SDK, Gradle cache), so a wipe makes the next run fully cold.
|
**Dind growth hazard.** The amd64 runner's PVC is nominally 20 Gi and currently sits at **~22 G**: it has previously grown to ~50 GB from heavy Android/Rust builds and pushed the node into `DiskPressure`, which evicted the runner and left Forgejo and `pg-1` Pending. Docker image GC does not reclaim the data-root. Rule: when it approaches the cap, scale the runner to 0 **first**, then wipe `.../docker/*` (keeping `runner.ini` beside it), then scale back and re-pull the job image — wiping it under a live or restarting pod leaves `dockerd` half-initialised and every pull fails. Note the data-root also hosts the named volumes CI depends on (`cargo-target`, Android SDK, Gradle cache), so a wipe makes the next run fully cold.
|
||||||
|
|
||||||
Host disks *(live)*: siriussec `/` 214 G, 167 G used (**83 %**, 37 G free); rpi `/` 917 G, 506 G used (58 %, 374 G free); linode `/` 79 G, 11 G used (**14 %**, 64 G free — this is the backup target).
|
Host disks *(live)*: siriussec `/` 214 G, 167 G used (**83 %**, 37 G free); rpi `/` 917 G, 506 G used (58 %, 374 G free); linode `/` 79 G, 29 G used (**39 %**, 46 G free — this is the backup target, and since 2026-11-19 it also hosts the `pg-wal-archive` Garage node).
|
||||||
|
|
||||||
### 8.1 Backup coverage
|
### 8.1 Backup coverage
|
||||||
|
|
||||||
Three independent scheduled paths, all **off** the T480 and **off** the Pi:
|
Five independent scheduled paths, all **off** the T480 and **off** the Pi:
|
||||||
|
|
||||||
1. **Cluster state → Linode VPS**, CronJob `forgejo/cluster-backup`
|
1. **Cluster state → Linode VPS**, CronJob `forgejo/cluster-backup`
|
||||||
(`apps/base/forgejo/cluster-backup.yaml`; exec-only RBAC in
|
(`apps/base/forgejo/cluster-backup.yaml`; exec-only RBAC in
|
||||||
|
|
@ -515,15 +537,24 @@ Three independent scheduled paths, all **off** the T480 and **off** the Pi:
|
||||||
3. **Garage object store (Pi) → same Linode**, `infrastructure/garage/backup/`
|
3. **Garage object store (Pi) → same Linode**, `infrastructure/garage/backup/`
|
||||||
`garage-meta-backup.timer` (hourly) + `garage-data-backup.timer` (nightly) →
|
`garage-meta-backup.timer` (hourly) + `garage-data-backup.timer` (nightly) →
|
||||||
`[email protected]:/root/garage-backup`.
|
`[email protected]:/root/garage-backup`.
|
||||||
|
4. **Point-in-time recovery for `sirius-growth/portal`**, continuous WAL archiving
|
||||||
|
+ a daily base backup straight from the CNPG operator into a **second Garage
|
||||||
|
node running on the Linode** (`infrastructure/garage-linode/`, bucket
|
||||||
|
`pg-wal-archive`, bucket-private, `10.10.0.5:3900` WireGuard-only). This is the
|
||||||
|
only path with a **sub-24 h RPO**: recovery to any second inside the last 14
|
||||||
|
days, not just "the state at 02:37". Config:
|
||||||
|
`apps/base/sirius-growth/cluster.yaml` `spec.backup.barmanObjectStore` +
|
||||||
|
`apps/base/sirius-growth/scheduled-backup.yaml` (`ScheduledBackup portal-daily`,
|
||||||
|
`20 3 * * *` UTC in **six**-field cron, seconds first).
|
||||||
|
|
||||||
A fourth path covers the Pi's own hub state: `infrastructure/wireguard/backup/`
|
A fifth path covers the Pi's own hub state: `infrastructure/wireguard/backup/`
|
||||||
`wireguard-backup.timer` (nightly 04:13) → `[email protected]:/root/pihost-backup`.
|
`wireguard-backup.timer` (nightly 04:13) → `[email protected]:/root/pihost-backup`.
|
||||||
|
|
||||||
| Artifact | Method | On the Linode | Retention |
|
| Artifact | Method | On the Linode | Retention |
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| `forgejo-data` PVC (`/data`) | `rsync -a --delete --link-dest` snapshot mirror, PVC mounted read-only | `forgejo-data/<stamp>/` + `latest` symlink | 7 snapshots (hardlinked: 1 full copy + nightly deltas) |
|
| `forgejo-data` PVC (`/data`) | `rsync -a --delete --link-dest` snapshot mirror, PVC mounted read-only | `forgejo-data/<stamp>/` + `latest` symlink | 7 snapshots (hardlinked: 1 full copy + nightly deltas) |
|
||||||
| `forgejo/pg` | `pg_dump -Fc -Z6` **inside the CNPG primary** over the local socket — no DB password exists in git or in the Job | `db/forgejo-pg-<stamp>.dump` | 14 |
|
| `forgejo/pg` | `pg_dump -Fc -Z6` **inside the CNPG primary** over the local socket — no DB password exists in git or in the Job | `db/forgejo-pg-<stamp>.dump` | 14 |
|
||||||
| `sirius-growth/portal` | same, through exec RBAC in `sirius-growth` | `db/sirius-growth-portal-<stamp>.dump` | 14 |
|
| `sirius-growth/portal` | two independent copies, on purpose. **(a)** `pg_dump -Fc -Z6` **inside the CNPG primary** over the local socket, through exec RBAC in `sirius-growth` — logical, human-readable with any `pg_restore`. **(b)** barman-cloud **continuous WAL archive + daily base backup** (path 4) | (a) `db/sirius-growth-portal-<stamp>.dump`; (b) `pg-wal-archive` bucket on the Linode: `portal/base/<stamp>/` + `portal/wals/…` | (a) 14 dumps; (b) 14 days of WAL (`retentionPolicy: 14d`) |
|
||||||
| `osint/osint-db` (plain Postgres Deployment, has TimescaleDB + PostGIS) | `pg_dump -Fc -Z6` **inside the pod** over the local socket, using its own `POSTGRES_USER`/`POSTGRES_DB` via exec RBAC in `osint` | `db/osint-osint-db-<stamp>.dump` | 14 |
|
| `osint/osint-db` (plain Postgres Deployment, has TimescaleDB + PostGIS) | `pg_dump -Fc -Z6` **inside the pod** over the local socket, using its own `POSTGRES_USER`/`POSTGRES_DB` via exec RBAC in `osint` | `db/osint-osint-db-<stamp>.dump` | 14 |
|
||||||
| `grafana.db` (sqlite) | **sqlite backup API** in a `python:3.12-alpine` pod that mounts the PVC — a `cp` of a live db can capture a torn page; the image is `-distroless`, so there is no shell to exec into | `grafana/grafana-<stamp>.db` | 14 |
|
| `grafana.db` (sqlite) | **sqlite backup API** in a `python:3.12-alpine` pod that mounts the PVC — a `cp` of a live db can capture a torn page; the image is `-distroless`, so there is no shell to exec into | `grafana/grafana-<stamp>.db` | 14 |
|
||||||
| `sgs-leadgen-data` PVC | `rsync -a --delete --link-dest` snapshot mirror, PVC mounted read-only | `leadgen-data/<stamp>/` + `latest` | 7 |
|
| `sgs-leadgen-data` PVC | `rsync -a --delete --link-dest` snapshot mirror, PVC mounted read-only | `leadgen-data/<stamp>/` + `latest` | 7 |
|
||||||
|
|
@ -546,6 +577,44 @@ A fourth path covers the Pi's own hub state: `infrastructure/wireguard/backup/`
|
||||||
- The Job lives in namespace `forgejo` (not a `backup` namespace) because a PVC
|
- The Job lives in namespace `forgejo` (not a `backup` namespace) because a PVC
|
||||||
cannot be mounted cross-namespace and `forgejo-data` is the largest artifact.
|
cannot be mounted cross-namespace and `forgejo-data` is the largest artifact.
|
||||||
|
|
||||||
|
- **The WAL archive lives in a second Garage node on the Linode, and only there.**
|
||||||
|
Pointing barman at the Pi's Garage would put the archive in the same building,
|
||||||
|
power domain and uplink as the CNPG primary — a second copy of the same
|
||||||
|
failure. `infrastructure/garage-linode/` is a *separate* single-node store
|
||||||
|
(node `994fd2f42ae72da6`, capacity 20 GB, no relation to the Pi's
|
||||||
|
`d053db4dfc97bf78`): podman + a quadlet unit (this host has no Docker — it is a
|
||||||
|
kubelet node), `garage.toml` binding `10.10.0.5:3900`/`:3903` only, and an nft
|
||||||
|
table `inet wal_archive_guard` (PREROUTING -140) that drops 3900/3903 from
|
||||||
|
anything but `lo`/`wg0`. Measured off-mesh (from this laptop, straight to the
|
||||||
|
Linode's public IP, no VPN in the path): 3900 and 3903 **filtered**, and the
|
||||||
|
drop counter increments. Anonymous S3 GET on the bucket → **403 AccessDenied**.
|
||||||
|
- **Disk sizing for the WAL archive** *(measured 2026-11-19)*: Linode `/` is 79 G
|
||||||
|
with **46 G free**; Garage is capped at 20 GB. Actual usage after the first
|
||||||
|
base backup + 7 WAL segments: **4.9 MB** in 8 bucket objects (`data/` 9.3 MB
|
||||||
|
with Garage's block-store overhead, `meta/` 4.6 MB). `archive_timeout` is 5 min
|
||||||
|
and `wal_segment_size` 16 MB, so the archive takes at most 288 segments/day;
|
||||||
|
gzip turns a segment into 16–25 KB when the database is quiet (measured) →
|
||||||
|
~6 MB WAL/day + a 4.5 MB base backup/day ≈ **150 MB for the whole 14-day
|
||||||
|
window**. Worst case on a busy database (every segment full at a typical 3–5×
|
||||||
|
gzip ratio) is ~1.5 GB/day → 21 GB for 14 days, i.e. it would hit the 20 GB
|
||||||
|
cap. The cap is deliberate: Garage answers `507 InsufficientStorage` and
|
||||||
|
`barman-cloud-backup` fails loudly (red `Backup`/`ScheduledBackup`) rather
|
||||||
|
than filling the Linode disk. If that ever fires, the lever is
|
||||||
|
`spec.backup.retentionPolicy` (7d) — not deleting WALs by hand.
|
||||||
|
- **The barman credentials are a namespaced Secret, not git**:
|
||||||
|
`sirius-growth/portal-wal-s3` (`ACCESS_KEY_ID` / `ACCESS_SECRET_KEY` /
|
||||||
|
`REGION`), created out of band from Garage key `cnpg-portal-wal`
|
||||||
|
(`GK7f2b4bb1fc9abaec50fde37b`, scope **read+write on `pg-wal-archive` only**,
|
||||||
|
no bucket-create). Recording key IDs is fine; the values are not in git, in the
|
||||||
|
docs, or in any comment.
|
||||||
|
- **CNPG 1.30 still ships the in-tree barman-cloud integration, and it warns that
|
||||||
|
1.31 removes it** (`Warning: Native support for Barman Cloud backups and
|
||||||
|
recovery is deprecated ... Please migrate existing clusters to the new Barman
|
||||||
|
Cloud Plugin`). That is why this is on 1.30 only: the plugin (an extra
|
||||||
|
Deployment + CNPG-I registration + TLS) is the migration path, and it must land
|
||||||
|
before the operator goes to 1.31. Nothing else here changes when it does — the
|
||||||
|
bucket layout stays `portal/base` + `portal/wals`.
|
||||||
|
|
||||||
**Accepted gaps (with the reason, not just a TODO):**
|
**Accepted gaps (with the reason, not just a TODO):**
|
||||||
|
|
||||||
- **Prometheus TSDB** (2.4 GiB) — deliberately excluded: regenerated metrics
|
- **Prometheus TSDB** (2.4 GiB) — deliberately excluded: regenerated metrics
|
||||||
|
|
@ -561,10 +630,21 @@ A fourth path covers the Pi's own hub state: `infrastructure/wireguard/backup/`
|
||||||
- **Pi `/etc/wireguard` is only as fresh as the last nightly run** — a peer
|
- **Pi `/etc/wireguard` is only as fresh as the last nightly run** — a peer
|
||||||
added today is in the db and on the Pi, and reaches the Linode at 04:13.
|
added today is in the db and on the Pi, and reaches the Linode at 04:13.
|
||||||
|
|
||||||
A new CloudNativePG cluster is **not** picked up automatically: add
|
**Closed 2026-11-19 — point-in-time recovery.** There is no longer a "restore to
|
||||||
`<ns>/<cluster>` to `CNPG_TARGETS` in the CronJob env *and* an equivalent
|
02:37 or lose the day" gap: `sirius-growth/portal` can be recovered to any second
|
||||||
exec-only Role/RoleBinding for the `forgejo/cluster-backup` ServiceAccount in
|
inside the 14-day window, and that restore has been rehearsed end to end (§8.3).
|
||||||
that namespace.
|
`forgejo/pg` is deliberately **not** on barman yet — a day of git history is
|
||||||
|
annoying, not costly, and one cluster proves the pattern; `osint/osint-db` is a
|
||||||
|
plain Deployment and cannot use CNPG backup at all.
|
||||||
|
|
||||||
|
A new CloudNativePG cluster is **not** picked up automatically by either
|
||||||
|
mechanism. For dumps: add `<ns>/<cluster>` to `CNPG_TARGETS` in the CronJob env
|
||||||
|
*and* an equivalent exec-only Role/RoleBinding for the `forgejo/cluster-backup`
|
||||||
|
ServiceAccount in that namespace. For barman: add `spec.backup.barmanObjectStore`
|
||||||
|
with a `destinationPath` of `s3://pg-wal-archive` (the bucket root — the server
|
||||||
|
name, defaulting to the cluster name, becomes the prefix, so clusters share one
|
||||||
|
bucket without colliding), the same `sirius-growth/portal-wal-s3`-shaped Secret
|
||||||
|
in that namespace, and a `ScheduledBackup`.
|
||||||
|
|
||||||
### 8.2 Restoring
|
### 8.2 Restoring
|
||||||
|
|
||||||
|
|
@ -631,6 +711,92 @@ sudo systemctl start wg-quick@wg0 && sudo wg show
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### 8.3 Point-in-time recovery (`sirius-growth/portal`)
|
||||||
|
|
||||||
|
Rehearsed end to end on **2026-11-19** (task `t_ce7d6772`) against the live
|
||||||
|
archive: a marker row was written, 10 s later a second, unwanted row was written,
|
||||||
|
and a throwaway cluster was restored with `targetTime` between the two. The
|
||||||
|
marker came back, the later row did not.
|
||||||
|
|
||||||
|
**Step 1 — establish the target time.** Take it from the data, never from
|
||||||
|
memory:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl -n sirius-growth exec portal-1 -c postgres -- \
|
||||||
|
psql -U postgres -d portal -tAc "select max(updated_at) from leads" # or pg_last_xact_replay_timestamp-style reasoning
|
||||||
|
date -u +%FT%TZ
|
||||||
|
```
|
||||||
|
|
||||||
|
**Step 2 — restore into a throwaway cluster.** Never into `portal` itself while
|
||||||
|
it is serving: CNPG recovery bootstraps a *new* data dir from the archive.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
apiVersion: postgresql.cnpg.io/v1
|
||||||
|
kind: Cluster
|
||||||
|
metadata:
|
||||||
|
name: portal-pitr-test
|
||||||
|
namespace: sirius-growth
|
||||||
|
spec:
|
||||||
|
instances: 1
|
||||||
|
imageName: ghcr.io/cloudnative-pg/postgresql:16
|
||||||
|
storage: {size: 5Gi, storageClass: local-path}
|
||||||
|
affinity: {nodeSelector: {kubernetes.io/hostname: siriussec}}
|
||||||
|
bootstrap:
|
||||||
|
recovery:
|
||||||
|
source: portal-wal
|
||||||
|
recoveryTarget:
|
||||||
|
targetTime: "2026-11-19T22:35:15Z" # UTC, RFC3339
|
||||||
|
externalClusters:
|
||||||
|
- name: portal-wal
|
||||||
|
barmanObjectStore:
|
||||||
|
destinationPath: s3://pg-wal-archive
|
||||||
|
endpointURL: http://10.10.0.5:3900
|
||||||
|
serverName: portal # MUST be the *source* cluster name
|
||||||
|
s3Credentials:
|
||||||
|
accessKeyId: {name: portal-wal-s3, key: ACCESS_KEY_ID}
|
||||||
|
secretAccessKey: {name: portal-wal-s3, key: ACCESS_SECRET_KEY}
|
||||||
|
region: {name: portal-wal-s3, key: REGION}
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl apply -f portal-pitr-test.yaml
|
||||||
|
kubectl -n sirius-growth get cluster portal-pitr-test -w # Ready=True, "Cluster in healthy state"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Step 3 — verify the cut, and then promote the result.**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# the restore must stop before the unwanted transaction
|
||||||
|
kubectl -n sirius-growth exec portal-pitr-test-1 -c postgres -- \
|
||||||
|
psql -U postgres -d portal -c "select id, note, at from <the table> order by id"
|
||||||
|
kubectl -n sirius-growth exec portal-pitr-test-1 -c postgres -- \
|
||||||
|
psql -U postgres -tAc "select pg_is_in_recovery(), pg_last_xact_replay_timestamp()"
|
||||||
|
```
|
||||||
|
|
||||||
|
`pg_is_in_recovery() = f` on a single-instance recovery cluster means replay
|
||||||
|
finished and it has already been promoted. **A recovery cluster is writable the
|
||||||
|
moment it is Ready** — do not leave `portal-pitr-test` running, and do not point
|
||||||
|
application traffic at it.
|
||||||
|
|
||||||
|
**Step 4 — make it the real one.** Two supported shapes: cut the app over to the
|
||||||
|
restored cluster (preferred — reversible), or re-point the PVC:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# cut over: patch the API/portal Deployments' POSTGRES_HOST to portal-pitr-test-rw,
|
||||||
|
# then, once verified, keep it and delete the old cluster.
|
||||||
|
# in-place: let the recovery cluster finish, stop portal, and restore the portal-1
|
||||||
|
# PVC from the test cluster's data dir — only after the app is confirmed correct.
|
||||||
|
```
|
||||||
|
|
||||||
|
**What recovery does not do:** it does not replay anything after the target, so
|
||||||
|
a "restore to now" is only as good as the last archived WAL. If
|
||||||
|
`pg_stat_archiver.failed_count` is non-zero, fix archiving *before* relying on a
|
||||||
|
timestamp near the present.
|
||||||
|
|
||||||
|
**If the archive is lost or corrupt:** fall back to the nightly `pg_dump`
|
||||||
|
(§8.2 step 2) — 24 h RPO, logical, and readable without barman. That is exactly
|
||||||
|
why `sirius-growth/portal` stayed in `CNPG_TARGETS`.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 9. Known hazards and runbook pointers
|
## 9. Known hazards and runbook pointers
|
||||||
|
|
|
||||||
155
infrastructure/garage-linode/README.md
Normal file
155
infrastructure/garage-linode/README.md
Normal file
|
|
@ -0,0 +1,155 @@
|
||||||
|
# Garage on the Linode — the CloudNativePG WAL archive
|
||||||
|
|
||||||
|
A **second, independent** single-node Garage on the Linode VPS. It holds one
|
||||||
|
bucket, `pg-wal-archive`, and its only consumer is CloudNativePG's barman-cloud
|
||||||
|
integration for `sirius-growth/portal` (continuous WAL archiving + daily base
|
||||||
|
backups → point-in-time recovery).
|
||||||
|
|
||||||
|
It is **not** the Pi's Garage (`infrastructure/garage/`, node
|
||||||
|
`d053db4dfc97bf78`). Different host, different `node_key`, different metadata
|
||||||
|
dir, no RPC peering, nothing shared. That is the whole point:
|
||||||
|
|
||||||
|
> The CNPG primary runs on `siriussec` in the same building, on the same power
|
||||||
|
> domain and the same uplink as the Pi. A WAL archive on the Pi would be a second
|
||||||
|
> copy of the same failure. The archive has to be off-site; the Linode is the
|
||||||
|
> only off-site box in this estate.
|
||||||
|
|
||||||
|
## What runs
|
||||||
|
|
||||||
|
| | |
|
||||||
|
|---|---|
|
||||||
|
| Host | Linode VPS, Kubernetes node `linode`, WireGuard `10.10.0.5` (`dummy-k8s`), hub `10.20.0.1` on `wg0` |
|
||||||
|
| Runtime | **podman 5.4** + a quadlet unit. This host is a kubelet node: installing `dockerd` next to the kubelet's containerd would add a second container runtime for no benefit, so the Pi's compose file cannot be reused verbatim |
|
||||||
|
| Unit | `/etc/containers/systemd/garage.container` → generated `garage.service` (`Restart=always`) |
|
||||||
|
| Image | `dxflrs/garage:v1.1.0` (same pinned tag as the Pi) |
|
||||||
|
| Config | `/etc/garage/garage.toml` (installed from this directory) |
|
||||||
|
| RPC secret | `/etc/garage/garage.env` → `GARAGE_RPC_SECRET`, `0600 root:root`, **not in git** |
|
||||||
|
| State | `/var/lib/garage/meta` (metadata, `node_key`) and `/var/lib/garage/data` (objects) |
|
||||||
|
| Node | `994fd2f42ae72da6`, zone `dc1`, capacity **20 GB**, `replication_factor = 1` |
|
||||||
|
| Bucket | `pg-wal-archive` — private, `Website access: false` |
|
||||||
|
|
||||||
|
## Exposure — WireGuard only, twice
|
||||||
|
|
||||||
|
1. `garage.toml` binds `10.10.0.5:3900` (S3) and `10.10.0.5:3903` (admin/metrics)
|
||||||
|
explicitly. There is no `0.0.0.0` listener and `eth0` (the public IP) is never
|
||||||
|
bound, so `ss -ltn` is proof by itself.
|
||||||
|
2. `host/wal-archive-firewall.nft` is an nftables table in **PREROUTING priority
|
||||||
|
-140** that accepts 3900/3903 only from `lo`/`wg0` (plus source
|
||||||
|
`10.244.0.0/16` for pods on this node) and **drops** everything else, with
|
||||||
|
counters on every rule. podman with `Network=host` does not need DNAT, but
|
||||||
|
the table keeps a future port mapping from reopening the path — and ufw alone
|
||||||
|
would not cover a container publish, exactly as on the Pi.
|
||||||
|
|
||||||
|
Measured (2026-11-19), from the laptop **straight to the Linode's public IP with
|
||||||
|
no VPN in the path**: 3900 and 3903 both `filtered`, and
|
||||||
|
`nft list table inet wal_archive_guard` shows the drop counter incrementing.
|
||||||
|
Anonymous `GET http://10.10.0.5:3900/pg-wal-archive/` → **403 AccessDenied**.
|
||||||
|
|
||||||
|
## Install / re-install
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# on the Linode, from a checkout of sirius/homek8s
|
||||||
|
cd infrastructure/garage-linode
|
||||||
|
sudo ./install.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
`install.sh` is idempotent: it installs podman if missing, writes
|
||||||
|
`/etc/garage/{garage.toml,garage.env}` (generating the RPC secret once), installs
|
||||||
|
the quadlet unit and the nft guard **before** starting the container, then
|
||||||
|
assigns the layout capacity on first run (`layout assign -z dc1 -c 20G`) and
|
||||||
|
prints `garage status` + the listener set.
|
||||||
|
|
||||||
|
Verify (all four must hold):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
systemctl status garage.service --no-pager | head -3
|
||||||
|
ss -ltnH 'sport = :3900 or sport = :3903' # only 10.10.0.5, never 0.0.0.0
|
||||||
|
podman exec garage /garage -c /etc/garage.toml status # node 994fd2f42ae72da6, HEALTHY
|
||||||
|
nft list table inet wal_archive_guard # counters on accept and drop
|
||||||
|
```
|
||||||
|
|
||||||
|
## Bucket and key
|
||||||
|
|
||||||
|
```bash
|
||||||
|
G() { podman exec garage /garage -c /etc/garage.toml "$@"; }
|
||||||
|
G bucket create pg-wal-archive
|
||||||
|
G key create cnpg-portal-wal # prints the secret once — capture it
|
||||||
|
G bucket allow --read --write pg-wal-archive --key cnpg-portal-wal
|
||||||
|
G bucket info pg-wal-archive # Website access: false
|
||||||
|
```
|
||||||
|
|
||||||
|
Key ID `GK7f2b4bb1fc9abaec50fde37b` (`cnpg-portal-wal`), scope **read+write on
|
||||||
|
`pg-wal-archive` only** — no bucket-create, no other bucket, not an admin key.
|
||||||
|
The secret lives in the cluster as Secret `sirius-growth/portal-wal-s3`
|
||||||
|
(`ACCESS_KEY_ID`, `ACCESS_SECRET_KEY`, `REGION=garage`), created out of band and
|
||||||
|
**never committed**. Garage v1.1 has no `--yes` on `key create`; the secret is
|
||||||
|
printed exactly once, so redirect it to a `0600` root file and read it from there.
|
||||||
|
|
||||||
|
## Disk sizing and retention
|
||||||
|
|
||||||
|
Measured 2026-11-19:
|
||||||
|
|
||||||
|
| | |
|
||||||
|
|---|---|
|
||||||
|
| Linode `/` | 79 GB, 29 GB used, **46 GB free** |
|
||||||
|
| Garage capacity | **20 GB** (layout), i.e. the store stops accepting before the disk does |
|
||||||
|
| First base backup + 7 WAL segments | **4.9 MB** in 8 bucket objects (`/var/lib/garage/data` 9.3 MB including Garage's block-store overhead, `meta` 4.6 MB) |
|
||||||
|
| `archive_timeout` / `wal_segment_size` on the primary | 5 min / 16 MB → at most 288 segments/day |
|
||||||
|
| Observed compressed segment | 16–25 KB when the portal is quiet |
|
||||||
|
| Steady state (quiet) | ~6 MB WAL/day + 4.5 MB base backup/day ≈ **150 MB per 14-day window** |
|
||||||
|
| Worst case (every segment full, 3–5× gzip) | ~1.5 GB/day ≈ 21 GB per 14 days — would hit the cap |
|
||||||
|
|
||||||
|
Retention is `spec.backup.retentionPolicy: "14d"` on the Cluster, enforced by
|
||||||
|
barman-cloud when a backup completes. The 20 GB cap is deliberate: when it is
|
||||||
|
reached Garage returns `507 InsufficientStorage` and the `Backup` /
|
||||||
|
`ScheduledBackup` goes red — a visible failure instead of a full Linode disk.
|
||||||
|
The response to that is to lower the retention policy to `7d`, or to grow the
|
||||||
|
Linode disk; never to delete WALs by hand (that breaks the archive's
|
||||||
|
continuity and every PITR target that depends on the deleted segment).
|
||||||
|
|
||||||
|
## How the archive is laid out
|
||||||
|
|
||||||
|
`destinationPath: s3://pg-wal-archive` (bucket root) with the barman server name
|
||||||
|
defaulting to the cluster name, so:
|
||||||
|
|
||||||
|
```
|
||||||
|
pg-wal-archive/portal/base/20261119T223452/{backup.info,data.tar.gz}
|
||||||
|
pg-wal-archive/portal/wals/0000000100000000/00000001000000000000005A.gz
|
||||||
|
```
|
||||||
|
|
||||||
|
That is one prefix per cluster, which is what lets `forgejo/pg` share this bucket
|
||||||
|
later without colliding. Listing it (the postgres container has no credentials in
|
||||||
|
its own environment; the Secret does):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl -n sirius-growth run wal-list --rm -it --restart=Never \
|
||||||
|
--image=public.ecr.aws/aws-cli/aws-cli:2.15.30 \
|
||||||
|
--overrides='{"spec":{"containers":[{"name":"aws","image":"public.ecr.aws/aws-cli/aws-cli:2.15.30",
|
||||||
|
"envFrom":[{"secretRef":{"name":"portal-wal-s3"}}],
|
||||||
|
"command":["sh","-c","export AWS_ACCESS_KEY_ID=$ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY=$ACCESS_SECRET_KEY AWS_DEFAULT_REGION=$REGION; aws --endpoint-url http://10.10.0.5:3900 s3 ls --recursive --human-readable s3://pg-wal-archive/"]}]}}'
|
||||||
|
```
|
||||||
|
|
||||||
|
## Restore
|
||||||
|
|
||||||
|
Point-in-time recovery is a **cluster restore**, not a file copy. The full
|
||||||
|
rehearsed recipe (marker → restore to `targetTime` → verify) is §8.3 of
|
||||||
|
`docs/cluster-overview.md`; `pitr-restore.md` in this directory is the
|
||||||
|
self-contained version with the commands and the acceptance output.
|
||||||
|
|
||||||
|
Short form: a throwaway `Cluster` with `bootstrap.recovery.source` pointing at an
|
||||||
|
`externalClusters` entry (`serverName: portal`, the same bucket and Secret) and
|
||||||
|
`recoveryTarget.targetTime`, then promote/cut over. Recovery needs the **base
|
||||||
|
backup** plus every WAL segment up to the target — one missing segment is a
|
||||||
|
failed restore, which is why the archive is never pruned by hand.
|
||||||
|
|
||||||
|
## What this store is *not*
|
||||||
|
|
||||||
|
- **Not a cluster peer of the Pi's Garage.** No `[rpc]` peering, no shared
|
||||||
|
`rpc_secret`, no replicated data. Two independent single-node stores.
|
||||||
|
- **Not Flux-managed.** Flux watches `./clusters/homek8s`; nothing there
|
||||||
|
references this directory. A push changes nothing on the Linode until
|
||||||
|
`install.sh` runs.
|
||||||
|
- **Not a general-purpose bucket host.** One bucket, one key, one consumer. Put
|
||||||
|
application media on the Pi's store; this one exists to be off-site.
|
||||||
|
- **Not exposed to the LAN or the internet**, and no Cloudflare tunnel, DNS
|
||||||
|
record or public bucket will be added to it.
|
||||||
38
infrastructure/garage-linode/garage.container
Normal file
38
infrastructure/garage-linode/garage.container
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
# Quadlet unit — Garage WAL archive on the Linode hub (10.10.0.5).
|
||||||
|
#
|
||||||
|
# Installed to /etc/containers/systemd/garage.container by install.sh; the
|
||||||
|
# podman systemd generator turns it into `garage.service` on the next
|
||||||
|
# `systemctl daemon-reload`. There is no docker on this host (it is a kubelet
|
||||||
|
# node — installing dockerd here would add a second container runtime next to
|
||||||
|
# the kubelet's containerd for no reason), so the Pi's compose file cannot be
|
||||||
|
# reused verbatim. Quadlet is the podman-native equivalent: one declarative
|
||||||
|
# file, systemd owns the lifecycle, no daemon of its own.
|
||||||
|
#
|
||||||
|
# Network=host on purpose: the container binds 10.10.0.5:3900 from garage.toml
|
||||||
|
# directly, so the published addresses are visible in `ss -lnt` on the host and
|
||||||
|
# no podman port-forwarding rules are injected into the node's netfilter state.
|
||||||
|
|
||||||
|
[Unit]
|
||||||
|
Description=Garage S3 — CloudNativePG WAL archive (WireGuard-only)
|
||||||
|
Documentation=file:///etc/garage/README.md
|
||||||
|
After=network-online.target
|
||||||
|
Wants=network-online.target
|
||||||
|
|
||||||
|
[Container]
|
||||||
|
ContainerName=garage
|
||||||
|
Image=docker.io/dxflrs/garage:v1.1.0
|
||||||
|
Network=host
|
||||||
|
EnvironmentFile=/etc/garage/garage.env
|
||||||
|
Volume=/etc/garage/garage.toml:/etc/garage.toml:ro
|
||||||
|
Volume=/var/lib/garage/meta:/data/meta
|
||||||
|
Volume=/var/lib/garage/data:/data/data
|
||||||
|
Exec=/garage -c /etc/garage.toml server
|
||||||
|
LogDriver=journald
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Restart=always
|
||||||
|
TimeoutStartSec=120
|
||||||
|
TimeoutStopSec=60
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
47
infrastructure/garage-linode/garage.toml
Normal file
47
infrastructure/garage-linode/garage.toml
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
# Garage v1.1.0 — WAL archive for CloudNativePG, on the Linode hub.
|
||||||
|
#
|
||||||
|
# Installed to /etc/garage/garage.toml (root:root 0644) by install.sh.
|
||||||
|
#
|
||||||
|
# This is a SECOND, independent Garage node — not a cluster peer of the Pi's
|
||||||
|
# node `d053db4dfc97bf78`. It exists because a WAL archive must live off-site:
|
||||||
|
# the Pi and the CNPG primary (siriussec) share a building, power domain and
|
||||||
|
# internet uplink, so archiving WALs there is a second copy of the same
|
||||||
|
# failure. Different node_key, different metadata dir, `replication_factor = 1`,
|
||||||
|
# nothing shared with the Pi's store.
|
||||||
|
#
|
||||||
|
# Listeners are bound to explicit addresses here AND the ports are guarded by
|
||||||
|
# host/wal-archive-firewall.nft before Docker-style DNAT could ever matter.
|
||||||
|
# `10.10.0.5` is the Linode worker's WireGuard-mesh InternalIP (dummy-k8s) —
|
||||||
|
# the only address any cluster pod can reach this on. eth0 (50.116.38.217) is
|
||||||
|
# not bound at all, so an off-mesh scan sees a filtered port, not a listener.
|
||||||
|
#
|
||||||
|
# rpc_secret is NOT in this file: GARAGE_RPC_SECRET comes from
|
||||||
|
# /etc/garage/garage.env (0600, out of git), same as the Pi's node.
|
||||||
|
|
||||||
|
metadata_dir = "/data/meta"
|
||||||
|
data_dir = "/data/data"
|
||||||
|
db_engine = "sqlite"
|
||||||
|
replication_factor = 1
|
||||||
|
|
||||||
|
# Single node: nothing outside the container speaks RPC. Garage still needs the
|
||||||
|
# listener for its own CLI-over-loopback calls (`garage status`, `garage key`).
|
||||||
|
rpc_bind_addr = "127.0.0.1:3901"
|
||||||
|
rpc_public_addr = "127.0.0.1:3901"
|
||||||
|
|
||||||
|
[s3_api]
|
||||||
|
s3_region = "garage"
|
||||||
|
# WireGuard address only. An empty/i.e. 0.0.0.0 bind here would put barman's
|
||||||
|
# archive on the Linode's public interface.
|
||||||
|
api_bind_addr = "10.10.0.5:3900"
|
||||||
|
|
||||||
|
# Admin API + Prometheus metrics, mesh-only. No metrics_token: the port does not
|
||||||
|
# leave the WireGuard mesh. Add one here (and a bearer token in the scrape
|
||||||
|
# config) if 3903 is ever exposed beyond it. Not scraped today — the archive's
|
||||||
|
# growth is asserted from the filesystem in the backup README instead.
|
||||||
|
[admin]
|
||||||
|
api_bind_addr = "10.10.0.5:3903"
|
||||||
|
|
||||||
|
# node_key is generated on first start and lives in metadata_dir (/data/meta).
|
||||||
|
# It is part of /root/garage-backup for the Pi's node; this node's meta/ is
|
||||||
|
# covered by the cluster-backup mirror on the same host. Restore meta/ before
|
||||||
|
# data/ or the layout no longer names this node and every bucket is orphaned.
|
||||||
20
infrastructure/garage-linode/host/install-wal-archive-firewall.sh
Executable file
20
infrastructure/garage-linode/host/install-wal-archive-firewall.sh
Executable file
|
|
@ -0,0 +1,20 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# Install the WAL-archive inbound guard on the Linode hub. Idempotent.
|
||||||
|
#
|
||||||
|
# sudo ./install-wal-archive-firewall.sh
|
||||||
|
#
|
||||||
|
# Verifies the table afterwards instead of trusting `systemctl start`'s exit 0.
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||||
|
|
||||||
|
install -D -m 0644 "$here/wal-archive-firewall.nft" /etc/nftables.d/wal_archive_guard.nft
|
||||||
|
install -D -m 0644 "$here/wal-archive-firewall.service" /etc/systemd/system/wal-archive-firewall.service
|
||||||
|
|
||||||
|
systemctl daemon-reload
|
||||||
|
systemctl enable --now wal-archive-firewall.service
|
||||||
|
|
||||||
|
nft list table inet wal_archive_guard >/dev/null
|
||||||
|
nft list table inet wal_archive_guard | grep -q 'dport { 3900, 3903 }'
|
||||||
|
echo "OK: wal_archive_guard loaded"
|
||||||
|
nft list table inet wal_archive_guard
|
||||||
41
infrastructure/garage-linode/host/wal-archive-firewall.nft
Normal file
41
infrastructure/garage-linode/host/wal-archive-firewall.nft
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
#!/usr/sbin/nft -f
|
||||||
|
# WAL-archive inbound guard — defence in depth for Garage on the Linode hub.
|
||||||
|
#
|
||||||
|
# WHY THIS EXISTS AND WHY UFW ALONE IS NOT ENOUGH:
|
||||||
|
# On the Pi the risk is docker's DNAT bypassing ufw's INPUT chain. Here the
|
||||||
|
# store runs under podman with Network=host, so there is no DNAT to bypass —
|
||||||
|
# but the same rule shape is kept anyway, because the next person who adds a
|
||||||
|
# port mapping (or a second container that proxies this one) must not be able
|
||||||
|
# to reach 3900 from eth0 by accident. This table is evaluated in PREROUTING
|
||||||
|
# at priority -140, before any DNAT, so it binds the exposure to the transport
|
||||||
|
# rather than to how the listener was published.
|
||||||
|
#
|
||||||
|
# Effective policy for 3900 (S3 API) and 3903 (metrics/admin):
|
||||||
|
# accept from WireGuard (wg0) and loopback — incl. pod traffic arriving from
|
||||||
|
# the mesh with a 10.244.x source — drop everything else (eth0, LAN, public).
|
||||||
|
# DROP not REJECT: an off-mesh scan sees `filtered` and learns nothing.
|
||||||
|
#
|
||||||
|
# Note this is *in addition to* ufw, which on this host allows 22 from
|
||||||
|
# 10.20.0.0/24 and any from 10.10.0.0/24 / 10.244.0.0/16. ufw's own default is
|
||||||
|
# deny incoming, so the LAN path is already closed; this table keeps it closed
|
||||||
|
# even if someone later opens ufw wider for a different service.
|
||||||
|
#
|
||||||
|
# `destroy` (not `delete`) so re-running the unit replaces the table instead of
|
||||||
|
# appending a duplicate, and does not fail on first install.
|
||||||
|
|
||||||
|
destroy table inet wal_archive_guard
|
||||||
|
table inet wal_archive_guard {
|
||||||
|
chain prerouting {
|
||||||
|
type filter hook prerouting priority -140; policy accept;
|
||||||
|
|
||||||
|
# WireGuard mesh + hub link, and loopback (the garage CLI talks to
|
||||||
|
# 127.0.0.1:3901 inside this host namespace).
|
||||||
|
iifname { "lo", "wg0" } tcp dport { 3900, 3903 } counter accept
|
||||||
|
|
||||||
|
# Pods on this node reach the dummy-k8s address from the pod network.
|
||||||
|
ip saddr 10.244.0.0/16 tcp dport { 3900, 3903 } counter accept
|
||||||
|
|
||||||
|
# Everything else — eth0/public, any future interface nobody added above.
|
||||||
|
tcp dport { 3900, 3903 } counter drop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
# /etc/systemd/system/wal-archive-firewall.service (linode)
|
||||||
|
#
|
||||||
|
# Host unit, installed by hand (not Flux-managed) — the file lives in git at
|
||||||
|
# infrastructure/garage-linode/host/. Same shape as garage-firewall.service on
|
||||||
|
# the Pi and k8s-api-firewall.service on siriussec.
|
||||||
|
#
|
||||||
|
# No Requires= on wg-quick@wg0: the tunnel is enabled at boot on this host but a
|
||||||
|
# hard dependency would turn a transient tunnel failure into "store unguarded
|
||||||
|
# and unit failed". The table only filters; it can load before the interface
|
||||||
|
# exists.
|
||||||
|
[Unit]
|
||||||
|
Description=Drop off-WireGuard inbound to the Garage WAL archive (3900/3903)
|
||||||
|
After=network-online.target
|
||||||
|
Wants=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/usr/sbin/nft -f /etc/nftables.d/wal_archive_guard.nft
|
||||||
|
RemainAfterExit=yes
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
60
infrastructure/garage-linode/install.sh
Executable file
60
infrastructure/garage-linode/install.sh
Executable file
|
|
@ -0,0 +1,60 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# Install the Garage WAL archive on the Linode hub (10.10.0.5). Idempotent.
|
||||||
|
#
|
||||||
|
# sudo ./install.sh
|
||||||
|
#
|
||||||
|
# Installs: podman (if missing), /etc/garage/{garage.toml,garage.env},
|
||||||
|
# /etc/containers/systemd/garage.container, the nft guard, and the state dirs.
|
||||||
|
# Then starts the unit and assigns the node's layout capacity on first run.
|
||||||
|
#
|
||||||
|
# The RPC secret is generated once and never printed. Rewriting it on an
|
||||||
|
# existing install is harmless for a single-node store, but the copy in
|
||||||
|
# /root/garage-backup is what a rebuild should reuse.
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||||
|
|
||||||
|
command -v podman >/dev/null || {
|
||||||
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
apt-get update -qq
|
||||||
|
apt-get install -y podman
|
||||||
|
}
|
||||||
|
|
||||||
|
install -d -m 0755 /etc/garage /etc/containers/systemd /etc/nftables.d
|
||||||
|
install -d -m 0700 /var/lib/garage/meta /var/lib/garage/data
|
||||||
|
|
||||||
|
install -m 0644 "$here/garage.toml" /etc/garage/garage.toml
|
||||||
|
install -m 0644 "$here/garage.container" /etc/containers/systemd/garage.container
|
||||||
|
|
||||||
|
if [ ! -s /etc/garage/garage.env ]; then
|
||||||
|
umask 077
|
||||||
|
printf 'GARAGE_RPC_SECRET=%s\n' "$(openssl rand -hex 32)" > /etc/garage/garage.env
|
||||||
|
fi
|
||||||
|
chmod 0600 /etc/garage/garage.env
|
||||||
|
|
||||||
|
# Guard first: the listener must never exist unguarded, not even for the
|
||||||
|
# seconds between `compose/quadlet up` and a firewall install.
|
||||||
|
"$here/host/install-wal-archive-firewall.sh" >/dev/null
|
||||||
|
|
||||||
|
systemctl daemon-reload
|
||||||
|
systemctl start garage.service
|
||||||
|
|
||||||
|
# First run only: this Garage node needs a layout entry before it accepts
|
||||||
|
# writes. Capacity 20 GB against a 79 GB disk holding 29 GB of other data —
|
||||||
|
# see README "Disk sizing".
|
||||||
|
for _ in $(seq 1 30); do
|
||||||
|
garage_status=$(podman exec garage /garage -c /etc/garage.toml status 2>&1 || true)
|
||||||
|
grep -q 'NO ROLE' <<<"$garage_status" && break
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
|
||||||
|
if grep -q 'NO ROLE' <<<"$garage_status"; then
|
||||||
|
node_id=$(awk '/NO ROLE/{print $1}' <<<"$garage_status" | head -1)
|
||||||
|
podman exec garage /garage -c /etc/garage.toml layout assign -z dc1 -c 20G "$node_id"
|
||||||
|
podman exec garage /garage -c /etc/garage.toml layout apply --version 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Verify rather than assume.
|
||||||
|
podman exec garage /garage -c /etc/garage.toml status
|
||||||
|
ss -ltnH 'sport = :3900 or sport = :3903'
|
||||||
|
nft list table inet wal_archive_guard >/dev/null && echo "OK: wal_archive_guard loaded"
|
||||||
177
infrastructure/garage-linode/pitr-restore.md
Normal file
177
infrastructure/garage-linode/pitr-restore.md
Normal file
|
|
@ -0,0 +1,177 @@
|
||||||
|
# Restore notes — point-in-time recovery for `sirius-growth/portal`
|
||||||
|
|
||||||
|
Rehearsed end to end on **2026-11-19** (kanban task `t_ce7d6772`) against the live
|
||||||
|
archive. This file records the commands and the actual output of that rehearsal,
|
||||||
|
so the next person restores from a transcript instead of a hope.
|
||||||
|
|
||||||
|
The archive: Garage on the Linode, bucket `pg-wal-archive`, `http://10.10.0.5:3900`
|
||||||
|
over the WireGuard mesh, credentials in Secret `sirius-growth/portal-wal-s3`.
|
||||||
|
Producer: `spec.backup.barmanObjectStore` on `Cluster sirius-growth/portal`
|
||||||
|
(WAL archiving continuous, `ScheduledBackup portal-daily` at 03:20 UTC,
|
||||||
|
`retentionPolicy: 14d`).
|
||||||
|
|
||||||
|
## 0. Is the archive actually healthy?
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl -n sirius-growth exec portal-1 -c postgres -- \
|
||||||
|
psql -U postgres -tAc "select last_archived_wal, last_archived_time, failed_count from pg_stat_archiver"
|
||||||
|
# 00000001000000000000005B|2026-11-19 22:40:30.1+00|0
|
||||||
|
```
|
||||||
|
|
||||||
|
`failed_count` must be 0 and `last_archived_time` must be minutes old. A
|
||||||
|
`targetTime` after the last archived WAL cannot be reached — recovery stops at
|
||||||
|
the last segment it can fetch.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl -n sirius-growth get backup -o wide # newest barmanObjectStore Backup: completed
|
||||||
|
kubectl -n sirius-growth get scheduledbackup # portal-daily, LAST BACKUP set
|
||||||
|
```
|
||||||
|
|
||||||
|
## 1. Prove the marker, then make the mistake
|
||||||
|
|
||||||
|
The rehearsal wrote a marker, forced the WAL out, waited, then wrote a second
|
||||||
|
row that must *not* survive recovery:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
q() { kubectl -n sirius-growth exec portal-1 -c postgres -- psql -U postgres -d portal -tAc "$1"; }
|
||||||
|
q "insert into pitr_probe(note) values ('MARKER-before-target') returning id, at"
|
||||||
|
# 3|2026-11-19 22:35:06.127778+00
|
||||||
|
q "select pg_switch_wal()" ; sleep 12
|
||||||
|
q "select last_archived_wal, last_archived_time from pg_stat_archiver"
|
||||||
|
# 000000010000000000000059|2026-11-19 22:35:07.089783+00
|
||||||
|
sleep 10
|
||||||
|
q "insert into pitr_probe(note) values ('POISON-after-target') returning id, at"
|
||||||
|
# 4|2026-11-19 22:35:28.959782+00
|
||||||
|
q "select pg_switch_wal()" ; sleep 12
|
||||||
|
q "select last_archived_wal, last_archived_time from pg_stat_archiver"
|
||||||
|
# 00000001000000000000005A|2026-11-19 22:35:29.906592+00
|
||||||
|
```
|
||||||
|
|
||||||
|
The target is therefore **`2026-11-19T22:35:15Z`** — 9 s after the marker, 14 s
|
||||||
|
before the row that must be lost. Note that WAL `…05A` (which contains the poison
|
||||||
|
row) *is* in the archive: the restore has to choose to stop, it is not starved of
|
||||||
|
data.
|
||||||
|
|
||||||
|
## 2. Restore into a throwaway cluster
|
||||||
|
|
||||||
|
Never restore over the live `portal` cluster while it is serving.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
apiVersion: postgresql.cnpg.io/v1
|
||||||
|
kind: Cluster
|
||||||
|
metadata:
|
||||||
|
name: portal-pitr-test
|
||||||
|
namespace: sirius-growth
|
||||||
|
labels: {purpose: pitr-acceptance-test}
|
||||||
|
spec:
|
||||||
|
instances: 1
|
||||||
|
imageName: ghcr.io/cloudnative-pg/postgresql:16
|
||||||
|
storage: {size: 5Gi, storageClass: local-path}
|
||||||
|
affinity: {nodeSelector: {kubernetes.io/hostname: siriussec}}
|
||||||
|
resources:
|
||||||
|
requests: {cpu: 100m, memory: 256Mi}
|
||||||
|
limits: {memory: 1Gi}
|
||||||
|
bootstrap:
|
||||||
|
recovery:
|
||||||
|
source: portal-wal
|
||||||
|
recoveryTarget:
|
||||||
|
targetTime: "2026-11-19T22:35:15Z"
|
||||||
|
externalClusters:
|
||||||
|
- name: portal-wal
|
||||||
|
barmanObjectStore:
|
||||||
|
destinationPath: s3://pg-wal-archive
|
||||||
|
endpointURL: http://10.10.0.5:3900
|
||||||
|
serverName: portal # MUST match the source Cluster name
|
||||||
|
s3Credentials:
|
||||||
|
accessKeyId: {name: portal-wal-s3, key: ACCESS_KEY_ID}
|
||||||
|
secretAccessKey: {name: portal-wal-s3, key: ACCESS_SECRET_KEY}
|
||||||
|
region: {name: portal-wal-s3, key: REGION}
|
||||||
|
```
|
||||||
|
|
||||||
|
`serverName` is not optional: it is the barman prefix (`portal/base`,
|
||||||
|
`portal/wals`). Omit it and the restore cluster looks for its own name and finds
|
||||||
|
an empty history. `targetTime` is UTC RFC3339 — a wrong timezone silently
|
||||||
|
restores the wrong hour.
|
||||||
|
|
||||||
|
The operator restores the base backup, replays WAL, stops at the target and
|
||||||
|
promotes:
|
||||||
|
|
||||||
|
```
|
||||||
|
ready=False phase=Setting up primary
|
||||||
|
ready=False phase=Waiting for the instances to become active
|
||||||
|
ready=True phase=Cluster in healthy state
|
||||||
|
portal-pitr-test 1 1 Cluster in healthy state portal-pitr-test-1
|
||||||
|
```
|
||||||
|
|
||||||
|
## 3. The acceptance evidence
|
||||||
|
|
||||||
|
```
|
||||||
|
$ kubectl -n sirius-growth exec portal-pitr-test-1 -c postgres -- \
|
||||||
|
psql -U postgres -d portal -c "select id, note, at from pitr_probe order by id"
|
||||||
|
id | note | at
|
||||||
|
----+----------------------+-------------------------------
|
||||||
|
3 | MARKER-before-target | 2026-11-19 22:35:06.127778+00
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
$ ... -tAc "select count(*) from pitr_probe where note like 'POISON%'"
|
||||||
|
0
|
||||||
|
```
|
||||||
|
|
||||||
|
Marker present, post-target row gone. The rest of the database came back with it
|
||||||
|
(physical restore, all databases, no `pg_restore` ordering games), e.g.
|
||||||
|
`clients 4 = 4`, `calendar_tokens 3 = 3`, `applications 1 = 1` against the
|
||||||
|
primary at that moment.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ ... -tAc "select pg_is_in_recovery()"
|
||||||
|
f # replay finished, instance promoted
|
||||||
|
```
|
||||||
|
|
||||||
|
`pg_is_in_recovery() = f` is expected here and is **not** a failure: a CNPG
|
||||||
|
recovery cluster with `instances: 1` promotes itself once it hits the target. It
|
||||||
|
is writable from that moment — which is why the test cluster must be deleted, and
|
||||||
|
why nothing may point application traffic at it before you decide to.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl -n sirius-growth delete cluster portal-pitr-test
|
||||||
|
```
|
||||||
|
|
||||||
|
## 4. Making the restored data the real data
|
||||||
|
|
||||||
|
Two shapes, both legitimate:
|
||||||
|
|
||||||
|
1. **Cut over (preferred, reversible).** Point the app at
|
||||||
|
`portal-pitr-test-rw` (`POSTGRES_HOST` in the API/portal Deployments — through
|
||||||
|
git, not `kubectl set env`), verify, then drop the old cluster only after the
|
||||||
|
app has been confirmed on the restored copy.
|
||||||
|
2. **In place.** Keep `portal`, stop its instances, and swap the PVC content from
|
||||||
|
the recovered data directory. Slower, destructive, and easy to get wrong —
|
||||||
|
only with the app scaled to zero.
|
||||||
|
|
||||||
|
Either way, take a fresh base backup once the decision is made
|
||||||
|
(`kubectl apply` a `Backup` CR against the surviving cluster) so the archive has
|
||||||
|
a post-recovery base rather than one from before the incident.
|
||||||
|
|
||||||
|
## Gotchas that cost time
|
||||||
|
|
||||||
|
- **Flux owns `apps/base/sirius-growth/cluster.yaml`.** A hand `kubectl apply` of
|
||||||
|
a new `spec.backup` is reverted by the `apps` Kustomization within its 1 min
|
||||||
|
interval. Config changes belong in the branch/PR. (During the rehearsal the
|
||||||
|
`kustomize-controller` Deployment was scaled to 0 for the test window and
|
||||||
|
scaled back afterwards; `Backup`/`Cluster` objects created by hand are not in
|
||||||
|
the Kustomization inventory, so they are not pruned.)
|
||||||
|
- **`ScheduledBackup.spec.schedule` is six-field cron, seconds first.** `0 20 3
|
||||||
|
* * *` = 03:20:00 UTC. Copying a five-field crontab string silently means
|
||||||
|
"every minute" in the first field.
|
||||||
|
- **The bucket prefix is `portal/portal/…` only if you get `destinationPath`
|
||||||
|
wrong.** Use `s3://pg-wal-archive` for the bucket root; barman appends the
|
||||||
|
server name.
|
||||||
|
- **CNPG 1.30 warns that in-tree barman-cloud is removed in 1.31.** If that
|
||||||
|
upgrade happens, migrate to the Barman Cloud Plugin first; until then the
|
||||||
|
archives remain readable by `barman-cloud-restore` in the same container image.
|
||||||
|
- **If archiving has failed** (`pg_stat_archiver.failed_count > 0`), fix it and
|
||||||
|
let a fresh base backup complete before trusting any recent `targetTime`.
|
||||||
|
- **Fallback when the archive is unusable:** the nightly `pg_dump` in
|
||||||
|
`forgejo/cluster-backup` (`db/sirius-growth-portal-<stamp>.dump`, 14 retained,
|
||||||
|
§8.2 step 2 of `docs/cluster-overview.md`). 24 h RPO, logical, independent of
|
||||||
|
barman and of the Linode Garage node.
|
||||||
Loading…
Reference in a new issue