-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
/nix/store is writable in a nix-shell started by root #4337
Comments
@regnat writes:
|
Note that it only happens because nix bypasses the daemon by default when running as root (see #4263). A workaround is to set $ sudo nix-shell -p mount --run mount | grep store
znvme/nix on /nix/store type zfs (rw,relatime,xattr,noacl)
$ sudo NIX_REMOTE=daemon nix-shell -p mount --run mount | grep store
znvme/nix on /nix/store type zfs (ro,relatime,xattr,noacl) |
This is clearly not desirable, as it is astonishing. The root user should be able to launch a Nix shell without unknowingly winding up with a writable Nix store. |
Somehow I was under the impression that this would affect the mount namespace outside the nix-shell, but this is not the case with more testing. I have updated the description. |
|
I marked this as stale due to inactivity. → More info |
This ensures any started processes can't write to /nix/store (except during builds). This partially reverts 01d07b1, which happened because of NixOS#2646. The problem was only happening after nix downloads anything, causing me to suspect the download thread. The problem turns out to be: "A process can't join a new mount namespace if it is sharing filesystem-related attributes with another process", in this case this process is the curl thread. Ideally, we might kill it before spawning the shell process, but it's inside a static variable in the getFileTransfer() function. So instead, stop it from sharing FS state using unshare(). A strategy such as the one from NixOS#5057 (single-threaded chroot helper binary) is also very much on the table. Fixes NixOS#4337.
Describe the bug
/nix/store
is read-write in a nix-shell started by root.Steps To Reproduce
Expected behavior
/nix/store
should stay read-only.nix-env --version
outputThe machine above is running unstable with
nix-env (Nix) 2.4pre20201201_5a6ddb3
.Also reproduced on a 20.09 machine with
nix-env (Nix) 2.3.9
.Additional context
The behavior is not related to ZFS, and I was able to reproduce it on a machine with single-partition ext4.
Edit: Somehow I was under the impression that this would affect the mount namespace outside the nix-shell, but this is not the case with more testing. I have updated the description.
The text was updated successfully, but these errors were encountered: