From 564842d332d97a2354853b865963ce7548ecd826 Mon Sep 17 00:00:00 2001 From: maia Date: Mon, 30 Nov 2026 15:17:27 +0100 Subject: [PATCH] swarm-victorialogs, swarm-victoriametrics: the four responders' socket directories admit only the service and nginx --- nix/host-modules/swarm-victorialogs.nix | 19 +++++++++++++--- nix/host-modules/swarm-victoriametrics.nix | 16 ++++++++++--- nix/module-eval/core-toggle.nix | 26 ++++++++++++++++++++++ 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/nix/host-modules/swarm-victorialogs.nix b/nix/host-modules/swarm-victorialogs.nix index 4ef88a29a..00480c100 100644 --- a/nix/host-modules/swarm-victorialogs.nix +++ b/nix/host-modules/swarm-victorialogs.nix @@ -539,6 +539,17 @@ in }; users.groups.${logsAuthUnit} = { }; + # Through the unit, not `users.users.nginx.extraGroups`: systemd resolves a + # unit's groups at start, and only a changed unit file makes the switch + # restart nginx (it does not reload) onto the new group. Each responder's + # directory is `0750` in its own group, so nginx is the only other user in. + systemd.services.nginx = lib.mkIf config.services.nginx.enable { + serviceConfig.SupplementaryGroups = [ + logsAuthUnit + grafanaAuthUnit + ]; + }; + systemd.services.${logsAuthUnit} = { description = "swarm log store auth_request responder for agent credentials"; wantedBy = [ "multi-user.target" ]; @@ -565,8 +576,10 @@ in User = logsAuthUnit; Group = logsAuthUnit; RuntimeDirectory = logsAuthUnit; - # Traverse-only for others, so nginx reaches the socket path. - RuntimeDirectoryMode = "0751"; + # Only the service and nginx (through a supplementary group on its unit) + # enter the directory: the socket is `0666`, and the directory is what + # keeps other local users off it. + RuntimeDirectoryMode = "0750"; # The path never vanishes from under a running nginx; the responder # unlinks a stale socket as it starts. RuntimeDirectoryPreserve = "yes"; @@ -619,7 +632,7 @@ in User = grafanaAuthUnit; Group = grafanaAuthUnit; RuntimeDirectory = grafanaAuthUnit; - RuntimeDirectoryMode = "0751"; + RuntimeDirectoryMode = "0750"; RuntimeDirectoryPreserve = "yes"; Restart = "on-failure"; RestartSec = "5s"; diff --git a/nix/host-modules/swarm-victoriametrics.nix b/nix/host-modules/swarm-victoriametrics.nix index c44cf976a..338e7381f 100644 --- a/nix/host-modules/swarm-victoriametrics.nix +++ b/nix/host-modules/swarm-victoriametrics.nix @@ -620,8 +620,10 @@ in User = metricsAuthUnit; Group = metricsAuthUnit; RuntimeDirectory = metricsAuthUnit; - # Traverse-only for others, so nginx reaches the socket path. - RuntimeDirectoryMode = "0751"; + # Only the service and nginx (through a supplementary group on its unit) + # enter the directory: the socket is `0666`, and the directory is what + # keeps other local users off it. + RuntimeDirectoryMode = "0750"; # The path never vanishes from under a running nginx; the responder # unlinks a stale socket as it starts. RuntimeDirectoryPreserve = "yes"; @@ -674,7 +676,7 @@ in User = agentAuthUnit; Group = agentAuthUnit; RuntimeDirectory = agentAuthUnit; - RuntimeDirectoryMode = "0751"; + RuntimeDirectoryMode = "0750"; RuntimeDirectoryPreserve = "yes"; Restart = "on-failure"; RestartSec = "5s"; @@ -704,6 +706,14 @@ in # is tmpfiles', and absent until that has run. systemd.services.nginx = { serviceConfig.ReadWritePaths = [ "-${egressDir}" ]; + # Through the unit, not `users.users.nginx.extraGroups`: systemd resolves + # a unit's groups at start, and only a changed unit file makes the switch + # restart nginx (it does not reload) onto the new group. Each responder's + # directory is `0750` in its own group, so nginx is the only other user in. + serviceConfig.SupplementaryGroups = [ + metricsAuthUnit + agentAuthUnit + ]; preStart = lib.mkBefore "rm -f ${egressSocket}"; }; diff --git a/nix/module-eval/core-toggle.nix b/nix/module-eval/core-toggle.nix index 5ebde9ef6..667d923cc 100644 --- a/nix/module-eval/core-toggle.nix +++ b/nix/module-eval/core-toggle.nix @@ -1347,6 +1347,32 @@ let logs.secureJsonData.httpHeaderValue1 == metrics.secureJsonData.httpHeaderValue1 && lib.hasInfix "--store-path ${leaf}" allLocal.systemd.services.swarm-logs-grafana-auth.serviceConfig.ExecStart; } + { + # Each responder binds its socket `0666`, so the directory is the only + # thing between the socket and every other local user: `0751` let them + # all in. nginx enters through a supplementary group, so the responders + # keep their own group and gain none of nginx's (its TLS keys among them). + name = "the four store responders' socket directories admit only the service and nginx"; + ok = + let + s = allLocal.systemd.services; + units = [ + "swarm-logs-auth" + "swarm-logs-grafana-auth" + "swarm-metrics-auth" + "swarm-metrics-agent-auth" + ]; + in + lib.all ( + u: + s.${u}.serviceConfig.RuntimeDirectoryMode == "0750" + && s.${u}.serviceConfig.Group == u + && allLocal.users.users.${u}.group == u + && s.${u}.serviceConfig.RuntimeDirectory == u + && s.${u}.serviceConfig.DynamicUser or false == false + && lib.elem u s.nginx.serviceConfig.SupplementaryGroups + ) units; + } { # The responder reads the store as itself, with the leaf the store's # host mints for it.