Skip to content

Commit b290caa

Browse files
oratisclaude
andcommitted
chore(sandbox): fix resolv.conf bind (dangling symlink) + --disable-dns
bwrap couldn't bind our resolv.conf onto /etc/resolv.conf because on the runner it's a dangling symlink (→ /run/systemd/resolve/stub-resolv.conf, not mounted in the sandbox). Bind our file at the readlink-resolved real path so the preserved symlink leads to it. Add slirp4netns --disable-dns to close the 10.0.2.3 bypass (all resolution must traverse our allowlist). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent d226f1d commit b290caa

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

scripts/sandbox-net-poc.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ CWD="$WORK/cwd"; mkdir -p "$CWD"
4949
echo "nameserver 10.0.2.2" > "$WORK/resolv.conf" # slirp gateway → host loopback
5050
echo "WORK=$WORK"
5151

52+
# /etc/resolv.conf is usually a dangling symlink (→ /run/systemd/resolve/...)
53+
# which bwrap can't create a bind target for. Bind our file at the symlink's
54+
# RESOLVED real path so the preserved /etc/resolv.conf symlink leads to it.
55+
say "resolv.conf shape on host"
56+
ls -l /etc/resolv.conf || true
57+
RP="$(readlink -f /etc/resolv.conf 2>/dev/null || true)"
58+
[ -n "$RP" ] || RP=/etc/resolv.conf
59+
echo "resolv real path RP=$RP"
60+
5261
# ── allowlisting DNS proxy on host 127.0.0.1:53 (allow example.com only) ──────
5362
say "start allowlist DNS proxy on 127.0.0.1:53"
5463
cat > "$WORK/dns.py" <<'PY'
@@ -104,7 +113,7 @@ bwrap \
104113
--ro-bind-try /usr /usr --ro-bind-try /lib /lib --ro-bind-try /lib64 /lib64 \
105114
--ro-bind-try /bin /bin --ro-bind-try /sbin /sbin --ro-bind-try /etc /etc \
106115
--proc /proc --dev /dev --tmpfs /tmp \
107-
--ro-bind "$WORK/resolv.conf" /etc/resolv.conf \
116+
--ro-bind "$WORK/resolv.conf" "$RP" \
108117
--bind "$CWD" "$CWD" \
109118
--unshare-net --unshare-pid --unshare-ipc --unshare-uts \
110119
--new-session --die-with-parent \
@@ -125,7 +134,9 @@ echo "child-pid=$CHILD_PID"
125134

126135
if [ -n "$CHILD_PID" ]; then
127136
say "start slirp4netns attached to child-pid=$CHILD_PID"
128-
slirp4netns --configure --mtu=65520 "$CHILD_PID" tap0 &
137+
# --disable-dns closes the 10.0.2.3 host-DNS bypass so ALL resolution must go
138+
# through our allowlisting proxy (guest resolv.conf points only at 10.0.2.2).
139+
slirp4netns --configure --disable-dns --mtu=65520 "$CHILD_PID" tap0 &
129140
SLIRP_PID=$!
130141
echo "slirp pid=$SLIRP_PID (inner sleeps 3s to let it configure)"
131142
else

0 commit comments

Comments
 (0)