From 8ef626a16b8591080ec0ac37e4d7ec50e8c86607 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Mon, 21 Sep 2026 16:19:43 -0400 Subject: [PATCH] dns games for buzz --- hosts/ABOUTME.md | 8 +- hosts/hl-minipc1.nix | 38 +++++-- hosts/scripts/hl-minipc1/buzz-manage.sh | 140 ++++++++++++++++++++++++ secrets/buzz-env.age | Bin 1169 -> 1202 bytes 4 files changed, 174 insertions(+), 12 deletions(-) create mode 100644 hosts/scripts/hl-minipc1/buzz-manage.sh diff --git a/hosts/ABOUTME.md b/hosts/ABOUTME.md index 5506037..1688862 100644 --- a/hosts/ABOUTME.md +++ b/hosts/ABOUTME.md @@ -14,8 +14,10 @@ hosts/ ├── fwbook/ # fwbook-specific shell scripts │ ├── functions.sh # ZSH functions sourced at shell startup │ └── functions.nu # NuShell helpers (k8s namespace/secret listing, secret decoding) - └── fw1/ - └── gs.sh # gamescope/Steam launch wrapper (VRR, HDR, mangoapp overlay) + ├── fw1/ + │ └── gs.sh # gamescope/Steam launch wrapper (VRR, HDR, mangoapp overlay) + └── hl-minipc1/ + └── buzz-manage.sh # Buzz stack management CLI (wired as `buzz-manage`) ``` ## Managed Hosts @@ -27,7 +29,7 @@ hosts/ | `hl-fws1.nix` | hl-fws1 | Framework 11th Intel — K3s server node | | `hl-bigbox1.nix` | hl-bigbox1 | AI/compute server (NVIDIA + AMD) | | `hl-bigbox2.nix` | hl-bigbox2 | NFS storage server | -| `hl-minipc1.nix` | hl-minipc1 | Core infra: Gitea, nix-serve, registry, Buzz (podman) | +| `hl-minipc1.nix` | hl-minipc1 | Core infra: Gitea, nix-serve, registry, Buzz (docker, `buzz-manage` CLI) | | `hl-minipc2.nix` | hl-minipc2 | Container/media server | | `hl-minipc3.nix` | hl-minipc3 | K3s worker node | | `hl-pi1.nix` | hl-pi1 | Raspberry Pi CM4 (aarch64) — headless server, SSH only. Also buildable as a bootable SD image via the `hl-pi1-sd-image` nixosConfiguration (`skyg build-pi-sd-image`) | diff --git a/hosts/hl-minipc1.nix b/hosts/hl-minipc1.nix index c82ca72..be5b22f 100644 --- a/hosts/hl-minipc1.nix +++ b/hosts/hl-minipc1.nix @@ -1,4 +1,4 @@ -{ config, ... }: +{ config, pkgs, ... }: let ports = { nixServe = 5000; @@ -35,9 +35,8 @@ let buzz = { domain = "buzz.app.internal"; port = 3000; + # Caddy's macvlan IP — buzz.app.internal resolves here; the relay is internal-only. ip = "10.0.101.3"; - # Caddy TLS terminator — buzz.app.internal points here (443/80). - caddyIp = "10.0.101.5"; bucket = "buzz-media"; images = { relay = "ghcr.io/block/buzz:main"; @@ -59,6 +58,13 @@ let device = ":/mnt/SmallG/buzz/${subpath}"; }; }; + # Buzz management CLI — upstream deploy/compose/run.sh ported to this + # deployment; the logic lives in scripts/hl-minipc1/buzz-manage.sh. + buzz-manage = pkgs.writeShellScriptBin "buzz-manage" '' + export BUZZ_ENV_FILE="${config.age.secrets.buzz-env.path}" + export BUZZ_COMPOSE_BIN="${pkgs.docker-compose}/bin/docker-compose" + ${builtins.readFile ./scripts/hl-minipc1/buzz-manage.sh} + ''; in { skyg.user.enable = true; @@ -286,10 +292,7 @@ in minio.condition = "service_healthy"; minio-init.condition = "service_completed_successfully"; }; - networks = { - internal = { }; - lan = { ipv4_address = buzz.ip; }; - }; + networks = [ "internal" ]; environmentFiles = [ config.age.secrets.buzz-env.path ]; environment = { BUZZ_BIND_ADDR = "0.0.0.0:${toString buzz.port}"; @@ -323,12 +326,14 @@ in # TLS terminator — owns buzz.app.internal (443/80), proxies to the relay # over the internal network. Cert minted by `skyg ca issue` (lab CA). + # Also proxies plain :3000 (Hermes guest can't trust the CA yet), :8080 + # health and :9102 metrics so everything stays on 10.0.101.3. caddy = { image = buzz.images.caddy; extraConfig.depends_on.relay.condition = "service_healthy"; networks = { internal = { }; - lan = { ipv4_address = buzz.caddyIp; }; + lan = { ipv4_address = buzz.ip; }; }; dns.names = [ buzz.domain ]; files."/etc/caddy/Caddyfile" = '' @@ -337,9 +342,21 @@ in encode zstd gzip reverse_proxy relay:${toString buzz.port} } + + :${toString buzz.port} { + reverse_proxy relay:${toString buzz.port} + } + + :8080 { + reverse_proxy relay:8080 + } + + :9102 { + reverse_proxy relay:9102 + } ''; volumes = [ - "${../../configs/pki/buzz.app.internal.crt}:/etc/caddy/tls/cert.pem:ro" + "${../configs/pki/buzz.app.internal.crt}:/etc/caddy/tls/cert.pem:ro" "${config.age.secrets.buzz-tls-key.path}:/etc/caddy/tls/key.pem:ro" ]; }; @@ -428,6 +445,9 @@ in }; }; + # Buzz management CLI. + environment.systemPackages = [ buzz-manage ]; + # Certbot TLS service skyg.server.dns.certbot = { enable = false; diff --git a/hosts/scripts/hl-minipc1/buzz-manage.sh b/hosts/scripts/hl-minipc1/buzz-manage.sh new file mode 100644 index 0000000..f39785f --- /dev/null +++ b/hosts/scripts/hl-minipc1/buzz-manage.sh @@ -0,0 +1,140 @@ +#!/usr/bin/env bash +# Buzz stack management — mirrors upstream block/buzz deploy/compose/run.sh, +# adapted to the container-services deployment: systemd unit instead of raw +# compose up/down, staged compose.yml, agenix env instead of a local .env. +# +# Expects these to be exported by the Nix wrapper before this file's content runs: +# BUZZ_ENV_FILE - agenix path of the buzz env file +# BUZZ_COMPOSE_BIN - store path of docker-compose +set -euo pipefail + +# Fallbacks so the file also runs directly from the repo for debugging. +BUZZ_ENV_FILE="${BUZZ_ENV_FILE:-/run/agenix/buzz-env}" +BUZZ_COMPOSE_BIN="${BUZZ_COMPOSE_BIN:-docker-compose}" + +STATE_DIR="/var/lib/container-services/buzz" +COMPOSE_FILE="$STATE_DIR/compose.yml" +UNIT="container-services-buzz.service" +UPDATE_UNIT="container-services-buzz-update.service" + +compose() { + if [ ! -f "$COMPOSE_FILE" ]; then + echo "$COMPOSE_FILE is not staged yet; run 'buzz-manage start' once" >&2 + exit 1 + fi + "$BUZZ_COMPOSE_BIN" -p buzz -f "$COMPOSE_FILE" "$@" +} + +require_env() { + if [ ! -f "$BUZZ_ENV_FILE" ]; then + cat >&2 <&2 <<'MSG' +buzz-env still contains CHANGE_ME placeholders. +Generate stable secrets first; these values must not rotate on restart. +MSG + exit 1 + fi +} + +backup_hint() { + cat <<'MSG' +Back up these before upgrades and on a regular schedule: + +- secrets/buzz-env.age (relay private key, DB/Redis/S3 secrets, HMAC secret) +- secrets/buzz-tls-key.age and configs/pki/buzz.app.internal.crt (lab CA TLS) +- Postgres data on tnas1:/mnt/SmallG/buzz/postgres (prefer pg_dump or a quiesced snapshot) +- MinIO/S3 data on tnas1:/mnt/SmallG/buzz/s3 (bucket: buzz-media) +- git objects on tnas1:/mnt/SmallG/buzz/git (BUZZ_GIT_REPO_PATH=/data/git) +- Redis data on tnas1:/mnt/SmallG/buzz/redis + +Keep Postgres + object/git state snapshots from the same maintenance window. +MSG +} + +case "${1:-help}" in + start|up) + require_env + systemctl start "$UNIT" + ;; + stop|down) + systemctl stop "$UNIT" + ;; + restart) + require_env + compose up -d --wait --force-recreate relay + ;; + pull) + require_env + compose pull + ;; + upgrade) + require_env + # Same pull + recreate path the auto-update timer uses. + systemctl start "$UPDATE_UNIT" + echo "pull output: journalctl -u $UPDATE_UNIT" + backup_hint + ;; + logs) + shift || true + compose logs -f "${@:-relay}" + ;; + status|ps) + systemctl --no-pager status "$UNIT" || true + compose ps + ;; + config) + require_env + compose config + ;; + backup-hint) + backup_hint + ;; + add-member) + compose exec relay /usr/local/bin/buzz-admin add-member --pubkey "${2:?Usage: buzz-manage add-member [--role member|admin]}" "${@:3}" + ;; + remove-member) + compose exec relay /usr/local/bin/buzz-admin remove-member --pubkey "${2:?Usage: buzz-manage remove-member [--role member|admin]}" "${@:3}" + ;; + list-members) + compose exec relay /usr/local/bin/buzz-admin list-members + ;; + help|-h|--help) + cat <<'MSG' +Usage: buzz-manage + +Commands: + start Start the stack (container-services-buzz.service) + stop Stop containers without deleting volumes + restart Recreate the relay after env/image changes + pull Pull configured images + upgrade Pull and restart via the update unit, then print backup reminders + logs [svc] Follow logs (default: relay) + status Show systemd unit and compose service status + config Render merged compose config + backup-hint Print the production backup checklist + + add-member [--role member|admin] + Add a relay member (default role: member) + remove-member [--role member|admin] + Remove a relay member + list-members List all relay members + + Note: when adding multiple members in a loop, add `sleep 1` between + invocations to avoid same-second timestamp collisions in the kind:13534 + roster event. Do not use parallel adds (e.g. xargs -P). + +Run as root (or via sudo): the env file and docker socket are root-only. +MSG + ;; + *) + echo "Unknown command: $1" >&2 + echo "Run 'buzz-manage help'" >&2 + exit 1 + ;; +esac diff --git a/secrets/buzz-env.age b/secrets/buzz-env.age index e413719c0b924c1a2f5160d68a40135f64c29c57..97f4f4d95fa01be1c913f664eefcc252b15e2dac 100644 GIT binary patch delta 1174 zcmV;H1Zn$`39<>0EPr7|S}|`~b!AL-PEJj0S7CH7S3!7LS~xRBb#OCDbz^o(Ye{Z2 zN^UktV+uxgQ$LBLoj%1c}99qHArJdW`9g;aA;LTFLz~ZNi#z* zPETuiL27n(Sz$s^3R!GuHZ@^5aBM*@T3T>9GkIDtH*#iSD_3+^WN1%0ZfbNgI5ad+ zVNQBy3N0-yAbLtOR6;>GD|T=-Su|8eY&AJaGG%IIGe$s66iAN9|dB- zT&v=+AbGm#IOhhie$i&VwaSfmy-4|QLGi+)Sz7d?=TF(<3)Y<5DV#BKT3CSm2lfs) zv>d$G&;4gu-k&D)3CSL}4cH?bRt_}H2>L@Cv@KN9F8Q1g)|=kbUwLmzWszymL3RLOc2#i|1H%@9a$Iapek!{GY4MkV~^WW?%Pk$pm&c?&?UOot``>v95EI{oT%*HXT zJJnEk>{4Z#z{CzzE5x8HcU>y2dd$#Uog|d-KRbZF62iilkmNEeE)r4bwvQNdD1a|H@@DS5fzlfP#gsJ^0R>z^|0-e4VE4&{i zVQn8$9Jb7rFU(b7(B4v-0C>^8${%H;uw953;i!+@`h7WL$km|OA`x!9NyN=n6Y=tw zg5?=w@zaIH@1$jHZbc5FW(FTfR@n{`BY)XDqV6pba-oQCl#Chjp&2O7Vp2y`#7>}* z6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