new: cluster hardening baseline (ADR-0015)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
BobbyandClaude Opus 5.5 committed 2026-11-27 16:05:30 -05:00
1 parent c60c9bb317
commit 16aa73251b
4 files changed
+33 -5

No files matched your search

+2 -2
View File
@@ -114,10 +114,10 @@ _Avoid_: Rule, auto-categorization
### Maintenance
Maintenance is the upkeep of the Household's physical property: the home, its land, its equipment, and its vehicles.
Maintenance is the recurring upkeep of the Household's property: the home, its land, its equipment, its vehicles, and its digital systems (such as the hAPI cluster). It is not a to-do list: errands, bills, and one-off chores don't belong.
**Asset**:
A physical thing the Household keeps up, such as the roof, the furnace, a fridge, or a car. It may have a meter whose Readings track its use.
A thing the Household keeps up, such as the roof, the furnace, a car, or the hAPI cluster. It may have a meter whose Readings track its use.
_Avoid_: Equipment, item, entity (a Home Assistant term); in Finance, use another word
**Task**:
+2 -2
View File
@@ -16,9 +16,9 @@ ADR-0002 allows no anonymous public endpoints, but kubelet probes can't carry a
- **`/livez`** returns a constant. **`/readyz`** passes once startup is done (config loaded, pools created). On SIGTERM, `/readyz` fails first and the pod drains for about 5 s before it shuts down. Readiness also gates rollouts (ADR-0007): an image that never becomes Ready stalls the rollout.
- **`/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.
- **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. **Amended by ADR-0015:** the Vector and node-exporter DaemonSets run in a separate `privileged` namespace, `monitoring-node`, while `monitoring` enforces Pod Security `restricted`. Vector also ships the Kubernetes audit log.
- **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. **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.
- **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. **Amended by ADR-0015:** Kubernetes audit logs are also kept 1 year and included in the same export.
- **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.
@@ -21,4 +21,4 @@ Linode's 14-day point-in-time recovery covers a bad migration, a bad delete or a
- **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.
- **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. **Amended by ADR-0015:** the Task concerns the "hAPI cluster" Asset, now that Maintenance covers the Household's digital systems.
@@ -0,0 +1,28 @@
# Cluster hardening baseline: deny-by-default network, restricted pods, audit logs; signing deferred
v1 hardens the cluster with built-in mechanisms only. That means **default-deny CiliumNetworkPolicies** in every namespace we own, **Pod Security `restricted`** wherever it fits, two **ValidatingAdmissionPolicies** (in-apiserver CEL rules), **Kubernetes audit logging**, and a written **upgrade runbook** with a fixed cadence. **Commit signature verification and cosign image signing are deferred.** We chose this because each measure here closes a real gap without adding a controller to run. Signing would only move trust onto keys held by the same Gitea and runner it's meant to protect against.
## Considered Options
- **Flux commit verification plus cosign signing with admission-time verification, in v1.** Rejected for now. CI commits the digest bump to `main` (ADR-0007), so HEAD is usually a CI commit, and CI would need its own signing key. There's no keyless identity for Gitea, so the cosign key would be key-based too. Both keys would live in Gitea Actions secrets or on the runner, where an attacker who controls Gitea can run a workflow that uses them. Signed tags from a hardware key would break "every green merge deploys". Flux image automation would need git write credentials in the cluster.
- **Kyverno (or sigstore policy-controller) for admission.** Rejected for two rules. It adds a controller, a webhook that can fail open or closed, and more upgrades to keep up with. Revisit when signing returns.
- **Moving `monitoring` to `privileged` as a whole.** Rejected in favour of isolating the node agents in their own namespace.
- **Keeping ops reminders out of hAPI** (a personal calendar), since hAPI can't remind you to fix hAPI while it's down. Rejected: these are recurring upkeep, which is what Maintenance Tasks are for, and Kuma covers the outage case. The glossary's Maintenance now includes the Household's digital systems.
## Consequences
- **NetworkPolicy:** every namespace we own (`hapi`, `bots`, `gateway`, `envoy-gateway-system`, `monitoring`, `monitoring-node`, `cert-manager`, `flux-system`) is default-deny for ingress and egress. Each component's allows sit next to its manifests in `deploy/`. Rules that name hosts are `CiliumNetworkPolicy`, using `toFQDNs` for ntfy, Linode Object Storage, the Linode API, SimpleFIN, Kuma and Let's Encrypt, and `toCIDR` for the Managed DB's VPC address. This includes the allows already promised by ADR-0009, ADR-0011, ADR-0013 and ADR-0014. `kube-system` (Cilium, CCM and CoreDNS, installed by Tofu) stays open.
- **Pod Security:** the cluster default stays at Talos's `baseline`. Every namespace we own enforces `restricted`, except **`monitoring-node`**, which is `privileged` and holds only the Vector and node-exporter DaemonSets. This amends ADR-0009.
- **Admission (ValidatingAdmissionPolicy, Deny from day one, delivered by Flux):**
1. Images must come from Gitea's registry, or carry an `@sha256:` digest. Applies everywhere except `kube-system`.
2. Pods in `hapi` and `bots` must set `readOnlyRootFilesystem: true` and `automountServiceAccountToken: false`.
- **Audit logging:** the apiserver audit policy is set in Talos machine config at `Metadata` level. It keeps every write and every access to `secrets`, `pods/exec`, `pods/portforward` and `serviceaccounts/token`, and drops controllers' and Flux's reads, health endpoints and Events. Vector in `monitoring-node` ships the control-plane node's audit file to VictoriaLogs, where it's **kept 1 year** and included in ADR-0014's daily `audit/` export. A `pods/exec` or a Secret read by a human sends an alert to the ntfy `ops` topic. Dial the policy back if it's too noisy.
- **Upgrades:** Talos, Kubernetes, Cilium and CCM versions are pinned in `infra/`. Renovate opens PRs for them and never auto-merges. Security patches go in within 14 days; minor versions after their `.1`, staying within upstream support. The procedure goes in `docs/runbooks/cluster-upgrade.md`, written during the build:
1. Take a throwaway local `talosctl etcd snapshot`, never stored (ADR-0014's no-etcd-backups rule still holds).
2. Upgrade and drain the workers one at a time.
3. Upgrade the control plane, accepting a few minutes without the API.
4. Run `talosctl health` and check that Flux reconciles.
The reminder is a monthly Household Maintenance Task, "Upgrade the cluster", on a **"hAPI cluster" Asset**. ADR-0014's "Rehearse disaster recovery" Task hangs off the same Asset.
- **Supply chain in v1:** images stay digest-pinned (ADR-0007), admission rule 1 limits where images come from, CI's Trivy scan stays, and `main` has branch protection in Gitea. Revisit signing once CI has an identity a compromised Gitea can't use.
- **Deferred to v2:** runtime detection (Tetragon/Falco), in-cluster vulnerability scanning (Trivy Operator), CIS scanning, the Cilium host firewall (the Linode Cloud Firewall already covers nodes), least-privilege kubeconfigs (the Owner keeps Talos's admin kubeconfig, used only over the tailnet), and any CI check of policy coverage. etcd secret encryption needs no decision: Talos enables it by default.