Skip to content

libstore: fix auto-allocate-uids for non-sandboxed builds#15822

Open
KiaraGrouwstra wants to merge 1 commit into
NixOS:masterfrom
KiaraGrouwstra:uids-unsandboxed-user
Open

libstore: fix auto-allocate-uids for non-sandboxed builds#15822
KiaraGrouwstra wants to merge 1 commit into
NixOS:masterfrom
KiaraGrouwstra:uids-unsandboxed-user

Conversation

@KiaraGrouwstra
Copy link
Copy Markdown
Contributor

Motivation

Allow unsandboxed builds using auto-allocate-uids to fall back to nixbld users.

Closes #9761.

Context

Where 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.

Disclaimer: I used a coding agent in the creation of this patch.

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Derivations Built Without Sandbox Do Not Use a Valid User

1 participant