mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 21:36:40 -10:00
On every confined tier, a tool that ignores the proxy settings (workerd
under wrangler dev, a static Go binary, a container made through Docker's
API) reaches the VM's proxy by the names it looks up. In the VM, dnsmasq
answers every name with the stand-in address 198.18.0.1 and has no
upstream; nftables sends that address's ports 80, 443 and those the allow
rules name to socat listeners on it, which make each an authenticated
CONNECT transparent.devvm.proxy:PORT to the VM's proxy. The proxy reads the
host from the connection's first bytes (TLS SNI, or each HTTP request's
Host) and judges it as CONNECT host:PORT, with the same order of checks,
log, secrets and floor. A blocked HTTPS host gets the 403 over a
certificate from the VM's CA. Nothing new runs on the host, and the
backends don't change.
Proxy (internal/proxy):
- transparent.go: TransparentHost, ProxyDomain, SentinelAddr,
IsSentinelAddr, ViaDNS, transparent (serve, take, tls, handler,
refusePage, ports), sniHost, replay, reservedRefusal, withVia, viaOf.
- routeFor and route: the one order of checks for CONNECT and the
transparent path; carry, the one tunnel with its SNI check; block split
into the record and blockPage; links.refuse split (isLinkDomain);
caEndedRefusal's test moved to routeFor; handshake and serveOne shared
by intercept and the 403 page.
- devvm.proxy reserved whole, CONNECT devvm.proxy:P included; the stand-in
address refused with its own reason.
- Hosts and SNI in ASCII alone, never folded (the Kelvin sign), in
splitHostPort, sniMatches and sniHost.
- A ClientHello record past 16 KiB + 256 is never read; once it starts,
a ClientHello must arrive whole within 10 s, on every tunnel; a stream
whose first byte is 0x16 is TLS from then on, so a record header that
doesn't come whole, or isn't TLS's version, is refused, never passed on
unchecked; and only a ClientHello that parsed (sniOf) counts, so one
split across records is refused, an address's tunnel's included, which
may have no name (a gap older than this change).
- routeFor carries the method and path rules: a host they narrow is
refused where it can't be decrypted and intercepted where it can, on
the transparent path too.
- On the transparent HTTP path, devvm.proxy answers /blocked alone.
- policy.transparentPorts and /transparent/ports: 80, 443, then the ports
allow rules name for hosts by name, at most 32, never 22 or 53.
- Event.Via ("dns"), shown in devvm network log, /blocked and the prompt's
note as "without proxy settings".
Guest (assets/): base.sh installs dnsmasq(-base), socat and nftables;
guest/transparent.sh is devvm-transparent: setup and teardown from
sync.sh (the proxy URL on stdin), the supervisor service (systemd or
OpenRC), the ruleset (render: two filter chains at -150 keep every
interface but lo and Docker's bridges, and every protocol but TCP, UDP
and ICMP, off the stand-in address; both NAT chains at -110 map every port of
the stand-in address, so Docker's published ports never take one; DNS to
public servers and 127.0.0.1:53 go to dnsmasq, which listens on the
stand-in address alone; private, link-local, CGNAT and loopback servers
are left alone, but the VM's own name servers, which Lima's DHCP adds
beside 127.0.0.1 and Docker gives containers, go to dnsmasq too), slots,
the port list's check, and status for devvm-why. Names without a dot and
names under the search domains (this machine's network's, through Lima)
don't resolve.
Setting: config.toml's transparent-proxy, and devvm network transparent
[on|off], the VM's own value in net.transparent (Settings.Transparent,
SetTransparent; netpolicy.TransparentOf, TransparentAddr); the setup gets
DEVVM_TRANSPARENT_ADDR while the VM runs confined and its mode is on.
devvm network --json has transparent; devvm network lock lists apart the
hosts only tools without proxy settings reached (Learned.NoProxy, via in
--json). vmssh.dialAddr refuses the stand-in address.
Tests: the transparent path's unit tests and FuzzTransparent; the
setting, TransparentOf, FormatEvent's via and learned hosts; the ruleset,
slots and port list under bash 3.2; network_transparent.txtar and
sync.txtar; e2e: transparentRuns, the network section's checks, a docker
step, the from section's Debian 12 and Alpine on the allowlist tier, and
the guarantee checks run with transparent mode stopped and running.
Docs: safety/network.md (tools that ignore the proxy, what isn't
covered, the setting, logs, lock), internals/network.md (tools that skip
the proxy), internals/design.md (the design note and threat check),
using/settings.md, using/troubleshooting.md, using/limits.md,
using/images.md, safety/attack-vectors.md, internals/lima.md,
contributing/tests.md and testing.md, the proxy's README, the CLI
reference and the Commands page.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
189 lines
9.7 KiB
Plaintext
189 lines
9.7 KiB
Plaintext
# A VM's setup on every launch: the host's settings, its agents' settings
|
|
# and logins from devvm's store (never their history), their folders
|
|
# mounted read-only, and on every tier the VM's own CA and placeholders
|
|
# for its tokens and logins.
|
|
env TZ=Europe/Paris
|
|
env LANG=en_US.UTF-8
|
|
exec git config --global user.name 'Test User'
|
|
exec git config --global user.email [email protected]
|
|
|
|
# The agents' files in the home folder, and their history: a VM gets
|
|
# nothing of them before devvm agent import copies them into the store.
|
|
mkdir $HOME/.claude/skills $HOME/.claude/projects/p $HOME/.codex/prompts
|
|
cp $WORK/settings.json $HOME/.claude/settings.json
|
|
cp $WORK/claude.json $HOME/.claude.json
|
|
cp $WORK/codex.json $HOME/.codex/auth.json
|
|
cp $WORK/config.toml $HOME/.codex/config.toml
|
|
cp $WORK/history.jsonl $HOME/.claude/projects/p/history.jsonl
|
|
cp $WORK/history.jsonl $HOME/.codex/history.jsonl
|
|
project before
|
|
exec devvm --network open --no-git-protect --agents claude,codex
|
|
exec tar -tf $STUB_DIR/sync.tar
|
|
! stdout '^home/|^claude\.json$'
|
|
exec tar -xOf $STUB_DIR/sync.tar links
|
|
! stdout /home/
|
|
exec devvm agent import
|
|
! exists $CFG/agents/claude/.claude/projects
|
|
! exists $CFG/agents/codex/.codex/history.jsonl
|
|
|
|
# An open VM: the agents' folders in the store mounted read-only, and as
|
|
# on every tier, the VM's own CA, its tokens' and logins' placeholders,
|
|
# and the settings files with their keys taken out. It holds no real
|
|
# secret.
|
|
project plain
|
|
env CLAUDE_CODE_OAUTH_TOKEN=sk-ant-oat01-testfake
|
|
exec devvm --network open --no-git-protect --agents claude,codex
|
|
stderr '^config_redacted file=\S*/agents/claude/\.claude/settings\.json keys=env\.ANTHROPIC_API_KEY vm=devvm-plain-[0-9a-f]{14}$'
|
|
stderr '^devvm: config_not_copied file=\S*/agents/codex/\.codex/config\.toml vm=devvm-plain-[0-9a-f]{14}$'
|
|
stub_calls
|
|
stdout '^limactl clone --tty=false \S+ devvm-plain-[0-9a-f]{14} --mount-none --set \.mounts = \[\{"location":"\S*/plain","writable":true(,"9p":\{"cache":"none"\})?\},\{"location":"\S*/config/devvm/agents/claude/\.claude/skills","writable":false\},\{"location":"\S*/config/devvm/agents/codex/\.codex/prompts","writable":false\},\{"location":"\S*/data/devvm/tools","mountPoint":"/mnt/devvm-tools","writable":false\}\]'
|
|
exec tar -tf $STUB_DIR/sync.tar
|
|
stdout '^home/\.claude/settings\.json$'
|
|
stdout '^home/\.codex/auth\.json$'
|
|
! stdout '^home/\.codex/config\.toml$'
|
|
stdout '^claude\.json$'
|
|
stdout '^ca/devvm-proxy\.crt$'
|
|
stdout '^ca/devvm-proxy-next\.crt$'
|
|
! stdout 'history|projects'
|
|
vm_name PLAIN plain
|
|
exec tar -xOf $STUB_DIR/sync.tar ca/devvm-proxy.crt
|
|
cmp stdout $PLAIN_dir/run/ca/ca.pem
|
|
exec sh -c 'tar -xOf "$STUB_DIR/sync.tar" home/.claude/settings.json home/.codex/auth.json claude.json env'
|
|
! stdout testfake
|
|
stdout '"OPENAI_API_KEY": *"sk-devvm-proxy-managed'
|
|
exec sh -c 'salt=$(sed -n "s/.*\"proxy_salt\": \"\([^\"]*\)\".*/\1/p" "$PLAIN_dir/vm.json"); tar -xOf "$STUB_DIR/sync.tar" env | grep -Fx "export CLAUDE_CODE_OAUTH_TOKEN=''sk-ant-oat01-devvm-proxy-managed-$salt''"'
|
|
# ~/.claude.json's copy holds only settings, account state and MCP servers:
|
|
# never an API key or the projects' history.
|
|
exec tar -xOf $STUB_DIR/sync.tar claude.json
|
|
stdout '"theme": *"dark"'
|
|
stdout '"API_KEY": *"devvm-redacted"'
|
|
! stdout 'testfake|primaryApiKey|customApiKeyResponses|projects'
|
|
# Each folder to link: its path in the VM's home, then its mount's.
|
|
exec tar -xOf $STUB_DIR/sync.tar links
|
|
stdout '^\.claude/skills\n\S+/config/devvm/agents/claude/\.claude/skills\n\.claude/agents\n\S+/agents/claude/\.claude/agents\n\.claude/commands\n\S+/agents/claude/\.claude/commands\n\.claude/output-styles\n\S+/agents/claude/\.claude/output-styles\n\.claude/plugins\n\S+/agents/claude/\.claude/plugins\n\.codex/prompts\n\S+/config/devvm/agents/codex/\.codex/prompts\n\.codex/skills\n\S+/agents/codex/\.codex/skills\n\z'
|
|
exec tar -xOf $STUB_DIR/sync.tar vm
|
|
stdout '\A\QDEVVM_HOSTNAME=''plain''\E\n\QDEVVM_TZ=''Europe/Paris''\E\n\QDEVVM_LANG=''en_US.UTF-8''\E\n\QDEVVM_GIT_NAME=''Test User''\E\n\QDEVVM_GIT_EMAIL=''[email protected]''\E\n'
|
|
# An open VM's proxy too, as its environment has it, and where its local proxy listens; no
|
|
# transparent mode, which is for confined VMs.
|
|
stdout '^DEVVM_PROXY=''http://devvm:[0-9a-f]{64}@192\.168\.5\.2:[0-9]+''\n\QDEVVM_NO_PROXY=''localhost,127.0.0.1,::1''\E\n\QDEVVM_LOCAL_PROXY=''127.0.77.1:3128''\E\n\QDEVVM_TRANSPARENT_ADDR=''''\E\n\QDEVVM_TRANSPARENT_HOST=''transparent.devvm.proxy''\E\n\z'
|
|
exec tar -tf $STUB_DIR/sync.tar
|
|
stdout '^transparent\.sh$'
|
|
# Without links, the hosts file for /etc/hosts is empty.
|
|
exec tar -xOf $STUB_DIR/sync.tar hosts
|
|
! stdout .
|
|
exec tar -xOf $STUB_DIR/sync.tar env
|
|
stdout '^export LANG=''en_US\.UTF-8''\nexport CLAUDE_CODE_OAUTH_TOKEN=''sk-ant-oat01-devvm-proxy-managed-[0-9a-f]+''\n\z'
|
|
|
|
# A Claude token that isn't a setup-token token isn't sent; no token at
|
|
# all is named too.
|
|
project badtoken
|
|
env CLAUDE_CODE_OAUTH_TOKEN=not-a-setup-token
|
|
exec devvm --network open --no-git-protect --agents claude
|
|
stderr '^devvm: claude_token_invalid$'
|
|
exec tar -xOf $STUB_DIR/sync.tar env
|
|
! stdout CLAUDE_CODE_OAUTH_TOKEN
|
|
project notoken
|
|
env CLAUDE_CODE_OAUTH_TOKEN=
|
|
exec devvm --network open --no-git-protect --agents claude
|
|
stderr '^devvm: no_claude_token vm=devvm-notoken-[0-9a-f]{14}$'
|
|
|
|
# An allowlist VM gets the same: the VM's own CA and its next, the VM's own placeholders, the logins'
|
|
# copies with placeholders (the host's files unchanged), and the
|
|
# settings files with their keys taken out; one devvm can't read that way
|
|
# isn't sent, and neither is an opencode file that isn't settings or
|
|
# Markdown, such as a .env.
|
|
mkdir $HOME/.config/opencode
|
|
cp $WORK/opencode-env $HOME/.config/opencode/.env
|
|
cp $WORK/opencode-agents $HOME/.config/opencode/AGENTS.md
|
|
exec devvm agent import opencode
|
|
project net
|
|
env CLAUDE_CODE_OAUTH_TOKEN=sk-ant-oat01-testfake
|
|
exec devvm --network allowlist --no-git-protect --agents claude,codex,opencode
|
|
stderr '^config_redacted file=\S*/agents/claude/\.claude/settings\.json keys=env\.ANTHROPIC_API_KEY vm=devvm-net-[0-9a-f]{14}$'
|
|
stderr '^devvm: config_not_copied file=\S*/agents/codex/\.codex/config\.toml vm=devvm-net-[0-9a-f]{14}$'
|
|
stderr '^devvm: config_not_copied file=\S*/agents/opencode/\.config/opencode/\.env vm=devvm-net-[0-9a-f]{14}$'
|
|
exec tar -tf $STUB_DIR/sync.tar
|
|
! stdout '^home/\.codex/config\.toml$'
|
|
! stdout '^home/\.config/opencode/\.env$'
|
|
stdout '^home/\.config/opencode/AGENTS\.md$'
|
|
vm_name NET net
|
|
exec tar -xOf $STUB_DIR/sync.tar ca/devvm-proxy.crt
|
|
cmp stdout $NET_dir/run/ca/ca.pem
|
|
exec tar -xOf $STUB_DIR/sync.tar ca/devvm-proxy-next.crt
|
|
cmp stdout $NET_dir/run/ca/next.pem
|
|
exec tar -xOf $STUB_DIR/sync.tar
|
|
! stdout 'PRIVATE KEY'
|
|
exec sh -c 'tar -xOf "$STUB_DIR/sync.tar" home/.claude/settings.json home/.codex/auth.json claude.json env'
|
|
! stdout testfake
|
|
stdout devvm-redacted
|
|
stdout '"OPENAI_API_KEY": *"sk-devvm-proxy-managed'
|
|
! stdout projects
|
|
exec sh -c 'salt=$(sed -n "s/.*\"proxy_salt\": \"\([^\"]*\)\".*/\1/p" "$NET_dir/vm.json"); tar -xOf "$STUB_DIR/sync.tar" env | grep -Fx "export CLAUDE_CODE_OAUTH_TOKEN=''sk-ant-oat01-devvm-proxy-managed-$salt''"'
|
|
exec sh -c 'key=$(sed -n "s/.*\"proxy_key\": \"\([^\"]*\)\".*/\1/p" "$NET_dir/vm.json"); tar -xOf "$STUB_DIR/sync.tar" vm | grep -E "^DEVVM_PROXY=''http://devvm:$key@[0-9.]+:[0-9]+''$"'
|
|
cmp $HOME/.codex/auth.json $WORK/codex.json
|
|
cmp $DATA/logins/codex/.codex/auth.json $WORK/codex.json
|
|
cmp $HOME/.claude.json $WORK/claude.json
|
|
|
|
# A .claude.json in the store devvm can't read stops the setup.
|
|
cp $DATA/logins/claude/.claude.json $WORK/store-claude.json
|
|
cp $WORK/bad.json $DATA/logins/claude/.claude.json
|
|
project badclaude
|
|
! exec devvm --network open --no-git-protect --agents claude
|
|
stderr '^devvm: login_copy_failed agent=claude reason=.* vm=devvm-badclaude-[0-9a-f]{14}$'
|
|
cp $WORK/store-claude.json $DATA/logins/claude/.claude.json
|
|
|
|
# A setup that fails says so, and leaves nothing of what it was sent.
|
|
mkdir $WORK/tmp $WORK/fails
|
|
cd $WORK/fails
|
|
env TMPDIR=$WORK/tmp
|
|
exec sh -c ': > "$STUB_DIR/shell-fails"'
|
|
! exec devvm --network open --no-git-protect --agents claude
|
|
stderr '^devvm: sync_failed vm=devvm-fails-[0-9a-f]{14}$'
|
|
exec sh -c 'ls -A "$TMPDIR"'
|
|
! stdout .
|
|
rm $STUB_DIR/shell-fails
|
|
|
|
# A shared tool the VM couldn't mount stops the launch, named by the VM's
|
|
# own tool list: a line naming any other file doesn't count, and with
|
|
# none left it's the setup that failed.
|
|
vm_name FAILS fails
|
|
exec bash $WORK/unmounted.sh '' ../../etc/passwd
|
|
! exec devvm --network open --no-git-protect
|
|
stderr '^devvm: tools_unmounted tools=claude [0-9][0-9.]* vm=devvm-fails-[0-9a-f]{14}$'
|
|
exec bash $WORK/unmounted.sh claude-9.9.9-000000000000.erofs
|
|
! exec devvm --network open --no-git-protect
|
|
stderr '^devvm: sync_failed vm=devvm-fails-[0-9a-f]{14}$'
|
|
rm $STUB_DIR/sync-fails-with
|
|
exec devvm --network open --no-git-protect
|
|
! stderr 'tools_unmounted|sync_failed'
|
|
|
|
-- unmounted.sh --
|
|
# The report tools.sh writes when it fails, listing each file named ('' for
|
|
# the VM's first tool image) after lines of its own, and with a last line
|
|
# cut short.
|
|
first=$(sed -n '/"files": \[/{n;s/.*"\([^"]*\)".*/\1/p;}' "$FAILS_dir/vm.json")
|
|
{
|
|
echo "devvm-tools: can't mount something"
|
|
printf '%s\n' "${first%% *} and more"
|
|
for f in "$@"; do echo "${f:-${first%% *}}"; done
|
|
printf '%s' "${first%% *}"
|
|
} > "$STUB_DIR/sync-fails-with"
|
|
|
|
-- settings.json --
|
|
{"env":{"ANTHROPIC_API_KEY":"testfake-settings"},"theme":"dark"}
|
|
-- claude.json --
|
|
{"theme":"dark","primaryApiKey":"testfake-apikey","customApiKeyResponses":{"approved":["testfake-apikey"]},"mcpServers":{"srv":{"command":"x","env":{"API_KEY":"testfake-mcp"}}},"projects":{"/p":{"history":["testfake-history"]}}}
|
|
-- codex.json --
|
|
{"OPENAI_API_KEY":"sk-testfake-codex","last_refresh":null}
|
|
-- config.toml --
|
|
note = """
|
|
testfake-unclosed
|
|
-- bad.json --
|
|
{"theme":
|
|
-- opencode-env --
|
|
MY_SERVICE=testfake-dotenv
|
|
-- opencode-agents --
|
|
Be brief.
|
|
-- history.jsonl --
|
|
{"prompt":"testfake-history"}
|