WS-H: NixOS module, VM test, README section
Module: Origin/Host allowlists from allowedHosts and the FQDN, credentials refreshed on reload so SIGHUP rotates the TLS cert, string cert/key paths kept out of the store, docker.enable asserts virtualisation.docker. VM test covers healthz, 401, token mint/revoke via sudo -u, /mcp, Origin 403, root refusal and a TLS node. Package skips two unit tests that need host state the sandbox lacks. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017WMgwyHQQU9cB4ruRDrKow
This commit is contained in:
1 parent
46b4f5ac0b
commit
34da657fdf
6 files changed
+193
-16
No files matched your search
+23
-8
@@ -8,14 +8,23 @@ let
|
||||
credDir = "/run/credentials/${name}.service";
|
||||
toml = pkgs.formats.toml { };
|
||||
|
||||
scheme = if cfg.tls.enable then "https" else "http";
|
||||
hostName = config.networking.fqdnOrHostName;
|
||||
# Names clients use, with the port, so both the Host and the Origin
|
||||
# allowlists on /mcp accept them. Entries with a scheme are origins only.
|
||||
withPort = h: if lib.hasInfix ":" h then h else "${h}:${toString cfg.port}";
|
||||
hosts = lib.unique (map withPort (
|
||||
lib.optional (hostName != "") hostName
|
||||
++ lib.filter (h: !lib.hasInfix "://" h) cfg.allowedHosts
|
||||
));
|
||||
|
||||
moduleDefaults = {
|
||||
server = {
|
||||
bind = cfg.bind;
|
||||
port = cfg.port;
|
||||
allowed_hosts = lib.unique ([
|
||||
config.networking.hostName
|
||||
"${config.networking.hostName}:${toString cfg.port}"
|
||||
] ++ cfg.allowedHosts);
|
||||
allowed_hosts = hosts;
|
||||
allowed_origins = map (h: "${scheme}://${h}") (lib.filter (h: !lib.hasInfix "://" h) hosts)
|
||||
++ lib.filter (h: lib.hasInfix "://" h) cfg.allowedHosts;
|
||||
} // lib.optionalAttrs cfg.tls.enable {
|
||||
tls = {
|
||||
enabled = true;
|
||||
@@ -64,14 +73,14 @@ in
|
||||
tls = {
|
||||
enable = mkEnableOption "native TLS for REST and /mcp";
|
||||
certFile = mkOption {
|
||||
type = types.nullOr types.path;
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = "PEM certificate chain. Passed through systemd LoadCredential, so the service user needs no access to the original file.";
|
||||
description = "Absolute path, kept out of the store (use a string, not a path literal). PEM certificate chain. Passed through systemd LoadCredential, so the service user needs no access to the original file.";
|
||||
};
|
||||
keyFile = mkOption {
|
||||
type = types.nullOr types.path;
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = "PEM private key. Passed through systemd LoadCredential.";
|
||||
description = "Absolute path, kept out of the store (use a string, not a path literal). PEM private key. Passed through systemd LoadCredential.";
|
||||
};
|
||||
};
|
||||
|
||||
@@ -121,6 +130,10 @@ in
|
||||
assertion = isLoopback bind || authEnabled;
|
||||
message = "services.skyg-linux-tracker: a non-loopback bind (${bind}) requires auth.enabled = true.";
|
||||
}
|
||||
{
|
||||
assertion = !cfg.docker.enable || config.virtualisation.docker.enable;
|
||||
message = "services.skyg-linux-tracker.docker.enable needs virtualisation.docker.enable (or use a socket proxy via settings.sources.docker_socket instead).";
|
||||
}
|
||||
{
|
||||
assertion = !cfg.tls.enable || (cfg.tls.certFile != null && cfg.tls.keyFile != null);
|
||||
message = "services.skyg-linux-tracker.tls.enable requires tls.certFile and tls.keyFile.";
|
||||
@@ -161,6 +174,8 @@ in
|
||||
Type = "simple";
|
||||
ExecStart = "${lib.getExe cfg.package} serve --config /etc/${name}.toml";
|
||||
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
||||
# Credentials are copied at start; refresh them so a reload rotates the cert.
|
||||
RefreshOnReload = mkIf cfg.tls.enable "credentials";
|
||||
Restart = "on-failure";
|
||||
RestartSec = 5;
|
||||
TimeoutStopSec = 30;
|
||||
|
||||
Reference in new issue
Block a user