Files
w3cjandClaude Opus 5.5 e4b44b5994 fix(lima): limactl shell never starts a stopped VM past devvm's checks
In a terminal, limactl shell of a stopped VM asks whether to start it, yes by default (Lima 2.3.0, reproduced under a pty), and that start is Lima's own: no proxy or sandbox-exec profile (no QEMU wrapper on Linux), no pins, and no folderChanged, so the project folder's mount, by path on Linux's 9p, follows a link put at the path or makes a folder that's gone again. devvm opens a shell (Shell) and runs an agent's login (Exec) on the terminal after bringUp, so a guest that powered itself off between the two got that question. This is the start path the self-check's restart was suspected of: that restart goes through startOnce, but limactl shell didn't.

The limactl builder, which every limactl command of devvm's goes through, now gives limactl shell --start=false, which Lima has had since 2.0.0-rc.0 (devvm's oldest is 2.2): a stopped VM's shell or command fails at once ("instance is stopped"), without asking, and devvm's next launch starts it with every check. devvm limactl, which passes its arguments on as given, is unchanged.

TestShellNeverStarts checks Exec's, Shell's and the builder's limactl shell, and fails without the change; the lima package's and the CLI scripts' expected limactl shell calls name the flag, their negative patterns too, so none turns vacuous. Docs: How it works' Lima page's A stopped VM's shell; the changelog's Security hardening gets the line, its summary widened to cover both of its lines, and the release page its section.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-25 07:43:53 -07:00

392 lines
18 KiB
Plaintext

