[repo] NixOS and docs: Caddy admin socket for changes under Caddy, polkit start/stop only, edge never stops restarting, openssl in the VM tests, beside-Caddy without secrets in argv, pinned Ianitor rev, X-Served-By trial marker

This commit is contained in:
2026-11-08 10:49:42 +01:00
parent e84eb1ba74
commit bc336d1188
7 changed files with 86 additions and 38 deletions
+12 -3
View File
@@ -4,7 +4,9 @@
# services.ianitor: ianitor-edge (the only public listener), ianitor-control (loopback),
# caddy-fallback (the same routes as Caddy JSON), the engine-select unit, the per-boot UI proof,
# and a polkit rule that lets control start, stop and restart exactly the two engine units.
# and a polkit rule that lets control start and stop exactly the two engine units. While Caddy
# serves, control loads changes into it through its admin socket (/run/caddy-fallback/admin.sock,
# group ianitor, 0660).
#
# Secrets never enter the Nix store: every credential is a *path string* to a file outside the
# store (sops-nix, agenix, Custos provisioning, ...), loaded with systemd LoadCredential; an
@@ -66,6 +68,8 @@ let
compile_caddy = compile // {
state_dir = "${stateRoot}/caddy-state";
access_log = "/var/log/ianitor/caddy-access.log";
# Changes keep working under Caddy: control loads them through this socket.
caddy_admin_socket = "/run/caddy-fallback/admin.sock";
};
ui =
{
@@ -298,6 +302,8 @@ in
systemd.services.ianitor-edge = {
description = "Ianitor edge (Pingora)";
# Never give up restarting the only public listener.
startLimitIntervalSec = 0;
after = [ "network-online.target" "ianitor-control.service" "ianitor-ui-proof.service" ];
wants = [ "network-online.target" ];
requires = [ "ianitor-ui-proof.service" ];
@@ -342,6 +348,8 @@ in
Group = "ianitor";
ExecStart = "${cfg.caddyPackage}/bin/caddy run --config ${stateRoot}/caddy/caddy.json";
LoadCredential = loadCreds cfg.credentials ++ [ "ui-proof:${runProof}/ui-proof" ];
RuntimeDirectory = "caddy-fallback";
RuntimeDirectoryMode = "0750";
ReadWritePaths = [ "${stateRoot}/caddy-state" "/var/log/ianitor" ];
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
@@ -370,7 +378,8 @@ in
'';
};
# Control may start, stop and restart exactly the two engine units, nothing else.
# Control may start and stop exactly the two engine units, nothing else. (polkit is new on a
# server that had no other use for it.)
security.polkit.enable = true;
security.polkit.extraConfig = ''
polkit.addRule(function (action, subject) {
@@ -378,7 +387,7 @@ in
var unit = action.lookup("unit");
var verb = action.lookup("verb");
if ((unit == "ianitor-edge.service" || unit == "caddy-fallback.service") &&
(verb == "start" || verb == "stop" || verb == "restart")) {
(verb == "start" || verb == "stop")) {
return polkit.Result.YES;
}
}
+7 -1
View File
@@ -51,7 +51,7 @@ let
wantedBy = [ "multi-user.target" ];
serviceConfig.ExecStart = "${pkgs.python3}/bin/python3 -m http.server 8000 --bind 127.0.0.1 --directory /etc";
};
environment.systemPackages = [ pkgs.curl pkgs.jq ];
environment.systemPackages = [ pkgs.curl pkgs.jq pkgs.openssl ];
};
# Python helpers shared by the test scripts.
@@ -151,6 +151,12 @@ in
assert server.succeed("cat /var/lib/ianitor/engine").strip() == "caddy"
server.wait_until_succeeds("curl -s -o /dev/null -w '%{http_code}' --cacert ${testRoot}/domi-root.crt --resolve app.test:443:127.0.0.1 https://app.test/ | grep -q 200")
# Changes keep working while Caddy serves: loaded through its admin socket and watched.
r = api(server, t, "POST", "/hosts", {"host": {
"hostname": "two.test", "upstreams": ["http://127.0.0.1:8000"], "tls": "domi", "auth": "none"}})
assert wait_apply(server, t, r["apply"]["id"])["state"] == "kept"
server.succeed("curl -s -o /dev/null -w '%{http_code}' --cacert ${testRoot}/domi-root.crt --resolve two.test:443:127.0.0.1 https://two.test/ | grep -q 200")
api(server, t, "POST", "/engine", {"target": "pingora"})
server.wait_until_succeeds(
f"curl -s -H 'Authorization: Bearer {t}' http://127.0.0.1:7878/api/v1/engine | jq -e '.running == \"pingora\" and .state == \"running\"'"
+9 -6
View File
@@ -15,8 +15,9 @@
# --public HOST must answer 2xx or 3xx (not a sign-in redirect)
# --protected HOST without a session, must redirect to --auth-host (302/303) or answer 401
# --auth-host HOST Authelia's portal name, for --protected
# --via-ianitor HOST must answer 2xx/3xx, and the answer must not come from Caddy alone
# (Ianitor adds no Via; Caddy adds "Via: 1.1 Caddy" once, so exactly one)
# --via-ianitor HOST must answer 2xx/3xx with "X-Served-By: ianitor": the trial hosts set that
# response header in their Ianitor route (configuration-server.patch), so
# an answer Caddy gives on its own fails
# --control-port N control's port (default 7878): must NOT answer from outside
# --insecure accept a certificate the client does not trust (staging: tls internal)
#
@@ -57,7 +58,7 @@ failures=0
pass() { printf 'ok %s\n' "$1"; }
fail() { printf 'FAIL %s\n' "$1"; failures=$((failures + 1)); }
# status, location and the number of Via headers for https://HOST/ sent to the server
# the response head of https://HOST/ sent to the server
probe() {
curl -sS -o /dev/null -D - --max-time 15 "${insecure[@]}" \
--resolve "$1:443:$server" "https://$1/" 2>/dev/null | tr -d '\r'
@@ -88,9 +89,11 @@ done
for h in "${via[@]}"; do
head=$(probe "$h")
code=$(printf '%s\n' "$head" | awk 'NR==1 {print $2}')
vias=$(printf '%s\n' "$head" | grep -ci '^via:' || true)
if [[ "$code" =~ ^[23][0-9][0-9]$ ]]; then
pass "through Ianitor $h answers $code (Via headers: $vias)"
served=$(printf '%s\n' "$head" | awk 'tolower($1)=="x-served-by:" {print tolower($2)}')
if [[ "$code" =~ ^[23][0-9][0-9]$ ]] && [ "$served" = "ianitor" ]; then
pass "through Ianitor $h answers $code (X-Served-By: ianitor)"
elif [[ "$code" =~ ^[23][0-9][0-9]$ ]]; then
fail "$h answers $code, but not through Ianitor (no X-Served-By: ianitor)"
else
fail "through Ianitor $h answers '${code:-nothing}'"
fi