[repo] NixOS and docs: ianitor-caddy-guard with caddy-fallback, caddy-revert after every control stop, admin socket only for control, Caddy trial deadline in the engine-switch VM test, trusted proxies stay off beside Caddy
This commit is contained in:
+30
-3
@@ -151,7 +151,7 @@ in
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
example = [ "127.0.0.1" ];
|
||||
description = "Proxies in front of edge whose X-Forwarded-For names the client (beside Caddy: 127.0.0.1), for the share-link throttle and the access log. Off by default.";
|
||||
description = "Proxies in front of edge whose X-Forwarded-For names the client (beside Caddy: 127.0.0.1), for the share-link throttle and the access log. Off by default: on a loopback listener any local process could then claim any address (docs/deploy/beside-caddy.md).";
|
||||
};
|
||||
};
|
||||
|
||||
@@ -252,7 +252,9 @@ in
|
||||
}) userCreds;
|
||||
|
||||
users.groups.ianitor = { };
|
||||
users.users.ianitor-control = { isSystemUser = true; group = "ianitor"; home = "${stateRoot}/control"; };
|
||||
# Only control (and Caddy itself) may reach Caddy's admin socket; edge is not in it.
|
||||
users.groups.ianitor-caddy-admin = { };
|
||||
users.users.ianitor-control = { isSystemUser = true; group = "ianitor"; extraGroups = [ "ianitor-caddy-admin" ]; home = "${stateRoot}/control"; };
|
||||
users.users.ianitor-edge = { isSystemUser = true; group = "ianitor"; };
|
||||
users.users.caddy-fallback = { isSystemUser = true; group = "ianitor"; };
|
||||
|
||||
@@ -300,6 +302,10 @@ in
|
||||
User = "ianitor-control";
|
||||
Group = "ianitor";
|
||||
ExecStart = "${pkg}/bin/ianitor-control --config ${controlToml}";
|
||||
# After every stop, a crash included: a trial still loaded into Caddy goes back to the
|
||||
# last good caddy.json at once (ianitor_control::caddy_guard). It runs after a crash
|
||||
# too, so no separate OnFailure= unit is needed.
|
||||
ExecStopPost = "${pkg}/bin/ianitor-control caddy-revert --config ${controlToml}";
|
||||
LoadCredential = loadCreds controlCreds ++ [ "ui-proof:${runProof}/ui-proof" ];
|
||||
ReadWritePaths = [ stateRoot ];
|
||||
Restart = "on-failure";
|
||||
@@ -352,7 +358,10 @@ in
|
||||
};
|
||||
serviceConfig = hardening // {
|
||||
User = "caddy-fallback";
|
||||
Group = "ianitor";
|
||||
# The admin socket (and its runtime directory) belong to this group; "ianitor" for the
|
||||
# certificates and logs.
|
||||
Group = "ianitor-caddy-admin";
|
||||
SupplementaryGroups = [ "ianitor" ];
|
||||
ExecStart = "${cfg.caddyPackage}/bin/caddy run --config ${stateRoot}/caddy/caddy.json";
|
||||
LoadCredential = loadCreds cfg.credentials ++ [ "ui-proof:${runProof}/ui-proof" ];
|
||||
RuntimeDirectory = "caddy-fallback";
|
||||
@@ -367,6 +376,24 @@ in
|
||||
};
|
||||
};
|
||||
|
||||
# The deadline of a trial under Caddy, outside control (a hung control included): once a
|
||||
# second it reverts a trial past its deadline to the last good caddy.json. Runs with Caddy.
|
||||
systemd.services.ianitor-caddy-guard = {
|
||||
description = "Ianitor: deadline for changes tried on Caddy";
|
||||
partOf = [ "caddy-fallback.service" ];
|
||||
after = [ "caddy-fallback.service" ];
|
||||
wantedBy = [ "caddy-fallback.service" ];
|
||||
environment.IANITOR_LOG = "info";
|
||||
serviceConfig = hardening // {
|
||||
User = "ianitor-control";
|
||||
Group = "ianitor";
|
||||
ExecStart = "${pkg}/bin/ianitor-control caddy-guard --config ${controlToml}";
|
||||
ReadWritePaths = [ "${stateRoot}/control" ];
|
||||
Restart = "always";
|
||||
RestartSec = 1;
|
||||
};
|
||||
};
|
||||
|
||||
# At boot: start the engine the UI chose last (ROADMAP §3).
|
||||
systemd.services.ianitor-engine-select = {
|
||||
description = "Ianitor: start the chosen engine";
|
||||
|
||||
@@ -157,6 +157,27 @@ in
|
||||
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")
|
||||
|
||||
# The trial's deadline under Caddy does not depend on control (fix round 2, B2): the guard
|
||||
# runs with Caddy, only control may use Caddy's admin socket, and a control killed during
|
||||
# the watch leaves Caddy on the last good config (ExecStopPost=caddy-revert).
|
||||
server.succeed("systemctl is-active ianitor-caddy-guard.service")
|
||||
server.fail("runuser -u ianitor-edge -- test -w /run/caddy-fallback/admin.sock")
|
||||
server.succeed("runuser -u ianitor-control -- test -w /run/caddy-fallback/admin.sock")
|
||||
r = api(server, t, "POST", "/hosts", {"host": {
|
||||
"hostname": "three.test", "upstreams": ["http://127.0.0.1:8000"], "tls": "domi", "auth": "none"}})
|
||||
three = r["apply"]["id"]
|
||||
for _ in range(60):
|
||||
if api(server, t, "GET", f"/applies/{three}").get("state") == "watching":
|
||||
break
|
||||
time.sleep(0.5)
|
||||
assert visit(server, "three.test") == "200", "the trial serves"
|
||||
server.succeed("systemctl kill --signal=KILL ianitor-control.service")
|
||||
server.wait_until_fails("curl -s -o /dev/null -w '%{http_code}' --cacert ${testRoot}/domi-root.crt --resolve three.test:443:127.0.0.1 https://three.test/ | grep -q 200", timeout=10)
|
||||
server.wait_for_unit("ianitor-control.service")
|
||||
server.wait_until_succeeds(f"curl -sf -H 'Authorization: Bearer {t}' http://127.0.0.1:7878/api/v1/overview")
|
||||
assert wait_apply(server, t, three)["state"] == "reverted"
|
||||
assert visit(server, "two.test") == "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\"'"
|
||||
|
||||
Reference in New Issue
Block a user