iac/README.md

99 lines
4.7 KiB
Markdown

# asxp.io infrastructure
Two Hetzner Cloud servers running NixOS, described by OpenTofu.
- `tofu/`: servers, network, firewalls, DNS, Object Storage buckets
(OpenTofu, applied by hand; `tofu/README.md`)
- `nixos/`: the whole system of each server (one flake; `nixos/README.md`)
- `RESTORE.md`: restoring data from the backups
Branches: `main` is what runs. `ansible` is the Debian/Ansible setup as
it was before the move to NixOS (2026-11-16), `migration` the move
itself: its plan and record, the data scripts and the rehearsal rules.
## Servers
| Server | Size | Runs |
|--------|------|------|
| asxpio-ops | CX23: 2 vCPU, 4 GB | WireGuard hub, Traefik, Forgejo (+ registry), Postgres, Garage, monitoring; app stacks deployed from their own repos |
| asxpio-services | CX43: 8 vCPU, 16 GB | Forgejo Actions runners, Minecraft (Paper), SillyTavern, XMPP (asxp.io), Xray |
Administration only over WireGuard (10.20.0.0/24) or the private network
(10.10.0.0/20). Both servers are billed below today's list price: never
delete or recreate them, reinstall in place (`nixos/README.md`).
## Changing something
Edit `nixos/`, push a branch (CI evaluates every host), merge to `main`:
`.forgejo/workflows/nixos.yaml` builds each host on itself and switches
to it, ops first. Only units whose definition changed restart. Undo
with `nixos-rebuild switch --rollback` on the host.
Versions are pinned (`flake.lock`, image tags); Renovate opens a PR per
bump and updates `flake.lock` weekly.
Things to know:
- The runner executes the deploy. A change to it restarts it mid-job:
the change lands, the job shows as cancelled, the next run confirms.
- App stacks (asxpio, datacenterbingo, blog, czsk, vhpbot) are Podman
containers that their own repositories deploy with `docker compose`
as user `deploy`. `docker` and `podman` talk to the system Podman for
every admin.
- Your workstation's uplink may run through Xray on services: never stop
it without another path.
## Monitoring
Grafana at https://gf.asxp.io (WireGuard only). Dashboards and the 33
alert rules are provisioned from `nixos/hosts/asxpio-ops/monitoring/`;
change them there, not in the UI. Alerts mail `asxpio.alertEmail`.
- **Metrics:** Prometheus on ops scrapes both hosts, 90 days.
- **Logs:** Alloy ships the journal, container logs and Traefik's access
log to Loki (bucket `asxpio-loki-main`), 2 years.
- **Probes:** blackbox checks every site and TCP/TLS service from ops.
- **Security baseline:** every host reports its WireGuard peers, devices
on the private network, accounts, listening ports and privileged
containers; anything not declared in the config alerts. Each service
declares what it expects (`asxpio.security`). SSH logins show the same
summary.
## Backups
Nightly restic on each host (ops 03:30, services 04:15 UTC) into
`restic/<host>` in `asxpio-backups-main` (hel1) and `asxpio-backups-repl`
(fsn1); a failed run mails. A daily replica (services, ~06:00) copies
`asxpio-backups-main` (minus `restic/`), `asxpio-tofu-main`,
`asxpio-loki-main` and `k8s-asxpio-main` to their fsn1 twins. Details
and restores: `RESTORE.md`.
## Secrets
Service secrets are in `nixos/secrets/<host>.yaml`, encrypted with sops
for the admin's age key and each host's SSH host key; the hosts decrypt
them at boot. CI holds only `SSH_DEPLOY_KEY`. Keep a copy of the admin
age key (`~/.config/sops/age/keys.txt`) outside this machine.
## TODO
- [ ] **From 2026-11-24**, if nothing came up: `rm -rf /old-root` on both
hosts (Debian and its leftovers: Postgres 17/18 rollback volumes on
ops), then delete the snapshots `pre-nixos-2026-11-17` and
`asxpio-ops-pre-nixos-2026-11-17` in the Hetzner console.
- [ ] Remove the repository secret `ANSIBLE_VAULT_PASSWORD` (Forgejo →
iac → Settings → Actions → Secrets).
- [ ] Empty and remove the old state buckets `asxpio-terraform-main/-repl`
(`legacy_state_*` in `tofu/s3.tofu`) once the new state has been in
use for a few weeks.
- [ ] Reset Forgejo's instance-wide runner registration token (Site
administration → Actions → Runners → Create new runner → Reset
registration token). Nothing uses it any more (the runners connect
by UUID and token), but the old one, from 2024, still registers
runners. The other secrets from the old history are rotated.
- [ ] Optional: a new token for the interop runner (by an admin of
dev.another.im), into sops `runner/interop_token`.
- [ ] Move Postgres and Garage from ops to services (bigger disk and
memory; the apps reach them over the private network).
- [ ] Move the app stacks to their own flakes on asxpio-services, one at
a time (blog → czsk → datacenterbingo → asxpio → vhpbot).