# The network tier for a new VM: the choice, the VM's proxy (devvm _proxy,
# started before the VM), the confined start, the self-check, and the
# VM's secrets as the proxy sees them.
# --network open: unconfined, with its proxy, which applies no
# rules but puts the VM's secrets in as every tier's does, with the VM's
# own CA and salt; its self-check asks the proxy through the VM's own
# settings, and no confined one runs.
project off
exec devvm --network open --no-git-protect
stdout '^==> creating_from image=base vm=devvm-off-[0-9a-f]{14}$'
vm_name OFF off
vm_state $OFF_dir/vm.json
stdout '^net\.tier=open$'
stdout '^net\.made\.proxy_key=[0-9a-f]{64}$'
stdout '^net\.made\.proxy_salt=[0-9a-f]{32}$'
! stdout 'net_check'
stub_calls
stdout 'curl -sSf -m 3 -o /dev/null --proxy "\$HTTPS_PROXY" http://devvm\.proxy/blocked'
! stdout 'noproxy'
! stdout 'sandbox-exec'
exists $OFF_dir/run/ca/ca.pem $OFF_dir/run/ca/next.key $OFF_dir/run/secrets.json
exec cat $OFF_dir/run/proxy.json
stdout '"open": true'
stdout '"ca": "\S+/run/ca/ca\.pem"'
stdout '"secrets": "\S+/run/secrets\.json"'
! stdout '"policies"|"builtin_policies"'
# --network allowlist: the VM's own CA and its next one, the keys the user's
# alone (kept out of Time Machine on macOS), the
# VM's proxy, then the VM started confined, its environment pointing at
# the proxy with the VM's key, then the self-check, the setup and the
# shell. (Its hostagent here: the test's runner, which runs on, so the
# proxy that follows it is still there for the checks below, however
# slowly they run.)
project net
stub_reset
exec sh -c 'echo $PPID > "$STUB_DIR/hostagent"'
exec devvm --network allowlist --no-git-protect
rm $STUB_DIR/hostagent
stdout '^==> starting what=devvm-net-[0-9a-f]{14}$'
vm_name NET net
exists $NET_dir/run/ca/ca.pem $NET_dir/run/ca/next.pem
exec ls -l $NET_dir/run/ca/ca.key $NET_dir/run/ca/next.key
stdout -count=2 '^-rw-------\S* '
exec ls -ld $NET_dir/run/ca
stdout '^drwx------\S* '
! exists $DATA/ca
vm_state $NET_dir/vm.json
stdout '^net\.tier=allowlist$'
stdout '^net\.made\.check=ok$'
stdout '^net\.made\.proxy_key=[0-9a-f]{64}$'
stdout '^net\.made\.proxy_salt=[0-9a-f]{32}$'
stdout '^ports\.host\.ssh=[0-9]+$'
stdout '^ports\.host\.proxy=[0-9]+$'
stub_calls
[darwin] stdout '^tmutil addexclusion \S*/data/devvm/vms/[0-9a-f]{14}/run/ca$'
[darwin] stdout '^limactl edit --tty=false devvm-net-[0-9a-f]{14} --set \.env = \{"HTTPS_PROXY":"http://devvm:devvm-proxy-password@192\.168\.5\.2:[0-9]+",.*"NODE_EXTRA_CA_CERTS":"/etc/ssl/devvm\.pem",.*"NO_PROXY":"localhost,127\.0\.0\.1,::1",.*\} --set \.propagateProxyEnv=false --set \.hostResolver\.enabled=false --set \.dns=\["127\.0\.0\.1"\]$'
[linux] stdout '^limactl edit --tty=false devvm-net-[0-9a-f]{14} --set \.env = \{"HTTPS_PROXY":"http://devvm:devvm-proxy-password@192\.168\.5\.4:3128",.*\} --set \.propagateProxyEnv=false --set \.hostResolver\.enabled=false --set \.dns=\["127\.0\.0\.1"\]$'
stdout '^limactl start --tty=false devvm-net-[0-9a-f]{14}\n(limactl list --json\n)*limactl shell --start=false --workdir / devvm-net-[0-9a-f]{14} sh -c .*/etc/ssh/ssh_host_.*\n(limactl list --json\n)*ssh -F none -M .*\nlimactl shell --start=false --workdir / devvm-net-[0-9a-f]{14} sh -c cd ''/'' && exec ''curl'' ''--noproxy'' ''\*'' ''-sS'' ''-m'' ''3'' ''-o'' ''/dev/null'' ''https://1\.1\.1\.1''\n'
stdout '^limactl shell --start=false --workdir /\S*/net devvm-net-[0-9a-f]{14}\n\z'
# The password is in no command's arguments: devvm wrote it into lima.yaml,
# the user's alone.
exec sh -c 'key=$(sed -n "s/^ *\"proxy_key\": \"\(.*\)\".*/\1/p" "$NET_dir/vm.json"); test -n "$key" && ! grep -qF "$key" "$STUB_LOG" && grep -qF "\"HTTPS_PROXY\":\"http://devvm:$key@" "$LIMA_HOME"/devvm-net-*/lima.yaml && ! grep -q devvm-proxy-password "$LIMA_HOME"/devvm-net-*/lima.yaml && ls -l "$LIMA_HOME"/devvm-net-*/lima.yaml'
stdout '^-rw-------\S* '
# macOS: the hostagent's profile lets it reach the proxy's port.
[darwin] exec sh -c 'grep -F "localhost:$(sed -n "s/^ *\"proxy\": \([0-9]*\).*/\1/p" "$NET_dir/vm.json")" "$NET_dir/run/sandbox.sb"'
# The proxy said it listens on that port, for that VM; its password is in
# its config, the user's alone, never in its arguments.
exec sh -c 'grep -F "listening on 127.0.0.1:$(sed -n "s/^ *\"proxy\": \([0-9]*\).*/\1/p" "$NET_dir/vm.json") for devvm-net-" "$NET_dir/logs/proxy.log"'
exec cat $NET_dir/run/proxy.json
stdout '^ "password": "[0-9a-f]{64}",$'
stdout '^ "version": 1,$'
exec ls -l $NET_dir/run/proxy.json
stdout '^-rw-------\S* '
exec sh -c 'ps -axww -o command= | grep "[_]proxy -config $NET_dir/run/proxy.json"'
stdout '_proxy -config \S*/run/proxy\.json$'
! stdout '[0-9a-f]{64}'
# Its child reads the VM's network, devvm _proxy-child -for the same config,
# its pid in the run folder beside how it's confined: on macOS, by Seatbelt,
# its check held; on Linux, by Landlock and its seccomp filter, as far as
# the kernel has them.
exec sh -c 'ps -ww -o command= -p "$(cat $NET_dir/run/proxy-child.pid)"'
stdout '_proxy-child -for \S*/run/proxy\.json$'
exec cat $NET_dir/run/proxy.confined
[darwin] stdout '^full seatbelt$'
[linux] stdout '^(full landlock|partial landlock landlock-[a-z0-9-]+)$'
# devvm-why with nothing blocked points at a tool that skipped the proxy.
exec sh -c 'pp=$(sed -n "s/^ *\"proxy\": \([0-9]*\).*/\1/p" "$NET_dir/vm.json"); key=$(sed -n "s/^ *\"proxy_key\": \"\(.*\)\".*/\1/p" "$NET_dir/vm.json"); /usr/bin/curl -sS -m 5 --proxy "http://devvm:[email protected]:$pp" http://devvm.proxy/blocked'
stdout '^devvm: nothing blocked recently$'
stdout 'skipped the proxy on a port or in a way devvm can''t send to it: turn on its own proxy setting'
stdout '/using/troubleshooting/#a-tool-that-skips-the-proxy-fails$'
# Transparent mode's ports: 80 and 443 first, then those the rules name, never 22.
exec sh -c 'pp=$(sed -n "s/^ *\"proxy\": \([0-9]*\).*/\1/p" "$NET_dir/vm.json"); key=$(sed -n "s/^ *\"proxy_key\": \"\(.*\)\".*/\1/p" "$NET_dir/vm.json"); /usr/bin/curl -sS -m 5 --proxy "http://devvm:[email protected]:$pp" http://devvm.proxy/transparent/ports'
stdout '\A80\n443\n'
! stdout '^22$'
exec cat $NET_dir/run/secrets.json
stdout '^\{"version":1,"bindings":\[\]\}$'
# The run log never holds the key.
exec sh -c 'cat "$DATA"/logs/runs/*.log'
stdout 'devvm:<password>@'
! stdout 'devvm-proxy-password'
! stdout 'devvm:[0-9a-f]{64}@'
# A VM devvm started confined that still reaches the internet directly:
# stopped, no setup, no shell.
project leak
stub_reset
exec sh -c ': > "$STUB_DIR/net-direct"'
! exec devvm --network allowlist --no-git-protect
stderr '^devvm: net_direct_route vm=devvm-leak-[0-9a-f]{14}$'
stub_calls
stdout '^limactl stop devvm-leak-[0-9a-f]{14}$'
! stdout 'tar -xf'
! stdout 'limactl shell --start=false --workdir /\S*/leak'
vm_name LEAK leak
vm_state $LEAK_dir/vm.json
stdout '^net\.made\.check=unenforced$'
rm $STUB_DIR/net-direct
# A running VM whose proxy is gone and can't start again (another program
# took its port) is stopped, never left running without it.
cd $WORK/net
exec sh -c 'sed -n "s/^ *\"proxy\": \([0-9]*\).*/\1/p" "$NET_dir/vm.json" > "$WORK/squat.port"; pkill -f -- "_proxy -config $NET_dir/run/proxy.json"; true'
wait_until '! nc -z 127.0.0.1 "$(cat "$WORK/squat.port")"'
exec sh -c 'printf "{\"version\": 1, \"listen\": \"127.0.0.1:%s\", \"password\": \"k\", \"lifeline\": \"%s\"}\n" "$(cat "$WORK/squat.port")" "$WORK/squat.none" > "$WORK/squat.json"; chmod 600 "$WORK/squat.json"; devvm _proxy -config "$WORK/squat.json" >/dev/null 2>&1 & echo $! > "$WORK/squat.pid"'
wait_until 'nc -z 127.0.0.1 "$(cat "$WORK/squat.port")"'
stub_reset
! exec devvm
stderr '^devvm: net_proxy_down_stopped vm=devvm-net-[0-9a-f]{14}$'
stderr '^devvm: proxy_port_taken port=[0-9]+ vm=devvm-net-[0-9a-f]{14}$'
stub_calls
stdout '^limactl stop devvm-net-[0-9a-f]{14}$'
! stdout 'limactl shell --start=false --workdir /\S*/net'
exec sh -c 'kill "$(cat "$WORK/squat.pid")"'
# Secrets: claude comes with Claude Code. The proxy gets its binding, with
# the VM's own placeholder and never the token, and its host on 443, and
# the OAuth login's binding, which gets the same token, and its binding for
# claude.ai's connectors, below mcp-proxy.anthropic.com's /v1/mcp/, which
# never gets a token in the login's place.
project agent
env CLAUDE_CODE_OAUTH_TOKEN=sk-ant-oat01-testfake
exec devvm --network allowlist --no-git-protect --agents claude
vm_name AGENT agent
exec cat $AGENT_dir/run/secrets.json
stdout '^\{"version":1,"bindings":\[\{"name":"claude","kind":"secret","hosts":\["api\.anthropic\.com"\],"header":"Authorization","placeholder":"sk-ant-oat01-devvm-proxy-managed-[0-9a-f]{32}"\},\{"name":"claude-oauth","kind":"login","agent":"claude-oauth","hosts":\["api\.anthropic\.com"\],"header":"Authorization","placeholder":"sk-ant-oat01-devvm-proxy-managed-oauth-[0-9a-f]{32}"\},\{"name":"claude-connectors","kind":"login","agent":"claude-oauth","hosts":\["mcp-proxy\.anthropic\.com"\],"path":"/v1/mcp/","header":"Authorization","placeholder":"sk-ant-oat01-devvm-proxy-managed-oauth-[0-9a-f]{32}"\}\]\}$'
! stdout testfake
exec sh -c 'salt=$(sed -n "s/^ *\"proxy_salt\": \"\(.*\)\".*/\1/p" "$AGENT_dir/vm.json"); test -n "$salt" && grep -F "$salt" "$AGENT_dir/run/secrets.json"'
exec cat $AGENT_dir/run/secrets.policy
stdout '^api\.anthropic\.com:443$'
stdout '^mcp-proxy\.anthropic\.com:443$'
# Its proxy's policies: base's and claude's built in, read from the
# binary, then the files: the user's, the VM's own and its secrets' hosts.
exec cat $AGENT_dir/run/proxy.json
stdout '"builtin_policies": \[\n "layers/base\.policy",\n "shared-tools/claude\.policy"\n \],\n "policies": \[\n "\S*/config/devvm/policy",\n "\S*/data/devvm/vms/[0-9a-f]{14}/policy",\n "\S*/data/devvm/vms/[0-9a-f]{14}/run/secrets\.policy"\n \],'
! exists $XDG_DATA_HOME/devvm/assets
# Each VM has CAs of its own: its proxy signs with its own, and no other
# VM has them.
exec sh -c 'grep -Fx " \"ca\": \"$AGENT_dir/run/ca/ca.pem\"," "$AGENT_dir/run/proxy.json" && grep -Fx " \"ca_next_key\": \"$AGENT_dir/run/ca/next.key\"," "$AGENT_dir/run/proxy.json"'
! cmp $AGENT_dir/run/ca/ca.pem $NET_dir/run/ca/ca.pem
! cmp $AGENT_dir/run/ca/next.pem $NET_dir/run/ca/next.pem
env CLAUDE_CODE_OAUTH_TOKEN=
# A Codex login in devvm's store: its bindings and hosts, with the VM's
# placeholders.
mkdir $HOME/.codex
cp $WORK/codex.json $HOME/.codex/auth.json
exec devvm agent import codex
project codex
exec devvm --network allowlist --no-git-protect --agents codex
vm_name CODEX codex
exec cat $CODEX_dir/run/secrets.json
stdout '"name":"codex-key","kind":"login","agent":"codex","hosts":\["api\.openai\.com"\]'
! stdout sk-testfake
exec cat $CODEX_dir/run/secrets.policy
stdout '^api\.openai\.com:443$'
# devvm network: the VM's tier, or unenforced, as devvm ls shows it. A
# tier changes the VM's state, applied when it next starts.
project none
! exec devvm network
stderr '^devvm: no_vm dir=\S*/none$'
! exec devvm network sideways
stderr '^devvm: arg_not_choice choices=open, internet, learn, allowlist, none command=devvm network given=sideways$'
! exec devvm network on
stderr '^devvm: arg_not_choice choices=open, internet, learn, allowlist, none command=devvm network given=on$'
cd $WORK/off
exec devvm network
stdout '^open$'
exec devvm network allowlist
stdout '^==> next_start count=1 vm=devvm-off-[0-9a-f]{14}$'
! stderr .
vm_state $OFF_dir/vm.json
stdout '^net\.tier=allowlist$'
exec devvm network allowlist
stdout '^==> setting_already command=devvm network allowlist vm=devvm-off-[0-9a-f]{14}$'
! stderr .
# Running, but not started confined: unenforced until devvm restart.
exec devvm network
stdout '^unenforced$'
exec devvm network open
stdout '^==> next_start count=1 vm=devvm-off-[0-9a-f]{14}$'
! stderr .
# Stopped, it changes at its next start.
exec limactl stop $OFF
exec devvm network allowlist
stdout '^==> setting_set vm=devvm-off-[0-9a-f]{14}$'
exec devvm network
stdout '^allowlist$'
# Without a flag, and without a terminal to ask in: allowlist, unasked.
project default
exec devvm --no-git-protect
stdout '^==> creating_from image=base vm=devvm-default-[0-9a-f]{14}$'
! stderr net_off_
vm_name DEFAULT default
vm_state $DEFAULT_dir/vm.json
stdout '^net\.tier=allowlist$'
stdout '^net\.made\.check=ok$'
# In a terminal, without customizing the VM, its summary shows allowlist
# and nothing asks for the tier. Customizing it shows the tier's picker
# after the agents of the first run and the parts' picker, allowlist on:
# k k moves up past learn to internet, and Enter makes it the VM's, which
# doesn't learn. The pickers show
# with a terminal on stdout too, which a test build's DEVVM_PICK_ON_PIPE
# stands in for.
env DEVVM_PICK_ON_PIPE=1
project shown
exec devvm setup --agents none
ttyin -stdin $WORK/enter.txt
exec devvm --no-git-protect
stdout '^new_vm_network tier=allowlist$'
! stdout net_tier_help
vm_name SHOWN shown
vm_state $SHOWN_dir/vm.json
stdout '^net\.tier=allowlist$'
project asked
ttyin -stdin $WORK/tiers.txt
exec devvm --no-git-protect
stdout 'net_tier_help vm=devvm-asked-[0-9a-f]{14}\r$'
vm_name ASKED asked
vm_state $ASKED_dir/vm.json
stdout '^net\.tier=internet$'
! stdout learning
# --network: the tier, unasked, the rest still customized.
project flagged
ttyin -stdin $WORK/enter.txt
exec devvm --network none --no-git-protect
stderr new_vm_customize
! stdout net_tier_help
env DEVVM_PICK_ON_PIPE=
vm_name FLAGGED flagged
vm_state $FLAGGED_dir/vm.json
stdout '^net\.tier=none$'
# A value that isn't a tier is a usage error, before anything is made.
project badflag
stub_reset
! exec devvm --network on --no-git-protect
stderr '^devvm: arg_not_choice choices=open, internet, learn, allowlist, none command=--network given=on$'
stderr '^usage_help command=devvm$'
! stub_calls
cd $WORK
# devvm network -g: what new VMs get, allowlist until it's saved, and
# only ever a tier.
exec devvm network -g
stdout '\Aallowlist # devvm: default\n\z'
! grep network $DATA/settings.json
exec devvm network -g --json
stdout '\A{\n "version": 1,\n "policy": "allowlist",\n "source": "built-in"\n}\n\z'
! exec devvm network -g ask
stderr '^devvm: arg_not_choice choices=open, internet, learn, allowlist, none command=devvm network given=ask$'
! exec devvm network -g sideways
stderr '^devvm: arg_not_choice choices=open, internet, learn, allowlist, none command=devvm network given=sideways$'
# A saved open: new VMs are open, unasked and unwarned; --network
# allowlist beats it. The VMs that exist keep theirs.
exec devvm network -g open
stdout '^==> network_default mode=open$'
grep '^ "network": "open",?$' $DATA/settings.json
exec devvm network -g
stdout '\Aopen # devvm: settings\.json\n\z'
exec devvm network -g --json
stdout '\A{\n "version": 1,\n "policy": "open",\n "source": "settings.json"\n}\n\z'
project offsaved
exec devvm --no-git-protect
! stderr net_off_
vm_name OFFSAVED offsaved
vm_state $OFFSAVED_dir/vm.json
stdout '^net\.tier=open$'
project offflag
exec devvm --network allowlist --no-git-protect
vm_name OFFFLAG offflag
vm_state $OFFFLAG_dir/vm.json
stdout '^net\.tier=allowlist$'
cd $WORK/default
exec limactl stop $DEFAULT
exec devvm
vm_state $DEFAULT_dir/vm.json
stdout '^net\.tier=allowlist$'
stdout '^net\.made\.check=ok$'
# Turned open, its next start starts it open, its proxy too, as open's,
# with the same CAs, which it keeps on allowlist again.
cp $DEFAULT_dir/run/ca/ca.pem $WORK/default-ca.pem
exec devvm network open
exec limactl stop $DEFAULT
exec devvm
cmp $DEFAULT_dir/run/ca/ca.pem $WORK/default-ca.pem
exec cat $DEFAULT_dir/run/proxy.json
stdout '"open": true'
stdout '"ca": "\S+/run/ca/ca\.pem"'
exec devvm network allowlist
exec limactl stop $DEFAULT
exec devvm
cmp $DEFAULT_dir/run/ca/ca.pem $WORK/default-ca.pem
# A saved allowlist: new VMs get it; --network open beats it.
exec devvm network -g allowlist
stdout '^==> network_default mode=allowlist$'
project onsaved
exec devvm --no-git-protect
! stderr net_off_
vm_name ONSAVED onsaved
vm_state $ONSAVED_dir/vm.json
stdout '^net\.tier=allowlist$'
project onflag
exec devvm --network open --no-git-protect
vm_name ONFLAG onflag
vm_state $ONFLAG_dir/vm.json
stdout '^net\.tier=open$'
# A saved none. config.toml's network wins over what devvm saved, devvm
# network -g shows it came from there, and devvm network -g refuses to
# change it, naming the file and the key.
exec devvm network -g none
stdout '^==> network_default mode=none$'
grep '^ "network": "none",?$' $DATA/settings.json
cp $WORK/config-on.toml $CFG/config.toml
exec devvm network -g
stdout '\Aallowlist # \S*/config/devvm/config\.toml\n\z'
exec devvm network -g --json
stdout '"source": "config.toml"'
! exec devvm network -g open
stderr '^devvm: set_in_config file=\S*/config/devvm/config\.toml key=network$'
grep '^ "network": "none",?$' $DATA/settings.json
project configon
exec devvm --no-git-protect
! stderr net_off_
vm_name CONFIGON configon
vm_state $CONFIGON_dir/vm.json
stdout '^net\.tier=allowlist$'
# A config.toml edited by hand with a typo: every command that reads it is
# refused, naming the file and the line, with a flag or without.
cp $WORK/config-typo.toml $CFG/config.toml
! exec devvm network -g
stderr '^devvm: net_default_failed reason=\S*/config/devvm/config\.toml:2: unknown key "netwrk"$'
project badsaved
! exec devvm --no-git-protect
stderr '\S*/config/devvm/config\.toml:2: '
! exec devvm --network allowlist --no-git-protect
stderr '\S*/config/devvm/config\.toml:2: '
cp $WORK/config-maybe.toml $CFG/config.toml
! exec devvm network -g
stderr '^devvm: net_default_failed reason=\S*/config/devvm/config\.toml:1: "maybe" isn''t one of open, internet, allowlist, none$'
rm $CFG/config.toml
exec devvm --network allowlist --no-git-protect
-- config-on.toml --
# new VMs get the allowlist, whatever devvm network -g says
network = "allowlist"
-- config-typo.toml --
# a typo
netwrk = "open"
-- config-maybe.toml --
network = "maybe"
-- enter.txt --
-- tiers.txt --
y
kk
-- codex.json --
{"OPENAI_API_KEY":"sk-testfake-codex","last_refresh":null}