0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-13 21:50:33 +03:00

nixos/acme: fix cert ownership assert message

Handle the case where a service has no `User` defined in the message
in addition to the assertion itself.
This commit is contained in:
ThinkChaos 2024-12-05 20:15:25 -05:00
parent 55d15ad12a
commit 1e8e314fdb
No known key found for this signature in database

View file

@ -4,18 +4,19 @@ lib:
let let
catSep = builtins.concatStringsSep; catSep = builtins.concatStringsSep;
svcUser = svc: svc.serviceConfig.User or "root";
svcGroups = svc: svcGroups = svc:
(lib.optional (svc.serviceConfig ? Group) svc.serviceConfig.Group) (lib.optional (svc.serviceConfig ? Group) svc.serviceConfig.Group)
++ lib.toList (svc.serviceConfig.SupplementaryGroups or [ ]); ++ lib.toList (svc.serviceConfig.SupplementaryGroups or [ ]);
in in
{ {
assertion = builtins.all (svc: assertion = builtins.all (svc:
svc.serviceConfig.User or "root" == "root" svcUser svc == "root"
|| builtins.elem svc.serviceConfig.User groups.${cert.group}.members || builtins.elem (svcUser svc) groups.${cert.group}.members
|| builtins.elem cert.group (svcGroups svc) || builtins.elem cert.group (svcGroups svc)
) services; ) services;
message = "Certificate ${cert.domain} (group=${cert.group}) must be readable by service(s) ${ message = "Certificate ${cert.domain} (group=${cert.group}) must be readable by service(s) ${
catSep ", " (map (svc: "${svc.name} (user=${svc.serviceConfig.User} groups=${catSep " " (svcGroups svc)})") services) catSep ", " (map (svc: "${svc.name} (user=${svcUser svc} groups=${catSep "," (svcGroups svc)})") services)
}"; }";
} }