Skip to content

Commit 769cd31

Browse files
oratisclaude
andcommitted
chore(sandbox): slirp --userns-path to fix setns EPERM into bwrap netns
slirp4netns failed with setns(CLONE_NEWNET): Operation not permitted — bwrap's net namespace is owned by bwrap's child user namespace, which the host-user slirp process has no CAP_SYS_ADMIN over. Pass --userns-path=/proc/<pid>/ns/user so slirp enters that userns (where it is root) before the netns. resolv.conf bind now confirmed working. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent b290caa commit 769cd31

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

scripts/sandbox-net-poc.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ python3 --version || true
3636
say "bwrap help — fd handshake flags"
3737
bwrap --help 2>&1 | grep -iE "info-fd|block-fd|sync-fd|userns-block|unshare-net|--chdir" || true
3838

39-
say "slirp4netns help — config/ready/dns flags"
40-
slirp4netns --help 2>&1 | grep -iE "ready-fd|configure|disable-host-loopback|mtu|netns|--dns|outbound" || true
39+
say "slirp4netns help — config/ready/dns/userns flags"
40+
slirp4netns --help 2>&1 | grep -iE "ready-fd|configure|disable-host-loopback|mtu|netns|userns|--dns|outbound" || true
4141

4242
say "unprivileged port start (need <=53 to bind :53 rootless)"
4343
sysctl net.ipv4.ip_unprivileged_port_start 2>/dev/null || true
@@ -134,9 +134,13 @@ echo "child-pid=$CHILD_PID"
134134

135135
if [ -n "$CHILD_PID" ]; then
136136
say "start slirp4netns attached to child-pid=$CHILD_PID"
137+
# bwrap's netns is owned by bwrap's CHILD user namespace; slirp (host user)
138+
# can't setns into it without entering that userns first. --userns-path makes
139+
# slirp join /proc/<pid>/ns/user (where it's root) before the netns.
137140
# --disable-dns closes the 10.0.2.3 host-DNS bypass so ALL resolution must go
138141
# through our allowlisting proxy (guest resolv.conf points only at 10.0.2.2).
139-
slirp4netns --configure --disable-dns --mtu=65520 "$CHILD_PID" tap0 &
142+
slirp4netns --configure --disable-dns --mtu=65520 \
143+
--userns-path="/proc/$CHILD_PID/ns/user" "$CHILD_PID" tap0 &
140144
SLIRP_PID=$!
141145
echo "slirp pid=$SLIRP_PID (inner sleeps 3s to let it configure)"
142146
else

0 commit comments

Comments
 (0)