[deploy] Sockets: services.ianitor.edge.proxySocket (Caddy beside Ianitor reaches edge on a 0660 socket of the ianitor-proxy group) and ui.socket (control's UI socket, the proof trusted only there); the Configuration_Server patch, beside-caddy.md and api.md follow; a VM test for both

This commit is contained in:
2026-11-10 21:09:24 +01:00
parent d249bcf9f2
commit 1358649550
5 changed files with 146 additions and 40 deletions
+54 -7
View File
@@ -20,6 +20,14 @@ let
pkg = cfg.package;
stateRoot = "/var/lib/ianitor";
runProof = "/run/ianitor-proof";
# Control's UI socket (G14 option b): its directory is control's RuntimeDirectory, 0750
# ianitor-control:ianitor, so only the ianitor group (edge, Caddy) can reach it and no other
# user can put a socket there while control restarts.
uiSocket = "/run/ianitor-control/ui.sock";
# The front proxy's socket (Caddy beside Ianitor): its directory is setgid ianitor-proxy, so
# the socket either engine makes there belongs to that group.
proxyDir = "/run/ianitor-proxy";
proxySocket = "${proxyDir}/edge.sock";
toml = pkgs.formats.toml { };
isStore = p: lib.hasPrefix builtins.storeDir (toString p);
@@ -42,7 +50,7 @@ let
access_log = "/var/log/ianitor/access.log";
caddy_credentials_dir = "/run/credentials/caddy-fallback.service";
trusted_proxies = cfg.edge.trustedProxies;
};
} // lib.optionalAttrs cfg.edge.proxySocket.enable { proxy_socket = proxySocket; };
controlToml = toml.generate "control.toml" (
{
@@ -78,6 +86,7 @@ let
static_dir = "${pkg}/share/ianitor/web";
}
// lib.optionalAttrs (cfg.ui.hostname != null) { hostname = cfg.ui.hostname; }
// lib.optionalAttrs cfg.ui.socket { socket = uiSocket; }
// lib.optionalAttrs (cfg.ui.logoutUrl != null) { logout_url = cfg.ui.logoutUrl; };
engine = {
file = "${stateRoot}/engine";
@@ -147,11 +156,24 @@ in
default = false;
description = "Open edge's two ports in the firewall.";
};
proxySocket = {
enable = mkEnableOption ''
a Unix socket (${proxySocket}, 0660, group ianitor-proxy) on which edge (or the Caddy
fallback) serves the HTTPS hosts in plain HTTP to a front proxy that terminated TLS,
such as Caddy beside Ianitor. Only that group can connect, so its X-Forwarded-For is
believed; no loopback TCP port is involved'';
users = mkOption {
type = types.listOf types.str;
default = [ ];
example = [ "caddy" ];
description = "The front proxy's users, added to the ianitor-proxy group so they can connect.";
};
};
trustedProxies = mkOption {
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: on a loopback listener any local process could then claim any address (docs/deploy/beside-caddy.md).";
description = "Proxies in front of edge whose X-Forwarded-For names the client, for the share-link throttle and the access log. Off by default: on a loopback listener any local process could then claim any address. Beside Caddy, use edge.proxySocket instead (docs/deploy/beside-caddy.md).";
};
};
@@ -229,6 +251,15 @@ in
example = "ianitor.example";
description = "The admin host edge serves the UI on (a host in the routes repository with forward-auth and the X-Ianitor-Proof rule, docs/api.md).";
};
socket = mkOption {
type = types.bool;
default = true;
description = ''
Serve the API for the admin host on ${uiSocket} as well, and trust the UI proof only
there (G14 option b): the admin host's upstream is then `unix:${uiSocket}`. Over the
loopback port, which every local process can reach, only API tokens work.
'';
};
logoutUrl = mkOption {
type = types.nullOr types.str;
default = null;
@@ -255,8 +286,19 @@ in
# 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"; };
users.users.ianitor-edge = {
isSystemUser = true;
group = "ianitor";
extraGroups = lib.optional cfg.edge.proxySocket.enable "ianitor-proxy";
};
users.users.caddy-fallback = {
isSystemUser = true;
group = "ianitor";
extraGroups = lib.optional cfg.edge.proxySocket.enable "ianitor-proxy";
};
users.groups.ianitor-proxy = mkIf cfg.edge.proxySocket.enable {
members = cfg.edge.proxySocket.users;
};
systemd.tmpfiles.rules = [
"d ${stateRoot} 0755 ianitor-control ianitor - -"
@@ -268,7 +310,7 @@ in
"d ${stateRoot}/caddy-state 0700 caddy-fallback ianitor - -"
"f ${stateRoot}/engine 0644 ianitor-control ianitor - ${cfg.defaultEngine}"
"d /var/log/ianitor 0770 ianitor-edge ianitor - -"
];
] ++ lib.optional cfg.edge.proxySocket.enable "d ${proxyDir} 2770 root ianitor-proxy - -";
environment.systemPackages = [ pkg ];
# The non-secret config, so the CLI (token, pki) finds it: --config /etc/ianitor/control.toml.
@@ -308,6 +350,9 @@ in
ExecStopPost = "${pkg}/bin/ianitor-control caddy-revert --config ${controlToml}";
LoadCredential = loadCreds controlCreds ++ [ "ui-proof:${runProof}/ui-proof" ];
ReadWritePaths = [ stateRoot ];
# The UI socket's directory: 0750, so the ianitor group may connect and nobody else.
RuntimeDirectory = "ianitor-control";
RuntimeDirectoryMode = "0750";
Restart = "on-failure";
RestartSec = 2;
};
@@ -334,7 +379,8 @@ in
LoadCredential = loadCreds edgeCreds ++ [ "ui-proof:${runProof}/ui-proof" ];
RuntimeDirectory = "ianitor-edge";
RuntimeDirectoryMode = "0750";
ReadWritePaths = [ "${stateRoot}/edge-state" "/var/log/ianitor" ];
ReadWritePaths = [ "${stateRoot}/edge-state" "/var/log/ianitor" ]
++ lib.optional cfg.edge.proxySocket.enable proxyDir;
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
# The first start may come before control has written edge.json.
@@ -366,7 +412,8 @@ in
LoadCredential = loadCreds cfg.credentials ++ [ "ui-proof:${runProof}/ui-proof" ];
RuntimeDirectory = "caddy-fallback";
RuntimeDirectoryMode = "0750";
ReadWritePaths = [ "${stateRoot}/caddy-state" "/var/log/ianitor" ];
ReadWritePaths = [ "${stateRoot}/caddy-state" "/var/log/ianitor" ]
++ lib.optional cfg.edge.proxySocket.enable proxyDir;
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
# Go needs W^X for its runtime on some platforms.