nixos/dhcpcd: add option to allow setuid binaries

The promise in the networking.dhcpcd.runHook description was broken by
further restrictions added in 21bb7ea9.

rnhmjoj 66db09eb 54a69497

Changed files
+24 -12
nixos
modules
services
networking
+24 -12
nixos/modules/services/networking/dhcpcd.nix
···
'';
};
+
networking.dhcpcd.allowSetuid = lib.mkOption {
+
type = lib.types.bool;
+
default = false;
+
description = ''
+
Whether to relax the security sandbox to allow running setuid
+
binaries (e.g. `sudo`) in the dhcpcd hooks.
+
'';
+
};
+
networking.dhcpcd.runHook = lib.mkOption {
type = lib.types.lines;
default = "";
···
::: {.note}
To use sudo or similar tools in your script you may have to set:
-
systemd.services.dhcpcd.serviceConfig.NoNewPrivileges = false;
+
networking.dhcpcd.allowSetuid = true;
In addition, as most of the filesystem is inaccessible to dhcpcd
by default, you may want to define some exceptions, e.g.
···
"CAP_NET_RAW"
"CAP_NET_BIND_SERVICE"
];
-
CapabilityBoundingSet = [
+
CapabilityBoundingSet = lib.optionals (!cfg.allowSetuid) [
"CAP_NET_ADMIN"
"CAP_NET_RAW"
"CAP_NET_BIND_SERVICE"
···
DeviceAllow = "";
LockPersonality = true;
MemoryDenyWriteExecute = true;
-
NoNewPrivileges = lib.mkDefault true; # may be disabled for sudo in runHook
+
NoNewPrivileges = lib.mkDefault (!cfg.allowSetuid); # may be disabled for sudo in runHook
PrivateDevices = true;
PrivateMounts = true;
PrivateTmp = true;
···
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
-
SystemCallFilter = [
-
"@system-service"
-
"~@aio"
-
"~@keyring"
-
"~@memlock"
-
"~@mount"
-
"~@privileged"
-
"~@resources"
-
];
+
SystemCallFilter =
+
[
+
"@system-service"
+
"~@aio"
+
"~@keyring"
+
"~@memlock"
+
"~@mount"
+
]
+
++ lib.optionals (!cfg.allowSetuid) [
+
"~@privileged"
+
"~@resources"
+
];
SystemCallArchitectures = "native";
UMask = "0027";
};