Repository navigation
Conversation
…oot() There is now one bootstrap, `init_userns()`, and the process always keeps its uid and gid. Services that check the caller's uid, such as the session D-Bus and PipeWire portals, work by default. Spawned commands keep CAP_NET_ADMIN, CAP_NET_RAW and CAP_NET_BIND_SERVICE as before in keep-uid mode. If the host has a subordinate id range for the user (newuidmap and newgidmap on PATH, /etc/subuid and /etc/subgid entries), uid and gid 0 map to the first subordinate id and the rest of the range to itself. `Device::root()` and `Router::root()` return an `AsRoot` handle whose `spawn_command` and `spawn_command_sync` run the child as uid 0. The patchbay process has CAP_SETUID in the namespace, so this needs no setuid binary. Without the range, root() spawns fail with an error that names the requirement. If newuidmap or newgidmap fails after the unshare, write the single-id maps instead of leaving the process without a mapping. The forked helper is reaped on every path. ## Breaking changes - `init_userns()` keeps the caller's uid instead of mapping it to 0. Commands that need uid 0 must be spawned through `root()`. - `init_userns_keep_uid()`, `init_userns_for_ctor()` and `init_userns_keep_uid_for_ctor()` are removed. Call `init_userns()`, also from a `#[ctor]`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
patchbay had two bootstraps.
init_userns()mapped the user to uid 0, which breaks services that check the caller's uid, such as the session D-Bus and PipeWire portals.init_userns_keep_uid()kept the uid, but then no command could run as root. A process had to pick one, and each had a libc-only_for_ctortwin.Approach
One bootstrap,
init_userns(). The process always keeps its uid and gid.If the host has a subordinate id range for the user (
newuidmap/newgidmaponPATH,/etc/subuidand/etc/subgidentries), the map is:Commands run as root through
Device::root()andRouter::root():root()returns anAsRoothandle withspawn_commandandspawn_command_sync. They set uid and gid 0 on the command. The patchbay process hasCAP_SETUIDin the namespace, so this needs no setuid binary. Without a subordinate range, root is not mapped, and these spawns fail with an error that names the requirement.Root is only for spawned commands. The patchbay process already has all capabilities in the namespace, and glibc applies
setuidto every thread, so an in-process "become root" would not be clean.If
newuidmapornewgidmapfails after the unshare, for example without its setuid bit, the bootstrap writes the single-id maps. Before, such a host was left in a namespace without a mapping, and every lab failed.Breaking changes
init_userns()keeps the caller's uid instead of mapping it to 0. Commands that need uid 0 must be spawned throughroot().init_userns_keep_uid(),init_userns_for_ctor()andinit_userns_keep_uid_for_ctor()are removed. Callinit_userns(), also from a#[ctor].patchbay-cliand the lib tests already do.Impact
podman unshare rmto remove them. The docs say to prefer running as the user./etc/subuid, there is no root. Labs work as before (nft, tc and ping use the ambient capabilities).sudocalls are inside the VM guest.Testing
tests/userns.rs: the uid maps to itself, 0 maps to the first subordinate id when a range exists,root()spawns run as uid 0 with all capabilities, plain spawns run as the user, androot()fails without a range.tests/userns_fallback.rs: runs its own binary with failingnewuidmap/newgidmapfirst onPATH, and checks that the bootstrap falls back and a lab works. Fails without the fallback.busctl --user statusandpw-cli info 0work from inside the namespace.The containers PR (#45) builds on this.
🤖 Generated with Claude Code