Watch
0
0
Fork
You've already forked hyperhive
0

swarm-victorialogs, swarm-victoriametrics: the four responders' socket directories admit only the service and nginx

This commit is contained in:
maia 2026-11-30 15:17:27 +01:00 • committed by mara
commit 564842d332
3 changed files with 55 additions and 6 deletions

View file

@ -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";

View file

@ -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}";
};

View file

@ -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.