new: backups and disaster recovery (ADR-0014)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
debdeb6754
commit
c60c9bb317
3 files changed
+26
-2
No files matched your search
@@ -29,5 +29,5 @@ hAPI uses a **Linode Managed PostgreSQL 18** cluster (Shared 2 GB, 1 node) attac
|
||||
- **Data repairs** normally ship as reviewed Alembic data migrations run as `hapi_migrator`, targeting rows by id or condition without printing them.
|
||||
- **Break-glass goes through `hapi db breakglass --reason "…"`.** It opens `psql` as `hapi_migrator` from a pod and emits structured audit events to hAPI's centralized logs: start, end, reason, and every statement. Query results are never logged. The platform offers no statement logging or pgaudit, so this is the only audit trail.
|
||||
- **Connection budget:** the plan allows 50 connections. That leaves about 46 usable after 3 reserved superuser slots and one platform backend. Each app pod holds at most 10 (`pool_size=5`, `max_overflow=5`), and the admin CLI holds 1–2. The rule is: (maximum concurrent app pods, including rollout surge) × 10, plus about 6 for migrate, CLI, break-glass and bootstrap, must be ≤ 46. That caps app pods at 4. Any future worker process counts against the same budget. **Amended by ADR-0012:** housekeeping CronJobs use a pool of 1, so the rule is app pods (with surge) × 10 + concurrently runnable CronJobs × 1 + ~6 ≤ 46.
|
||||
- **Plan changes are restores.** An in-place resize stalled during verification. Changing size or node count is done as a restore-to-new-cluster, with the same runbook as disaster recovery: fork, wait for DNS, `hapi db bootstrap`, repoint the app. Single-node maintenance windows (pinned to a quiet slot) cause short downtime, covered by 14-day point-in-time recovery.
|
||||
- **Plan changes are restores.** An in-place resize stalled during verification. Changing size or node count is done as a restore-to-new-cluster, with the same runbook as disaster recovery: fork, wait for DNS, `hapi db bootstrap`, repoint the app. Single-node maintenance windows (pinned to a quiet slot) cause short downtime, covered by 14-day point-in-time recovery. **Amended by ADR-0014:** our own daily dumps (an Object Lock bucket, pulled off-account) cover damage found after 14 days and account loss, and `hapi db bootstrap` also creates a read-only `BYPASSRLS` `hapi_backup` role for `hapi db backup`.
|
||||
- Passwords are rotated manually with a runbook. `password_encryption` is set explicitly to `scram-sha-256`.
|
||||
@@ -18,7 +18,7 @@ ADR-0002 allows no anonymous public endpoints, but kubelet probes can't carry a
|
||||
- **`/v1/health`** checks `db` (a `SELECT 1` through the app pool) and `schema` (at the expected Alembic head). These are critical: if either fails, the status is `down` with HTTP 503. It also checks `ha_bridge` (no poll for 5 min, see ADR-0006) and `job_backlog` (oldest pending Job too old). These are non-critical: if one fails, the status is `degraded` with HTTP 200. Bodies carry no error text, hostnames, versions or latencies. Kuma points two monitors at it: *up* (HTTP status) and *healthy* (a JSON query asserting `status == "ok"`).
|
||||
- **Collection:** vmagent scrapes the app, kubelet/cAdvisor, kube-state-metrics, node-exporter, Flux and Cilium. A Vector DaemonSet takes pod stdout and Talos service logs (`machine.logging`, JSON over TCP). An event exporter ships Kubernetes Events as logs. Everything lives in a `monitoring` namespace on Block Storage PVs and arrives as Flux `HelmRelease`s.
|
||||
- **App metrics** come from `prometheus-client`: requests by route template, method and status; latency; DB pool usage; Job depth, age and failures; seconds since HA's last poll; auth failures by reason. **Labels never carry `principal_id` or Personal data.** Per-Principal detail stays in logs.
|
||||
- **Retention:** logs and metrics are kept for 30 days, breakglass audit events for 1 year.
|
||||
- **Retention:** logs and metrics are kept for 30 days, breakglass audit events for 1 year. **Amended by ADR-0014:** the daily backup job also exports breakglass audit events to the backup bucket, and the off-account copy keeps them for 1 year, so they survive a cluster rebuild.
|
||||
- **Locked down:** Grafana requires login, with analytics, update checks and Gravatar off. Datasource plugins are pinned in the image. Outbound traffic from `monitoring` is denied by default, except vmalert → ntfy and the Watchdog → Kuma push.
|
||||
- **Every failure has one alerting owner.**
|
||||
- Kuma: reachability and degraded status.
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
# Backups go to an Object Lock bucket the cluster can't read back, pulled off-account to the Owner's machine
|
||||
|
||||
Linode's 14-day point-in-time recovery covers a bad migration, a bad delete or a lost database (ADR-0004). It doesn't cover damage found after 14 days, or losing the Linode account. So hAPI also takes its own daily dump. A **`hapi db backup` CronJob** streams `pg_dump -Fc | age | upload` into **`hapi-backups`**, a Linode Object Storage bucket with **Object Lock in compliance mode**. Dumps are encrypted to a **dedicated backup age recipient**, and its private key is never in the cluster. A **puller outside Linode**, holding only a `read_only` key, copies new objects out and never deletes or overwrites them. A compromised cluster can therefore neither read nor erase backups, and losing the account doesn't lose them. Recovery targets: (a) inside Linode, minutes of data lost and back within about 2 h; (b) damage found late, up to one day lost; (c) account loss, everything since the puller's last copy lost, with a weekend of downtime acceptable. Nothing is highly available.
|
||||
|
||||
## Considered Options
|
||||
|
||||
- **Backblaze B2 (or R2 or S3) as the off-platform target.** Rejected in favour of Linode plus a pull: no new vendor, and Object Lock plus an off-account copy give the same protection. Linode keys are only `read_only` or `read_write` (there's no write-only key), so compliance-mode lock is what stops the cluster's key from deleting.
|
||||
- **Pushing to a home NAS.** Impossible: no connection may start from home into the cluster (ADR-0002, CGNAT). The pull direction works.
|
||||
- **Encrypting with the SOPS age key.** Rejected: Flux holds it in the cluster, so a compromised cluster could decrypt every old dump.
|
||||
- **Dumping as `hapi_migrator`** (it owns the tables, so it bypasses RLS). Rejected by ADR-0012: no migrator credentials in recurring pods.
|
||||
- **A separate backup image** (postgres + age + rclone). Rejected: ADR-0012's one-image, one-delivery-path rule. `postgresql-client-18` is added to the hAPI image instead, and `pg_restore` comes with it.
|
||||
- **etcd / Talos snapshots.** Not taken: everything in etcd is in git or can be recreated (certificates get reissued, the Tailscale operator re-authenticates from SOPS, the CCM recreates the NodeBalancer on the reserved IP). Losing the cluster means rebuilding it from code (ADR-0003).
|
||||
- **Keeping breakglass audit events only in VictoriaLogs**, or also writing them to Postgres. Rejected: the monitoring PVs don't survive a rebuild, and `hapi_migrator` could edit rows in Postgres.
|
||||
|
||||
## Consequences
|
||||
|
||||
- **`hapi_backup` role** (amends ADR-0004): LOGIN, `BYPASSRLS`, SELECT only, created by `hapi db bootstrap`. Its reads stay complete through `ALTER DEFAULT PRIVILEGES` set as `hapi_migrator`. Its password is its own SOPS secret, mounted only into the backup pod. Whoever holds it, or the backup private key, can read all Personal data. Like `akmadmin` and the Tofu state, that is controlled by policy and audit, not by cryptography (ADR-0001). The dump uses one connection, counted in ADR-0012's CronJob term. To verify during the build: that `akmadmin` can create a `BYPASSRLS` role on Aiven.
|
||||
- **Backup key:** an age keypair generated offline. The cluster has only the public recipient, in plain config. The private key is in Vaultwarden and the offline copy (ADR-0008), next to the other Owner roots.
|
||||
- **Bucket:** created by Tofu with Object Lock (compliance mode, which turns on versioning). Each object is locked for 35 days, and a lifecycle rule expires it after 35 days. The cluster's key is `read_write` and limited to this bucket (through SOPS). To verify during the build: that it can't delete a locked version.
|
||||
- **Schedule and content:** daily at 03:00 Household time (`spec.timeZone`, ADR-0012). The job copies the plaintext stream into `pg_restore --list` before encrypting it, so an archive whose table of contents doesn't parse fails the run. The same job exports the previous day's breakglass audit events from VictoriaLogs to `audit/`, encrypted to the same recipient (amends ADR-0009: the 1-year retention now survives a rebuild). The backup pod's egress is limited to the DB, Object Storage, VictoriaLogs and Kuma.
|
||||
- **Puller:** a script in `infra/backup-pull/` (with a `just` recipe) running `rclone copy --immutable` plus pruning. It keeps 90 dailies, the dump from each 1st of the month for 3 years, and `audit/` for 1 year. It also pulls the versioned Tofu state bucket (which holds the Talos machine secrets, ADR-0003) with a second `read_only` key. It isn't a Principal: it never talks to hAPI. **For now it runs on the Owner's PC** as a systemd user timer (daily, `Persistent=true`). There, tier (c)'s data loss is "since the last pull", which is safe as long as the PC pulls at least once in 35 days. **It moves unchanged to a NAS** when one exists.
|
||||
- **Monitoring:** two Kuma push monitors. The backup CronJob's alerts after 26 h of silence. The puller's (it pushes only after copying an object less than 26 h old) alerts after **8 days while it runs on the PC. Change that to 26 h when it moves to the NAS.** ADR-0012's generic vmalert rule also covers the CronJob.
|
||||
- **Restore runbook:** the database is VPC-only, so restores run as **`hapi db restore`** in a pod. The Owner pastes in the backup private key at run time (like the `akmadmin` password), and it's never stored. Path **(A)**: a Linode point-in-time fork, then bootstrap, then repoint the app (ADR-0004's runbook, shared with plan resizes). Path **(B)**: a new database, then bootstrap, then `hapi db restore` from our dump as `hapi_migrator`, then repoint the app. If the account is lost, the Owner first uploads the dump from the puller's copy into the new account's bucket. A cluster rebuild needs the SOPS age key, the Tofu state passphrase (Vaultwarden or the offline copy) and Gitea. Backing up Gitea is out of scope. Its fallbacks are the Owner's local clone and rebuilding images in CI.
|
||||
- **Rehearsal:** before go-live, as acceptance for the build epic, run one full drill: rebuild the cluster from code in an empty Linode project, then path (B) from a pulled copy. After that, every 6 months, run path (B) into a throwaway database, check the Alembic revision and row counts per table, then delete it. This also rehearses plan resizes. It's tracked as a Household Maintenance Task, "Rehearse disaster recovery" (fixed RRULE), so the `tasks` check reminds through ntfy.
|
||||
Reference in new issue
Block a user