git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #95444 from doronbehar/fix/mount+s

nixos/wrappers: make mount have the +s bit.

commit609eb86db707c836564d42c88f531bb774db64a9 authorFlorian Klink <flokli@flokli.de> dateSun 16 Aug 2020, 12:23 (6 years ago) parentd4203692519e54
2 files changed+35
nixos/modules/security/wrappers/default.nix+3 nixos/tests/misc.nix+32
nixos/modules/security/wrappers/default.nix+3
@@ -160,8 +160,11 @@ in
160160 config = {
161161
162162 security.wrappers = {
163+ # These are mount related wrappers that require the +s permission.
163164 fusermount.source = "${pkgs.fuse}/bin/fusermount";
164165 fusermount3.source = "${pkgs.fuse3}/bin/fusermount3";
166+ mount.source = "${lib.getBin pkgs.utillinux}/bin/mount";
167+ umount.source = "${lib.getBin pkgs.utillinux}/bin/umount";
165168 };
166169
167170 boot.specialFileSystems.${parentWrapperDir} = {
nixos/tests/misc.nix+32
@@ -20,12 +20,24 @@ import ./make-test-python.nix ({ pkgs, ...} : rec {
2020 { fsType = "tmpfs";
2121 options = [ "mode=1777" "noauto" ];
2222 };
23+ # Tests https://discourse.nixos.org/t/how-to-make-a-derivations-executables-have-the-s-permission/8555
24+ "/user-mount/point" = {
25+ device = "/user-mount/source";
26+ fsType = "none";
27+ options = [ "bind" "rw" "user" "noauto" ];
28+ };
29+ "/user-mount/denied-point" = {
30+ device = "/user-mount/denied-source";
31+ fsType = "none";
32+ options = [ "bind" "rw" "noauto" ];
33+ };
2334 };
2435 systemd.automounts = singleton
2536 { wantedBy = [ "multi-user.target" ];
2637 where = "/tmp2";
2738 };
2839 users.users.sybil = { isNormalUser = true; group = "wheel"; };
40+ users.users.alice = { isNormalUser = true; };
2941 security.sudo = { enable = true; wheelNeedsPassword = false; };
3042 boot.kernel.sysctl."vm.swappiness" = 1;
3143 boot.kernelParams = [ "vsyscall=emulate" ];
@@ -112,6 +124,26 @@ import ./make-test-python.nix ({ pkgs, ...} : rec {
112124 machine.succeed("touch /tmp2/x")
113125 machine.succeed("grep '/tmp2 tmpfs' /proc/mounts")
114126
127+ with subtest(
128+ "Whether mounting by a user is possible with the `user` option in fstab (#95444)"
129+ ):
130+ machine.succeed("mkdir -p /user-mount/source")
131+ machine.succeed("touch /user-mount/source/file")
132+ machine.succeed("chmod -R a+Xr /user-mount/source")
133+ machine.succeed("mkdir /user-mount/point")
134+ machine.succeed("chown alice:users /user-mount/point")
135+ machine.succeed("su - alice -c 'mount /user-mount/point'")
136+ machine.succeed("su - alice -c 'ls /user-mount/point/file'")
137+ with subtest(
138+ "Whether mounting by a user is denied without the `user` option in fstab"
139+ ):
140+ machine.succeed("mkdir -p /user-mount/denied-source")
141+ machine.succeed("touch /user-mount/denied-source/file")
142+ machine.succeed("chmod -R a+Xr /user-mount/denied-source")
143+ machine.succeed("mkdir /user-mount/denied-point")
144+ machine.succeed("chown alice:users /user-mount/denied-point")
145+ machine.fail("su - alice -c 'mount /user-mount/denied-point'")
146+
115147 with subtest("shell-vars"):
116148 machine.succeed('[ -n "$NIX_PATH" ]')
117149