main: the current setup only
Some checks failed
nixos / nixos (push) Has been cancelled

Both servers run NixOS. The Ansible code and the move itself leave main
for their own branches: `ansible` is the Debian/Ansible setup as it was
before the migration, `migration` keeps the plan and record, the data
scripts and everything else the move needed.

README and RESTORE describe the setup as it is now: NixOS, Podman,
sops, OpenTofu, the backup paths and hooks of the new layout. The
README carries the TODO list that MIGRATION.md had. The Forgejo
sanitising script stays, under hosts/rehearsal, with the rules for
rehearsing on restored production data in the NixOS README. Renovate
no longer looks at Ansible files.

Assisted-by: Claude:opus-5-5
This commit is contained in:
Sergei Poljanski 2026-11-17 10:08:40 +04:00
commit 6d9122eeff
Signed by: asxpi
GPG key ID: 4F8851660FA4121B

199
README.md
View file

@ -1,162 +1,93 @@
# asxp.io infrastructure
Two Hetzner Cloud servers, described by OpenTofu. They are moving from
Debian configured by Ansible to NixOS (`MIGRATION.md`); until a host has
moved, pushing to `main` still applies `ansible/site.yaml` to it.
Two Hetzner Cloud servers running NixOS, described by OpenTofu.
- Build the servers from nothing: `nixos/README.md`
- Restore data from backups: `RESTORE.md`
- `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 | 2 vCPU, 4 GB | Traefik, Forgejo, monitoring, crawler stats; app stacks deployed from their own repos |
| asxpio-services | 8 vCPU, 16 GB | Forgejo Actions runners, Minecraft (Paper), SillyTavern, XMPP (asxp.io), Xray |
| 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 |
Both are reachable for administration only over WireGuard
(10.20.0.0/24) or the private network (10.10.0.0/20).
## Layout
- `tofu/`: servers, network, firewalls, DNS, object storage buckets (OpenTofu).
Applied by hand; see `tofu/README.md`.
- `ansible/site.yaml`: everything the pipeline manages (see below).
- `ansible/playbooks/`: host bootstrap, run by hand.
- `.forgejo/workflows/deploy.yaml`: the pipeline.
## What the pipeline manages
| Role | Host | What |
|------|------|------|
| `base` | both | unattended upgrades, fail2ban, journal size cap, Docker daemon config, weekly image prune |
| `monitoring_agent` | both | node_exporter, cAdvisor and Alloy on the VPC address |
| `traefik` | ops | reverse proxy, TLS, dashboard on WireGuard |
| `xmpp_cert_sync` | ops | pushes Traefik's XMPP certificates to ejabberd (see below) |
| `crawler_alert` | ops | crawler reports (daily, weekly) and metrics every 5 min |
| `monitoring` | ops | Prometheus, Loki, Grafana, blackbox and Postgres exporters, alerts |
| `forgejo` | ops | Forgejo at git.asxp.io (git.czsk.it is an alias), SSH passthrough |
| `forgejo_runner` | services | Actions runner and its job labels |
| `forgejo_runner_interop` | services | runner for another-im/interop on dev.another.im |
| `sillytavern` | services | SillyTavern on the WireGuard address |
| `minecraft` | services | Paper server |
| `xmpp` | services | ejabberd, apushd and tackygram for asxp.io; secrets stay in `/opt/xmpp/state` |
| `acme_forward` | services | port 80: ACME challenges to Traefik on ops, 404 otherwise |
| `xray` | services | Xray VLESS Reality on :443, config in the vault |
| `monitoring_agent` | both | node_exporter, cAdvisor, Alloy (logs to Loki); `security-metrics` timer |
| `monitoring` | ops | Prometheus, Loki, Grafana at gf.asxp.io (WireGuard only), dashboards and alert rules |
| `restic_backup` | both | nightly restic backup to object storage, hel1 and fsn1 |
| `s3_replicate` | services | daily copy of the hel1 buckets into their fsn1 twins |
Not managed here: the app stacks on asxpio-ops (asxpio, datacenterbingo,
blog, czsk, vhpbot, storage). Each deploys from its own repository into
`/opt/<app>`.
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
1. Edit the role or variable, for example an image tag in
`ansible/inventory/group_vars/` or a compose file under
`ansible/roles/<role>/files/`. Versions are pinned exactly; Renovate
opens a PR per bump.
2. Push a branch. The pipeline does a dry run against production.
3. Merge to `main`. The pipeline dry-runs again, then applies.
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.
A run with nothing to change touches nothing and restarts nothing.
Versions are pinned (`flake.lock`, image tags); Renovate opens a PR per
bump and updates `flake.lock` weekly.
Things to know:
- **Game servers** are saved and stopped with a 120 s timeout before a
compose change recreates them.
- **The runner** executes the pipeline. A change to it recreates the
container mid-job: the change lands, that job is reported as failed,
and the next run confirms it.
- **Forgejo** restarts on a config change; the job log may pause for a
few seconds.
- **New systemd units** don't exist yet during the dry run, so tasks that
enable them use `ignore_errors: "{{ ansible_check_mode }}"`.
To run it yourself, over WireGuard:
```sh
cd ansible
ansible-playbook site.yaml --check --diff # dry run
ansible-playbook site.yaml --tags traefik # one service
```
- 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 is at https://gf.asxp.io, reachable over WireGuard and the VPC
only. Dashboards are provisioned from
`ansible/roles/monitoring/files/dashboards/` and can't be saved from the
UI: change the JSON and deploy. The overview is the home dashboard.
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 scrapes both hosts over the VPC and keeps 90
days. Scripts add metrics through node_exporter's textfile directory
(`monitoring_textfile_dir`).
- **Logs:** Alloy ships the journal and container logs to Loki, kept 2
years. From 2026-11-14 chunks go to bucket `asxpio-loki-main` (hel1);
older ones stay on disk until they expire.
- **Probes:** blackbox_exporter checks the sites and the TCP/TLS services
from outside (`monitoring_probes`).
- **Alerts** mail `monitoring_alert_email`. Rules are in
`templates/alert-rules.yaml.j2`.
Settings: `ansible/inventory/group_vars/all/monitoring.yaml`.
## XMPP certificates
Traefik issues them; ejabberd on services only loads files.
1. The router `xmpp-cert` in Traefik's dynamic config requests
xmpp.asxp.io + conference.asxp.io. The HTTP challenge reaches services
(where those names point), and `acme_forward` passes it to ops.
asxp.io itself is the site's certificate: Traefik never requests a
name it already holds.
2. `xmpp-cert-sync.path` on ops fires when `acme.json` changes (and a
timer daily). It pushes both certificates over SSH with a key that
only runs `xmpp-cert-install`, from ops' VPC address.
3. `xmpp-cert-install` checks name, expiry and key, writes
`/opt/xmpp/state/certs/<name>.pem` and reloads ejabberd, which picks
a file per domain.
Alerts: sync not successful for 2 days; served certificate older than
Traefik's for 6 hours; expiry under 14 days. Names: `xmpp_cert.yaml`.
- **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
Hetzner's server backups are off. Each host runs `restic-backup.timer`
nightly (ops 03:30, services 04:15 UTC) into two independent
repositories, `restic/<host>` in `asxpio-backups-main` (hel1) and
`asxpio-backups-repl` (fsn1). Databases go in as dumps or online
copies; see `restic_pre_hooks` in `ansible/inventory/host_vars/`.
A failed run mails its journal.
```sh
restic-backup hel1 snapshots
restic-backup fsn1 restore latest --target /tmp/restore --include /opt/xmpp
```
The password is `vault_restic_password` in the vault. Keep a copy
outside the servers and this repo's CI: without it nothing can be read.
`s3_replicate` copies `asxpio-backups-main` (minus `restic/`),
`asxpio-tofu-main`, `asxpio-loki-main` and `k8s-asxpio-main` to their fsn1 twins daily
around 06:10 UTC. A run that would delete over 1000 objects stops and
mails instead.
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
Nothing secret is stored in the clear. Service secrets live in
`ansible/inventory/group_vars/all/vault.yaml`, encrypted with Ansible
Vault. The pipeline needs two repository 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.
- `ANSIBLE_VAULT_PASSWORD`: decrypts the vault.
- `SSH_DEPLOY_KEY`: private key of user `deploy` on both servers.
## TODO
Locally, put the vault password in `ansible/.vault_pass` (ignored by git).
## Bootstrap (by hand)
`ansible/playbooks/` holds what is done once per host or can lock you
out: WireGuard, SSH hardening, s3fs mounts, swap, user creation.
See `ansible/README.md`.
- [ ] **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.
- [ ] Rotate the secrets that sat in the old repository history:
Forgejo's `INTERNAL_TOKEN` and JWT secrets, the runner token; give
Grafana its own `secret_key`.
- [ ] Move the app stacks to their own flakes on asxpio-services, one at
a time (blog → czsk → datacenterbingo → asxpio → vhpbot).