From 3aca8a85a354237fc2b1d974a737e6510fc2139d Mon Sep 17 00:00:00 2001 From: Sergei Poljanski Date: Tue, 17 Nov 2026 07:51:59 +0400 Subject: [PATCH 1/6] nixos: break-glass root login on ops for its conversion ops is the WireGuard hub. If WireGuard does not come back after the switch, root may still log in from the admin's exit address (services' IPv4, where the admin's traffic leaves through Xray). Root only, ops only; the dead-man reboot covers the rest. Remove after Phase 2. Assisted-by: Claude:opus-5-5 --- nixos/hosts/asxpio-ops/default.nix | 5 +++++ nixos/modules/base.nix | 26 +++++++++++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/nixos/hosts/asxpio-ops/default.nix b/nixos/hosts/asxpio-ops/default.nix index 217a176..db58434 100644 --- a/nixos/hosts/asxpio-ops/default.nix +++ b/nixos/hosts/asxpio-ops/default.nix @@ -18,6 +18,11 @@ networking.hostName = lib.mkDefault "asxpio-ops"; networking.domain = "asxp.io"; asxpio.privateIPv4 = "10.10.0.10"; + + # Break-glass for the conversion (MIGRATION.md, Phase 2): root from the + # admin's exit address (services' IPv4, through Xray), in case WireGuard + # does not come back. REMOVE after Phase 2. + asxpio.rootSshFromExtra = lib.mkDefault [ "46.62.228.216/32" ]; system.stateVersion = "26.05"; systemd.network.networks."10-public".address = [ "2a01:4f9:c013:3258::1/64" ]; diff --git a/nixos/modules/base.nix b/nixos/modules/base.nix index e4813c0..01c54aa 100644 --- a/nixos/modules/base.nix +++ b/nixos/modules/base.nix @@ -32,6 +32,12 @@ in description = "Networks shell users may log in from."; }; + options.asxpio.rootSshFromExtra = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = [ ]; + description = "Extra addresses root alone may log in from (break-glass)."; + }; + # Units that own data start only once /var/lib/.data-in-place exists, # so a fresh install never creates empty state where a restore is about # to land. Create the file after the data is in place. @@ -98,15 +104,17 @@ in ]; # Shell users only from the trusted networks; the Hetzner # firewall is the outer layer - AllowUsers = lib.concatMap ( - net: - map (u: "${u}@${net}") [ - "root" - "asxpi" - "deploy" - "zerrtika" - ] - ) config.asxpio.sshFrom; + AllowUsers = + lib.concatMap ( + net: + map (u: "${u}@${net}") [ + "root" + "asxpi" + "deploy" + "zerrtika" + ] + ) config.asxpio.sshFrom + ++ map (net: "root@${net}") config.asxpio.rootSshFromExtra; }; }; services.fail2ban.enable = true; From 5742e0633202d4f57fff8ad80a9e5e593346a9ba Mon Sep 17 00:00:00 2001 From: Sergei Poljanski Date: Tue, 17 Nov 2026 07:56:10 +0400 Subject: [PATCH 2/6] nixos: ops-data.sh starts no apps on a rehearsal host A restored /opt//.env holds production credentials: vhpbot would log in as the production bot, asxpio-monitor would probe the internet, the apps could send mail. On a rehearsal host the script now stops before starting them; they are started by hand, sanitized. Assisted-by: Claude:opus-5-5 --- nixos/migration/ops-data.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/nixos/migration/ops-data.sh b/nixos/migration/ops-data.sh index 557f1cf..c5e809a 100755 --- a/nixos/migration/ops-data.sh +++ b/nixos/migration/ops-data.sh @@ -90,6 +90,14 @@ forgejo-admin regenerate hooks forgejo-admin regenerate keys echo "== App stacks: images again (Docker's image store does not carry over)" +case "$(hostname)" in + rehearsal-*) + # Restored .env files hold production credentials: vhpbot would log + # in as the production bot, asxpio-monitor probe the internet, the + # apps send mail. Start them by hand, sanitized (MIGRATION.md rules). + echo " rehearsal host: apps NOT started" + exit 0 ;; +esac for app in asxpio datacenterbingo blog czsk vhpbot-prod vhpbot-dev; do [ -f "/opt/$app/docker-compose.yml" ] || continue echo " $app" From f49dd721727d86784de6a17655c5a255450794e0 Mon Sep 17 00:00:00 2001 From: Sergei Poljanski Date: Tue, 17 Nov 2026 08:10:13 +0400 Subject: [PATCH 3/6] nixos: podman without sudo for the admins; re-key the rehearsal ops `podman` run as an admin showed that user's own, empty rootless store, so `podman ps` needed sudo while `docker ps` did not. Point CONTAINER_HOST at the system Podman's socket, which group podman (the admins) may use. The rehearsal ops server was rebuilt and has a new host key. Assisted-by: Claude:opus-5-5 --- nixos/.sops.yaml | 2 +- nixos/modules/podman.nix | 4 ++++ nixos/secrets/rehearsal-ops.yaml | 22 +++++++++++----------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/nixos/.sops.yaml b/nixos/.sops.yaml index 066253a..79f5755 100644 --- a/nixos/.sops.yaml +++ b/nixos/.sops.yaml @@ -6,7 +6,7 @@ keys: - &asxpio_services age15ws8alg3ftsgmzvqxft09556g87s4n8c8v39nmvhaz6k50gp4e7se8acmg # Throwaway servers: replace with the new host's key, then # sops updatekeys secrets/rehearsal-*.yaml - - &rehearsal_ops age1hfaf7h2h43ahhql8zc6u3yr67yx4utnrlw57h6r32wnm4axvzves8pcl0r + - &rehearsal_ops age138t70j9mf3su6krnt2ygxdy4xwm2wpyrgjjhk7rlzpr3tkdhcuyqdywfjl - &rehearsal_services age1au6f8m6l245ddrunqf2a62xprnlevn9yrducynlay2tgknfxeeusj94j5l creation_rules: - path_regex: secrets/asxpio-ops\.yaml$ diff --git a/nixos/modules/podman.nix b/nixos/modules/podman.nix index 90dfa93..c929698 100644 --- a/nixos/modules/podman.nix +++ b/nixos/modules/podman.nix @@ -22,6 +22,10 @@ virtualisation.oci-containers.backend = "podman"; environment.systemPackages = [ pkgs.docker-client ]; + # `podman` talks to the same system Podman too, for every admin without + # sudo (they are in group podman, which owns the socket); otherwise it + # would show each user's own, empty rootless store + environment.variables.CONTAINER_HOST = "unix:///run/podman/podman.sock"; # Podman's DNS for container networks, on each bridge's gateway. The # NixOS module opens it on podman0 only; CI jobs and compose stacks get # networks of their own (podman1, podman2, ...). diff --git a/nixos/secrets/rehearsal-ops.yaml b/nixos/secrets/rehearsal-ops.yaml index 34a2278..b6bd5d0 100644 --- a/nixos/secrets/rehearsal-ops.yaml +++ b/nixos/secrets/rehearsal-ops.yaml @@ -43,22 +43,22 @@ sops: age: - enc: | -----BEGIN AGE ENCRYPTED FILE----- - YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBpZEZIUzZVWU5TNUlWVXdX - aGIyRVhCb25BdGxlK3AvcTBjMWRqeWFXWFhRClVjZHgwZ1dLVnEySi9FdlV5Myts - anA1aysyYjh3S0Q2ZksyK0luYktqVFUKLS0tIDA3WEVLMFVkajhzQVJwNi9kSGc1 - VjZsaWRuUGJnN2JZdncyY01hb04xNE0Ko0GKw0FHJETlil7W8xbmqoJnnimpQHw3 - E7C4HeRPaDvG+OcYpMH/ukIRHsQkiDc5KL80COM7AS/ZDK0IeNNPhA== + YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBreDl5dVA3K3R6LzEzVkVX + VkVaY3dacjU2OFFWLzdFdmxOVGR1OVpNdWw4CnFNN2tVNDdkM2ZWQTE5TGFKbGlL + VUxEZ01sNk5RL3AzWG4wdnk5dVNtSW8KLS0tIGhkT2ZIYTZ1b0ZtTUpKTTd1aW9m + NjVhUkI5QnZOSWxWL3VjWmJGbDFGRzgKdRmEd3BbVeSMbzuj+alpEe+812FVresO + EtyvWrmeui2FMUP5wAJRKaCo2uoDlCsNMGlMYUABSE8VGvp8EtHyOg== -----END AGE ENCRYPTED FILE----- recipient: age19xvmm6j3h2u6mc3w6k65ufry4p5aa5lwu96p55h3e42p9wfzwc0qp2w7pk - enc: | -----BEGIN AGE ENCRYPTED FILE----- - YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBXRHFyWmRPdEI0VktmdWQx - ZkFMUDh2RFgvWkhpKy9iWEhqdVpzSVBZU3lJCmExYktHemxNUGFUMUZtQ3NNc3E1 - QUE4UEZDU3J5VTdyRnA2MFFDUnY1a2cKLS0tIEYyTnpWdC9tQ3Fmb013REc3Y0Ez - UjkrQnZaUFpUQlB2ZEhYUUxQckdKM28KXsP1eTtI/512vxqfhB3zitJFzFrA78kY - Bez9GS+nbC/VEfTrAjd+uCKcj5hzYRvjF6HIvX97qMCPVFIwmhlXIg== + YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBrVUc2eUppeTVaTmRTVFJy + L0xMVVRSanIraWJKTC9tazdDN3JMTUNDTUZnCnFLRXRMZ2RYRkJ4MUdWUGZrTGN2 + MDlrbEVQR2dld25Kayt6T3RoQlU5Z0UKLS0tIHVlOTZEVGUyY2ZnMmhGbE9LQWNP + aU8xUm5tdW9WNUxFaGI1K2tUbjJFREkK0aHOJ+uQUSx/XbhSo3QdWWdXFxH8QW2x + rk/NS8GmCAjgxzv7dochfGLLH5pimVe7gniKW9FgonLMdRR1MR4WWw== -----END AGE ENCRYPTED FILE----- - recipient: age1hfaf7h2h43ahhql8zc6u3yr67yx4utnrlw57h6r32wnm4axvzves8pcl0r + recipient: age138t70j9mf3su6krnt2ygxdy4xwm2wpyrgjjhk7rlzpr3tkdhcuyqdywfjl lastmodified: "2026-11-17T00:40:51Z" mac: ENC[AES256_GCM,data:GfJBC73iJcXVroSEXbRhYPE0CrHANiPccWe5fCGx9ZzgeaBStCLDfSk2mkLmWsn/M87UzSTxus95Y09JojGmSwhgnoMfrVc26T/WuiyfJj4r4J7K83E/HR6XsIckc1xBcc6I9dbbvHRIhPj23hjz9jTbt5oa0/f5Rhj5I5u6NYE=,iv:gWwtV2tMWdmssSQ9iH54FTntNb4jDuzZNOrlge9qi5k=,tag:VIDg7swKFuB5KAGNyjaiWA==,type:str] unencrypted_suffix: _unencrypted From 2ca56d595c8b7a2eec2a728eb8d2bf2087df8e9f Mon Sep 17 00:00:00 2001 From: Sergei Poljanski Date: Tue, 17 Nov 2026 08:27:35 +0400 Subject: [PATCH 4/6] nixos: containers come back after a reboot; ops-data.sh fixes Found by rehearsing the ops conversion on a fresh test server with last night's backup: - After a reboot the app containers stayed stopped. Docker restarted them; Podman does so only through podman-restart.service, which it ships but does not enable. Enable it; on ops it waits for the app networks, Postgres and Garage. - ops-data.sh: a fresh NixOS has no /opt, so moving the app directories failed; and NixOS creates an empty /var/lib/forgejo/repositories at boot, so the repositories were moved into it, one level too deep. Every part now creates its target, replaces what is empty and skips what already moved, so an interrupted run can be resumed. - `forgejo admin regenerate hooks` is gone in Forgejo 17, which gives git its own hooks on every push; a push to a restored repository works with the old hook files in place. Drop the call. - The rehearsal ops host does not push XMPP certificates: there is no services host behind 10.10.0.20 on the test network. Assisted-by: Claude:opus-5-5 --- nixos/hosts/asxpio-ops/apps.nix | 15 +++++++++++++++ nixos/hosts/rehearsal/ops.nix | 3 +++ nixos/migration/ops-data.sh | 30 +++++++++++++++++++++--------- nixos/modules/podman.nix | 10 ++++++++++ 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/nixos/hosts/asxpio-ops/apps.nix b/nixos/hosts/asxpio-ops/apps.nix index 4449755..1cdce34 100644 --- a/nixos/hosts/asxpio-ops/apps.nix +++ b/nixos/hosts/asxpio-ops/apps.nix @@ -21,6 +21,21 @@ in # at start only systemd.services.podman.restartTriggers = [ hosts ]; + # After a reboot the apps come back once their networks, database and + # object store are there + systemd.services.podman-restart = { + after = [ + "podman-network-traefik.service" + "podman-network-storage.service" + "postgresql.service" + "garage.service" + ]; + wants = [ + "podman-network-traefik.service" + "podman-network-storage.service" + ]; + }; + # `docker compose up --build` (vhpbot-prod builds on the host) starts # BuildKit in a privileged container asxpio.security.containers."buildx_buildkit_.*" = [ "privileged" ]; diff --git a/nixos/hosts/rehearsal/ops.nix b/nixos/hosts/rehearsal/ops.nix index bfc1be4..2a3a284 100644 --- a/nixos/hosts/rehearsal/ops.nix +++ b/nixos/hosts/rehearsal/ops.nix @@ -32,6 +32,9 @@ asxpio.alertEmail = "nobody@example.invalid"; services.grafana.settings.smtp.enabled = lib.mkForce false; systemd.timers.crawler-alert.enable = false; + # No services host behind 10.10.0.20 on the test network + systemd.paths.xmpp-cert-sync.enable = false; + systemd.timers.xmpp-cert-sync.enable = false; systemd.timers.crawler-weekly.enable = false; services.loki.configuration = { # No Object Storage keys here: everything on local disk diff --git a/nixos/migration/ops-data.sh b/nixos/migration/ops-data.sh index c5e809a..6824e96 100755 --- a/nixos/migration/ops-data.sh +++ b/nixos/migration/ops-data.sh @@ -15,30 +15,40 @@ set -euo pipefail src=${1:?usage: ops-data.sh } stage=$src/var/backups/restic-stage [ ! -e /var/lib/.data-in-place ] || { echo "services already have data (/var/lib/.data-in-place exists)" >&2; exit 1; } -for f in "$stage/pg_dumpall.sql" "$stage/forgejo-gitea.db" "$src/opt/forgejo/data/git/repositories"; do +for f in "$stage/pg_dumpall.sql" "$stage/forgejo-gitea.db"; do [ -e "$f" ] || { echo "missing: $f" >&2; exit 1; } done +# Each part moves what is still under and skips what already +# moved, so an interrupted run can simply be started again. echo "== Forgejo" fj=/var/lib/forgejo install -d -o git -g git -m 750 $fj $fj/data $fj/custom -mv "$src/opt/forgejo/data/git/repositories" $fj/repositories -mv "$src/opt/forgejo/data/git/lfs" $fj/data/lfs +if [ -d "$src/opt/forgejo/data/git/repositories" ]; then + rm -rf $fj/repositories + mv "$src/opt/forgejo/data/git/repositories" $fj/repositories +fi +[ ! -d "$src/opt/forgejo/data/git/lfs" ] || { rm -rf $fj/data/lfs; mv "$src/opt/forgejo/data/git/lfs" $fj/data/lfs; } +[ -d $fj/repositories ] || { echo "missing: Forgejo repositories" >&2; exit 1; } for d in "$src"/opt/forgejo/data/gitea/data/*; do + [ -e "$d" ] || continue case "$(basename "$d")" in home | ssh | tmp | sessions | queues | indexers) ;; # rebuilt, or the container's own - *) mv "$d" $fj/data/ ;; + *) rm -rf "$fj/data/$(basename "$d")"; mv "$d" $fj/data/ ;; esac done -[ ! -d "$src/opt/forgejo/data/gitea/public" ] || mv "$src/opt/forgejo/data/gitea/public" $fj/custom/public +[ ! -d "$src/opt/forgejo/data/gitea/public" ] || { rm -rf $fj/custom/public; mv "$src/opt/forgejo/data/gitea/public" $fj/custom/public; } # The online copy taken by the backup hook, not the live file cp "$stage/forgejo-gitea.db" $fj/data/forgejo.db chown -R git:git $fj echo "== Garage" install -d -m 700 /var/lib/garage -mv "$src/var/lib/docker/volumes/storage_garage_meta/_data" /var/lib/garage/meta -mv "$src/var/lib/docker/volumes/storage_garage_data/_data" /var/lib/garage/data +for part in meta data; do + v="$src/var/lib/docker/volumes/storage_garage_$part/_data" + [ ! -d "$v" ] || { rm -rf /var/lib/garage/$part; mv "$v" /var/lib/garage/$part; } + [ -d /var/lib/garage/$part ] || { echo "missing: Garage $part" >&2; exit 1; } +done echo "== Traefik" install -d -o traefik -g traefik -m 700 /var/lib/traefik @@ -65,6 +75,7 @@ if [ -f "$vols/monitoring_grafana-data/_data/grafana.db" ]; then fi echo "== App stacks (compose file and .env each; CI deploys them later)" +install -d -m 755 /opt for app in asxpio datacenterbingo blog czsk vhpbot-prod vhpbot-dev; do [ -d "$src/opt/$app" ] || continue rm -rf "/opt/$app"; mv "$src/opt/$app" "/opt/$app" @@ -85,8 +96,9 @@ systemctl restart postgres-roles.service systemctl start garage.service garage-bootstrap.service forgejo.service traefik.service -echo "== Forgejo: hooks and SSH keys for the new paths" -forgejo-admin regenerate hooks +echo "== Forgejo: SSH keys file for the new paths" +# The repositories' own hook files still name the container's binary; +# Forgejo 17 gives git its own hooks on every push, so they are unused. forgejo-admin regenerate keys echo "== App stacks: images again (Docker's image store does not carry over)" diff --git a/nixos/modules/podman.nix b/nixos/modules/podman.nix index c929698..e06e763 100644 --- a/nixos/modules/podman.nix +++ b/nixos/modules/podman.nix @@ -21,6 +21,16 @@ }; virtualisation.oci-containers.backend = "podman"; + # Containers started outside systemd (compose stacks, `docker run`) come + # back after a reboot only through this unit, which Podman ships but + # does not enable: the Docker daemon used to do it. It starts every + # container whose restart policy says so (always, unless-stopped). + systemd.services.podman-restart = { + wantedBy = [ "multi-user.target" ]; + after = [ "network-online.target" ]; + wants = [ "network-online.target" ]; + }; + environment.systemPackages = [ pkgs.docker-client ]; # `podman` talks to the same system Podman too, for every admin without # sudo (they are in group podman, which owns the socket); otherwise it From c1a4080f398370f576d0925074c5942bafb89972 Mon Sep 17 00:00:00 2001 From: Sergei Poljanski Date: Tue, 17 Nov 2026 08:30:33 +0400 Subject: [PATCH 5/6] docs: the ops rehearsal, its timings and the bugs it found Assisted-by: Claude:opus-5-5 --- MIGRATION.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index ba74e9e..9e48536 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -264,10 +264,15 @@ log shipping to Loki and the runner's link to Forgejo pause. 2. **Storage repo:** disable its deploy workflow (Phase 0 step 4). 3. **Secrets:** compare every ops secret in sops with the vault, `/opt/storage/.env` and the live values, as was done for services. -4. **Final rehearsal on `claude-test-nixos-a`** with that night's ops - backup: `migration/ops-data.sh /restore`, the apps pulled and healthy - through the Docker CLI, monitoring history moved. Proves the data - script end to end on fresh data. +4. **Final rehearsal on `claude-test-nixos-a`** — **done 2026-11-17** with + that night's ops backup (7.8 GiB): fresh Debian → cloud-init conversion + (4 min) → build and switch on the host (7 min on this cx23, the same + size as ops) → restore → `ops-data.sh` (10 s) → apps pulled and started + (31 s) and healthy with the compose healthchecks → reboot, everything + back by itself (1.5 min). It found four bugs, all fixed: the apps did + not come back after a reboot (podman-restart was not enabled), no + `/opt` on a fresh system, the repositories moved one level too deep, + and a Forgejo command that no longer exists. 5. **Break-glass in the flake:** root SSH from 46.62.228.216 for ops only (`asxpio.sshFrom` override in `hosts/asxpio-ops`), merged before the window, removed after it. @@ -277,7 +282,7 @@ log shipping to Loki and the runner's link to Forgejo pause. 7. **Snapshot** of ops in the Hetzner console (the prod token is read-only), `pre-nixos-`. -### The window (about 25–35 minutes of downtime) +### The window (about 20–25 minutes of downtime, by the rehearsal) From a workstation on WireGuard, in the repo. Every step is a separate go-ahead. From acf5260414443617f38f8034fed72e0ac0291663 Mon Sep 17 00:00:00 2001 From: Sergei Poljanski Date: Tue, 17 Nov 2026 08:31:51 +0400 Subject: [PATCH 6/6] nixos: never restart podman-restart on a deploy Its stop step is `podman stop --all`. A deploy that changes the unit, such as a Podman update, would restart it and so stop XMPP, running CI jobs and every app, only to start them again. It does its work at boot; leave it alone on a switch. Assisted-by: Claude:opus-5-5 --- nixos/modules/podman.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nixos/modules/podman.nix b/nixos/modules/podman.nix index e06e763..db7313d 100644 --- a/nixos/modules/podman.nix +++ b/nixos/modules/podman.nix @@ -29,6 +29,10 @@ wantedBy = [ "multi-user.target" ]; after = [ "network-online.target" ]; wants = [ "network-online.target" ]; + # Its stop step stops every container: a deploy that changes the unit + # (a Podman update) must not take XMPP, CI jobs and the apps down. + # It only matters at boot. + restartIfChanged = false; }; environment.systemPackages = [ pkgs.docker-client ];