nixos/wireless: add enableHardening option#484382
nixos/wireless: add enableHardening option#484382sternenseemann merged 1 commit intoNixOS:masterfrom
Conversation
ed506e5 to
d0abc5c
Compare
d0abc5c to
1f00b56
Compare
|
Should this maybe be off by default based on the stateVersion? |
There's no need: I intentionally postponed merging the hardening changes after 25.11 and I will not backport them, of course. |
|
All the |
1f00b56 to
80f8e04
Compare
|
@tazjin, please check the new version of the PR. |
| ExecStartPre = | ||
| lib.optionals (cfg.allowAuxiliaryImperativeNetworks || !hasDeclarative) [ | ||
| # set up imperative config file | ||
| "+${pkgs.coreutils}/bin/touch /etc/wpa_supplicant/imperative.conf" | ||
| "+${pkgs.coreutils}/bin/chmod 664 /etc/wpa_supplicant/imperative.conf" | ||
| "+${pkgs.coreutils}/bin/chown -R wpa_supplicant:wpa_supplicant /etc/wpa_supplicant" | ||
| ] | ||
| ++ lib.optionals cfg.userControlled [ | ||
| # set up client sockets directory | ||
| "+${pkgs.coreutils}/bin/mkdir /run/wpa_supplicant/client" | ||
| "+${pkgs.coreutils}/bin/chown wpa_supplicant:wpa_supplicant /run/wpa_supplicant/client" | ||
| "+${pkgs.coreutils}/bin/chmod g=u /run/wpa_supplicant/client" | ||
| ]; |
There was a problem hiding this comment.
Those should really be in tmpfiles 😓
There was a problem hiding this comment.
I get that systemd-tmpfiles has a neater syntax and was made for this sort of thing, but it provides less guarantees. If the files permissions gets messed up or they get deleted, wpa_supplicant will fails to start until you reboot; with the setup in ExecStartPre it just works.
| "CAP_SYS_ADMIN" | ||
| "CAP_DAC_OVERRIDE" |
There was a problem hiding this comment.
Can we add a TODO to revisit those in the future?
There was a problem hiding this comment.
Now the daemon runs with full previleges again if enableHardening = false. I don't think we should try to make it more balanced: the setups that break under enableHardening are rare and complicated to reason about.
Doesn't work, in fact it triggered new kinds of errors I haven't seen before which also prevented wpa_supplicant from starting: Here is my own commit which properly disables the hardening changes and makes things work again: tazjin@4f18477 |
There's something strange going on here: the dbus interface is tested in <policy user="wpa_supplicant">
<allow own="fi.w1.wpa_supplicant1"/>
</policy>It looks like you're running not running wpa_supplicant with the right user, or did not apply unprivileged patch.
Well, this is problematic: the unprivileged patch moves the location of the socket dir, so |
80f8e04 to
fbeaf39
Compare
This would be fixed by also making the path in the config depending on the toggle, no? I don't use |
| }; | ||
|
|
||
| enableHardening = mkOption { | ||
| default = false; |
There was a problem hiding this comment.
don't forget to add a line that assigns this to true in nixos/modules/profiles/hardened.nix
There was a problem hiding this comment.
Actually this was a left-over from testing. It's supposed to be on by default.
This may be necessary for more complex enterprise networks (for example requiring access to mutable files, smart cards or TPM devices), as pointed out in NixOS#480355 (comment).
fbeaf39 to
4006a9b
Compare
|
Ok, I think I have a solution. It turns out the patch works regardless of which user the daemon is running as. The only thing that depends on the user is the dbus auto-start mechanism, however wpa_supplicant is a systemd service, so the So, I left I tested all |
|
@rnhmjoj Sorry for the delay, didn't get around to testing it during the week ... With your commit, the diff to my previous unit is minimal:
and the connection works, so from my perspective this resolves the issue. I'm fine with keeping the default enabled, people with these kinds of complex network setups will probably find the toggle. Code looks fine, and I support your explicit use of |
I don't think this should be a point of discussion here anyway, that code is unchanged and has just been moved around for this change. |
Does this mean that some things will run as root when activated via dbus? Maybe we should override the setting if |
No, the service runs with the correct user even when activated by dbus, because in this case dbus simply starts our systemd service. It would be a problem if it were to run the command specified in the dbus service file, but it's not the case.
Note that the file in question is a dbus service: it looks like a systemd unit file, but it's a different thing and can't be modified from NixOS. But in this case it doesn't matter. |

This may be necessary for more complex enterprise networks (for example requiring access to mutable files, smart cards or TPM devices), as pointed out in #480355 (comment).
Things done
passthru.tests.nixpkgs-reviewon this PR. See nixpkgs-review usage../result/bin/.