Every host runs node_exporter, cAdvisor (now against Podman), Alloy and the security-metrics script, on its private address. Each service declares its own expected ports, users and privileged containers next to its definition, so the security baseline follows the config instead of a separate inventory list. On ops: Prometheus, Loki, Grafana, the blackbox prober and the Postgres exporter, with the same scrape jobs, probes, retention, dashboards and 33 alert rules. Two rules matched container-era names and now match the native ones: Forgejo's log is unit forgejo.service, Grafana's route is grafana@file. Grafana keeps its default secret_key on production, because its database was written with it; rotating it is a separate step. Prometheus, Grafana and Alloy come from nixos-unstable: their data is from newer versions than 26.05 ships. LLMNR and mDNS are off: the baseline flagged them as public listeners. Tried on the rehearsal pair: all 28 scrape targets up, logs from both hosts in Loki, Grafana WireGuard-only, no unexpected port, user or container on either host. Assisted-by: Claude:opus-5-5
162 lines
5.3 KiB
Nix
162 lines
5.3 KiB
Nix
# Forgejo Actions runners. Jobs are containers started through Podman's
|
|
# Docker-compatible socket.
|
|
#
|
|
# asxpio for git.asxp.io, reached over the private network
|
|
# interop for another-im/interop on dev.another.im
|
|
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
let
|
|
# Image behind the nix labels. Jobs mount a nix-store volume over /nix,
|
|
# seeded from this image on first use; the image's /bin/sh and
|
|
# /etc/nix/nix.conf link into that store, so a volume from another
|
|
# version breaks every job. Bumping this switches to a fresh volume;
|
|
# remove the old one afterwards (podman volume rm nix-store-<old>).
|
|
# renovate: datasource=docker depName=nixos/nix
|
|
nixVersion = "2.35.6";
|
|
|
|
yaml = pkgs.formats.yaml { };
|
|
interopConfig = yaml.generate "runner-interop.yaml" {
|
|
log = {
|
|
level = "info";
|
|
job_level = "info";
|
|
};
|
|
runner = {
|
|
capacity = 3;
|
|
timeout = "5h";
|
|
shutdown_timeout = "5h";
|
|
fetch_interval = "5s";
|
|
envs.NIX_CONFIG = ''
|
|
experimental-features = nix-command flakes
|
|
build-users-group =
|
|
sandbox = false
|
|
'';
|
|
labels = [
|
|
"nix:docker://nixos/nix:${nixVersion}"
|
|
"docker:docker://node:22.23.5-bookworm"
|
|
"nix-host:docker://nixos/nix:${nixVersion}"
|
|
];
|
|
};
|
|
container = {
|
|
network = "bridge";
|
|
privileged = false;
|
|
docker_host = "-"; # its jobs get no container socket
|
|
valid_volumes = [ ];
|
|
force_pull = false;
|
|
};
|
|
};
|
|
in
|
|
{
|
|
options.asxpio.runner.forgejoUrl = lib.mkOption {
|
|
type = lib.types.str;
|
|
default = "http://10.10.0.10:3000"; # over the private network, not through Traefik
|
|
};
|
|
|
|
config = {
|
|
sops.secrets."runner/token" = { };
|
|
sops.secrets."runner/interop_token" = { };
|
|
sops.templates."runner.env".content = ''
|
|
TOKEN=${config.sops.placeholder."runner/token"}
|
|
'';
|
|
# The connection (URL, UUID, token) is merged into the config at
|
|
# start; the UUID is not secret (interop's infra/runner.json)
|
|
sops.templates."runner-interop-server.yaml".content = ''
|
|
server:
|
|
connections:
|
|
interop:
|
|
url: https://dev.another.im/
|
|
uuid: dc326085-8420-4c33-8b88-a9ef46b3359b
|
|
token: ${config.sops.placeholder."runner/interop_token"}
|
|
'';
|
|
|
|
# The job cache server listens on a random port
|
|
asxpio.security.ports = [ "tcp/*/.forgejo-runner" ];
|
|
asxpio.security.containers."FORGEJO-ACTIONS-TASK-.*" = [ "docker-sock" ]; # docker_host: automount
|
|
|
|
services.gitea-actions-runner = {
|
|
package = pkgs.forgejo-runner;
|
|
instances.asxpio = {
|
|
enable = true;
|
|
name = config.networking.hostName;
|
|
url = config.asxpio.runner.forgejoUrl;
|
|
tokenFile = config.sops.templates."runner.env".path;
|
|
labels = [
|
|
"ubuntu-latest:docker://node:20.20.2-bookworm"
|
|
"ubuntu-22.04:docker://node:20.20.2-bookworm"
|
|
"ubuntu-24.04:docker://node:22.23.5-bookworm"
|
|
"debian-latest:docker://debian:12.15"
|
|
"debian-12:docker://debian:12.15"
|
|
"debian-11:docker://debian:11.11"
|
|
"arch-latest:docker://archlinux:base-20261108.0.623074"
|
|
"nginx-latest:docker://nginx:1.31.8"
|
|
"nginx-alpine:docker://nginx:1.31.8-alpine"
|
|
"node-20:docker://node:20.20.2"
|
|
"node-22:docker://node:22.23.5"
|
|
"python-3.11:docker://python:3.11.18"
|
|
"python-3.12:docker://python:3.12.16"
|
|
"alpine-latest:docker://alpine:3.24.4"
|
|
"nix-latest:docker://nixos/nix:${nixVersion}"
|
|
];
|
|
settings = {
|
|
log = {
|
|
level = "info";
|
|
job_level = "info";
|
|
};
|
|
runner = {
|
|
capacity = 4;
|
|
timeout = "3h";
|
|
shutdown_timeout = "3h";
|
|
fetch_timeout = "5s";
|
|
fetch_interval = "2s";
|
|
report_interval = "1s";
|
|
};
|
|
cache.enabled = true;
|
|
container = {
|
|
privileged = false;
|
|
options = "-v nix-store-${nixVersion}:/nix";
|
|
valid_volumes = [ "**" ];
|
|
docker_host = "automount"; # deploy jobs build and push images
|
|
force_pull = false;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
systemd.services.forgejo-runner-interop = {
|
|
description = "Forgejo Actions runner for another-im/interop";
|
|
wantedBy = [ "multi-user.target" ];
|
|
after = [
|
|
"network-online.target"
|
|
"podman.socket"
|
|
];
|
|
wants = [
|
|
"network-online.target"
|
|
"podman.socket"
|
|
];
|
|
environment.DOCKER_HOST = "unix:///run/podman/podman.sock";
|
|
path = [
|
|
pkgs.forgejo-runner
|
|
pkgs.yq-go
|
|
];
|
|
serviceConfig = {
|
|
DynamicUser = true;
|
|
SupplementaryGroups = [ "podman" ];
|
|
StateDirectory = "forgejo-runner-interop";
|
|
WorkingDirectory = "/var/lib/forgejo-runner-interop";
|
|
RuntimeDirectory = "forgejo-runner-interop";
|
|
LoadCredential = "server.yaml:${config.sops.templates."runner-interop-server.yaml".path}";
|
|
Restart = "always";
|
|
RestartSec = 5;
|
|
};
|
|
script = ''
|
|
umask 077
|
|
yq eval-all '. as $i ireduce ({}; . * $i)' ${interopConfig} "$CREDENTIALS_DIRECTORY/server.yaml" \
|
|
> "$RUNTIME_DIRECTORY/config.yaml"
|
|
exec forgejo-runner daemon --config "$RUNTIME_DIRECTORY/config.yaml"
|
|
'';
|
|
};
|
|
};
|
|
}
|