Files
devvm/testdata/script/network_transparent.txtar
w3cjandClaude Opus 5.5 63bb1ff9a8 fix(network): a confined VM's programs ask 127.0.0.1 directly, so names fail at once
With transparent mode off or stopped, a confined VM's only name server,
127.0.0.1 (Lima's DNS setting), has nothing listening. glibc asked it
through systemd-resolved's stub, which could keep retrying it over UDP
and TCP without answering, so a lookup such as getent's waited out its
timeout instead of failing at once (seen on a Linux host: e2e network's
checks of DNS with transparent mode stopped and off).

Each launch's setup now replaces /etc/resolv.conf, the stub's link, with
devvm's own file on a confined VM: nameserver 127.0.0.1 alone, the stub's
search line, timeout:1 attempts:2. glibc gets a refusal at once with
nothing listening, and dnsmasq's answer through transparent mode's
nftables rule when it runs, as musl on Alpine does. An open VM gets the
stub's link back. Only systemd guests that have the stub's file and whose
/etc/resolv.conf is its link or devvm's own are touched.

Root cause, as far as it could be pinned down: with resolved's stub in
the path, a lookup depended on resolved's retry loop over a server that
refuses everything (24 attempts, flipping UDP and TCP feature levels),
and on the linux host that loop sometimes never answered the stub
within getent's 3 s. It didn't reproduce on demand (a base run on the
linux host passed both checks, and bursts of 200 parallel lookups and
stops mid-lookup all failed in under 2 s), so the fix takes resolved out
of glibc's path rather than tuning it.

Going back to open restarts systemd-resolved: it reads a /etc/resolv.conf
that isn't its own link as global servers and search domains, so it had
taken 127.0.0.1 and "~." from devvm's file, and kept them once the link
was back, which left an open VM unable to resolve names (caught by e2e
network's open checks on the linux host and ubuntu).

Review folded in: no change of a foreign or dangling link when the stub's
file is missing; two attempts; Docker's user-defined networks in the docs.
Second review: devvm's file alone is enough to go back on an open VM (a
warning when the stub's file is missing); a failed write says so in one
line and the launch goes on; troubleshooting's "An open VM resolves no
names after a downgrade"; tests for resolved's own resolv.conf link, an
open VM without the stub, a non-systemd guest with devvm's file and a
failed write.

workerd under wrangler dev, checked by hand on fedora with transparent
mode off: its fetch fails at once (Temporary failure in name resolution),
so the "about 40 seconds for each lookup" sentence is gone from lima.md,
safety/network.md and troubleshooting.md, and testing.md's manual check
covers it.

testdata/coverage/darwin.txt: internal/sshagent's baseline rose with
mise run coverage (unrelated to this change).

- backend.Confinement.Resolver: the one owner of a confined guest's name
  server; Lima's start sets .dns from it, sync.go sends it to the setup
  as DEVVM_RESOLVER; sync.go's setupInputs as mise run fmt writes it.
- assets/guest/sync.sh: resolver_conf; its unit test runs the function
  (internal/vm/resolver_test.go). sync.sh runs at each launch and goes in
  no image, so no image key changes.
- CLI tests: DEVVM_RESOLVER on confined (transparent on and off) and open
  VMs. e2e network: the stopped-transparent check also checks the file.
- Docs: network.md's The VM's resolver, lima.md, design.md, tests.md;
  CHANGELOG Fixed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 22:04:32 -07:00

96 lines
3.5 KiB
Plaintext

# devvm network transparent: shows a folder's VM's transparent mode and
# where it comes from (its own, config.toml's transparent-proxy, or the
# default, on), and gives the VM its own. A launch's setup gets the
# stand-in address while the VM runs confined and its mode is on, and none
# on an open VM. config.toml's value must be true or false, and a word
# that isn't on or off is a usage error.
# No VM yet; a bad word changes nothing.
project web
! exec devvm network transparent
stderr '^devvm: no_vm dir=\S*/web$'
! exec devvm network transparent maybe
stderr '^devvm: arg_not_choice choices=on, off command=devvm network transparent given=maybe$'
# A confined VM: on by default, and its setup gets the stand-in address
# and the proxy's reserved target. (Its hostagent: the test's runner, so
# its proxy lasts through the launches below.)
exec sh -c 'echo $PPID > "$STUB_DIR/hostagent"'
exec devvm --network allowlist --no-git-protect
vm_name WEB web
exec devvm network transparent
stdout '\Aon # devvm: default\n\z'
exec devvm network transparent --json
stdout '"on": true'
stdout '"from": "default"'
exec tar -xOf $STUB_DIR/sync.tar vm
stdout '^DEVVM_TRANSPARENT_ADDR=''198\.18\.0\.1''$'
stdout '^DEVVM_TRANSPARENT_HOST=''transparent\.devvm\.proxy''$'
stdout '^DEVVM_RESOLVER=''127\.0\.0\.1''$'
exec devvm network --json
stdout '"transparent": \{\n *"on": true,\n *"from": "default"\n *\}'
vm_state $WEB_dir/vm.json
! stdout '^net\.transparent='
! exec devvm network transparent --json off
stderr '^devvm: json_shows_only command=devvm network transparent$'
# config.toml turns it off for every VM, from the next launch; the VM's
# programs still ask its one name server directly, so names fail at once.
cp $WORK/off.toml $CFG/config.toml
exec devvm network transparent
stdout '\Aoff # \S*/config/devvm/config\.toml\n\z'
exec devvm network transparent --json
stdout '"from": "config"'
exec devvm
exec tar -xOf $STUB_DIR/sync.tar vm
stdout '^DEVVM_TRANSPARENT_ADDR=''''$'
stdout '^DEVVM_RESOLVER=''127\.0\.0\.1''$'
# The VM's own setting comes first, from its next launch; the same again
# changes nothing.
exec devvm network transparent on
stdout '^==> net_transparent_set mode=on vm=devvm-web-[0-9a-f]{14}$'
vm_state $WEB_dir/vm.json
stdout '^net\.transparent=on$'
exec devvm network transparent
stdout '\Aon # devvm network transparent\n\z'
exec devvm network transparent on
stdout '^==> setting_already command=devvm network transparent on vm=devvm-web-[0-9a-f]{14}$'
exec devvm
exec tar -xOf $STUB_DIR/sync.tar vm
stdout '^DEVVM_TRANSPARENT_ADDR=''198\.18\.0\.1''$'
exec devvm network transparent off
stdout '^==> net_transparent_set mode=off vm=devvm-web-[0-9a-f]{14}$'
exec devvm
exec tar -xOf $STUB_DIR/sync.tar vm
stdout '^DEVVM_TRANSPARENT_ADDR=''''$'
exec devvm network transparent --json
stdout '"on": false'
stdout '"from": "vm"'
# An open VM: none, whatever its setting, and the system's own resolver.
rm $STUB_DIR/hostagent
rm $CFG/config.toml
project open
exec devvm --network open --no-git-protect
exec tar -xOf $STUB_DIR/sync.tar vm
stdout '^DEVVM_TRANSPARENT_ADDR=''''$'
stdout '^DEVVM_RESOLVER=''''$'
# A value that isn't true or false, for a VM without its own: the command
# fails, naming the line.
cp $WORK/bad.toml $CFG/config.toml
! exec devvm network transparent
stderr '^devvm: net_transparent_failed reason=\S*/config/devvm/config\.toml:2: '
rm $CFG/config.toml
exec devvm network transparent on
exec devvm
exec tar -xOf $STUB_DIR/sync.tar vm
stdout '^DEVVM_TRANSPARENT_ADDR=''''$'
-- off.toml --
transparent-proxy = false
-- bad.toml --
# transparent mode
transparent-proxy = "no"