Files
devvm/testdata/script/sync.txtar
T
w3cjandClaude Opus 5.5 36f910839e fix(desktop): browsers reach the web through a local proxy that adds the VM's password
Chrome, Chromium and Firefox ignore the password in HTTP(S)_PROXY, so in
devvm desktop they asked for the proxy's username and password on every
site. The guest setup now writes devvm-local-proxy, which socat (now in
the desktop layer) serves on 127.0.77.1:3128, the VM's loopback alone.
For each connection it reads the request's head, drops the client's
Proxy-Authorization and Proxy-Connection, adds the VM's password and
sends it to devvm's proxy, then socat carries the rest both ways. It
takes only CONNECT HOST:PORT and absolute http(s):// requests, the
latter with Connection: close, so each connection's one request carries
the password. devvm-desktop starts it and points the Xfce session's
http_proxy, https_proxy, HTTP_PROXY and HTTPS_PROXY at it; on Xfce,
Chrome and Chromium read those, and Firefox reads them first with its
default system proxy setting. A blocked host still gets the proxy's 403.

- proxy.LocalProxyAddr, LocalProxyPort, IsLocalProxyAddr: the one owner
  of the address, sent to the guest as DEVVM_LOCAL_PROXY (vm.localProxy).
- vmssh: the port forwarder never forwards a server on 127.0.77.1.
- Tests: netpolicy's TestLocalProxy runs sync.sh's script (bash 3.2 on
  macOS) against a fake proxy: the password replaced, Connection: close,
  a tunnel, the 403 passed on, origin-form and junk refused with 400
  before any connection; TestListeners, TestIsLocalProxyAddr,
  TestLocalProxy (vm), sync.txtar. e2e desktop (tests/e2e.sh, still the
  bash section): the session's variables, the listener on 127.0.77.1
  alone, curl without a password to github.com, example.com's 403 over
  CONNECT and plain HTTP, 400 for origin form, nothing on this
  machine's 3128.
- Docs: using/desktop.md (Browsers), internals/desktop.md (The local
  proxy), design.md's desktop note, ports.md, network.md's setup.

Security review (security-audit skill, guidance mode, local IPC and
proxy request handling):
- Fixed by design: devvm forwards every VM port by default, so a local
  proxy on 127.0.0.1 would have put a password-less route to the VM's
  proxy, and its secrets, on the host's localhost for every local user.
  The forwarder now skips the local proxy's address on every port.
- The password goes only to the VM's proxy, whose address is fixed in
  the script, never to an address a request names, in the one header
  the local proxy adds; devvm's proxy strips Proxy-Authorization before
  forwarding. It's never in a process's arguments (bash builtins only).
- Web pages: requests from a page to the loopback are origin form,
  refused with 400 before any connection; a page can't send CONNECT or
  an absolute-form line, and DNS rebinding changes only Host.
- No new power in the VM: the same password is in /etc/environment;
  the script is mode 700, the VM user's.
- Residual: a program in the VM can hold up to 256 connections slowly
  (30 s a line, 100 headers), only against the VM's own browsing; an
  ssh -L the user types to 127.0.77.1:3128 would expose it, as any
  forward they choose.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-06 00:03:45 -07:00

186 lines
9.5 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\},\{"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.
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\z'
# 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"}