libstore: fix auto-allocate-uids for non-sandboxed builds#15822
libstore: fix auto-allocate-uids for non-sandboxed builds#15822KiaraGrouwstra wants to merge 1 commit into
auto-allocate-uids for non-sandboxed builds#15822Conversation
…locate-uids` builds When `auto-allocate-uids` is enabled, builds that cannot be sandboxed (e.g. derivations with `__noChroot = true`, or with `sandbox = false`) were `setuid`'d to an auto-allocated UID with no entry in the host's `/etc/passwd`. `/etc/passwd` is only fabricated inside the chroot, so outside the user namespace `whoami`, `getpwuid()`, `podman` and `ssh` all fail, breaking nixpkgs packages like `spago-legacy`, `generic-stack-builder` and `xcodeenv`. Auto-allocated UIDs only make sense inside a user namespace where Nix controls `/etc/passwd`. For non-sandboxed builds, fall back to a real `nixbld` user via `build-users-group` if one is configured; otherwise fail with a clear error pointing at sandboxing or `build-users-group` rather than silently running as an unknown UID. Assisted-by: Claude:claude-opus-4-7
|
Should we just fail unconditionally? That would make much more sense. |
|
@xokdvium conceptually, i would then regard the |
|
I might be misunderstanding, but the whole purpose of the feature is to not have the explicitly configured users at all. You can happen to have some stale users from prior install, but I'd imagine new installs that only do auto-allocate-uids wouldn't have it. Also, if somebody wants to use unsandboxed builds they probably shouldn't be running auto-allocate-UIDs in the first place – those would be fully incompatible features. |
nixpkgs has like a dozen packages that opted out of the sandbox. |
Hm, I don't really get what you mean? Enabling/disabling the feature doesn't interact with the feature itself being stable. Disabling the sandbox isn't a default configuration too. Btw, another curious avenue to have
I wonder if it would be possible to only enter a userns (provided by nsresourced), while bypassing mount namespaces. Would that work in the scenario you had in mind? |
Motivation
Allow unsandboxed builds using
auto-allocate-uidsto fall back tonixbldusers.Closes #9761.
Context
Where
auto-allocate-uidsis enabled, builds that cannot be sandboxed (e.g. derivations with__noChroot = true, or withsandbox = false) weresetuid'd to an auto-allocated UID with no entry in the host's/etc/passwd./etc/passwdis only fabricated inside the chroot, so outside the user namespacewhoami,getpwuid(),podmanandsshall fail, breaking nixpkgs packages likespago-legacy,generic-stack-builderandxcodeenv.Auto-allocated UIDs only make sense inside a user namespace where Nix controls
/etc/passwd. For non-sandboxed builds, fall back to a realnixblduser viabuild-users-groupif one is configured; otherwise fail with a clear error pointing at sandboxing orbuild-users-grouprather than silently running as an unknown UID.Disclaimer: I used a coding agent in the creation of this patch.