git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/nscd: only drop privs after nss module init

NixOS usually needs nscd just to have a single place where LD_LIBRARY_PATH can be set to include all NSS modules, but nscd is also useful if some of the NSS modules need to read files which are only accessible by root. For example, nixos/modules/config/ldap.nix needs this when users.ldap.enable = true; users.ldap.daemon.enable = false; and users.ldap.bind.passwordFile exists. In that case, the module creates an /etc/ldap.conf which is only readable by root, but which the NSS module needs to read in order to find out what LDAP server to connect to and with what credentials. If nscd is started as root and configured with the server-user option in nscd.conf, then it gives each NSS module the opportunity to initialize itself before dropping privileges. The initialization happens in the glibc-internal __nss_disable_nscd function, which pre-loads all the configured NSS modules for passwd, group, hosts, and services (but not netgroup for some reason?) and, for each loaded module, calls an init function if one is defined. After that finishes, nscd's main() calls nscd_init() which ends by calling finish_drop_privileges(). There are provisions in systemd for using DynamicUser with a service which needs to drop privileges itself, so this patch does that.

commitf7c776760babb4f2d5d4341a5dbd882bf7751e9c authorJamey Sharp <jamey@minilop.net> dateSun 7 Jul 2019, 08:43 (7 years ago) parentc38fa99
2 files changed+2−1
nixos/modules/services/system/nscd.conf+1 nixos/modules/services/system/nscd.nix+1−1
nixos/modules/services/system/nscd.conf+1
@@ -6,6 +6,7 @@
66# fallback to trying to handle the request by itself. Which won't work as glibc
77# is not aware of the path in which the nss modules live. As a workaround, we
88# have `enable-cache yes` with an explicit ttl of 0
9+server-user nscd
910
1011enable-cache passwd yes
1112positive-time-to-live passwd 0
nixos/modules/services/system/nscd.nix+1−1
@@ -53,7 +53,7 @@ in
5353 ];
5454
5555 serviceConfig =
56− { ExecStart = "@${pkgs.glibc.bin}/sbin/nscd nscd";
56+ { ExecStart = "!@${pkgs.glibc.bin}/sbin/nscd nscd";
5757 Type = "forking";
5858 DynamicUser = true;
5959 RuntimeDirectory = "nscd";