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. 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/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/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/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 557f1cf..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,11 +96,20 @@ 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)" +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" 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; diff --git a/nixos/modules/podman.nix b/nixos/modules/podman.nix index 90dfa93..db7313d 100644 --- a/nixos/modules/podman.nix +++ b/nixos/modules/podman.nix @@ -21,7 +21,25 @@ }; 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" ]; + # 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 ]; + # `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