mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 21:36:40 -10:00
Behind a proxy that inspects TLS, VMs and build VMs couldn't make TLS
connections. The CA certificates in ~/.config/devvm/ca (*.pem, *.crt) are
now read at each launch, build and proxy start, checked, and trusted;
images never keep them.
- internal/trust (new): Read parses every PEM block with crypto/x509 and
refuses anything but CA certificates (ca_not_certificate, ca_not_ca,
ca_invalid, naming the file); only the re-encoded certificates leave the
host. Env/GuestEnv (NODE_EXTRA_CA_CERTS=/etc/ssl/devvm.pem,
SSL_CERT_FILE, REQUESTS_CA_BUNDLE, PIP_CERT, UV_SYSTEM_CERTS), Build
(a build's Add/Remove root scripts from guest/ca.sh), Script (Env
exported at a build script's start), Name, Bundle.
- assets/guest/ca.sh (new): installs exactly DIR's devvm-*.crt into
/usr/local/share/ca-certificates (update-ca-certificates --fresh), or
into the bundle file itself when there's no update-ca-certificates (the
old bundle kept and put back), writes /etc/ssl/devvm.pem; without DIR,
removes all of devvm's. sync.sh runs it with the proxy's CA
(ca/devvm-proxy.crt) and the user's (ca/devvm-extra-N.crt).
- backend: ImageSpec.Trust and ToolsSpec.Trust (backend.Trust{Add,
Remove}); VMSpec.Env. Lima runs Add after the start and Remove after the
scripts (runScript's root mode, sudo sh), the --from conversion VM runs
Add and oci/build.sh runs ca.sh in the image's chroot around bootify.sh
(guest/ mounted read-only, CA_SH argument); smolvm and Docker run Add
before prepare.sh and Remove after sshd.sh; tools builds run Add only.
Lima's clone sets the guest environment, so starts edit nothing.
- vm: every project VM starts with trust.Env (netpolicy.Env keeps only the
proxy's variables); the setup sends ca.sh and ca/; Dirs.TrustedCAs.
- proxy: -upstream-cas FILE adds CAs to the system roots for its own TLS
connections; netpolicy writes run/<vm>.proxy.cas and restarts a proxy
whose bundle changed.
- doctor: doctor_proxy_ca when HTTPS_PROXY is set and the folder has no
CAs (Say), a refused folder warned about.
- Tests: internal/trust unit tests (folder reading, scripts, ca.sh run in a
stand-in root with and without update-ca-certificates); ca.txtar; sync,
up, network, smolvm txtars and the limactl stub (clone's .env, list
shows lima.yaml's env); e2e: images (a layer built with a test CA, its
key unchanged, its image's copy without CA files), project ("a company's
CA" section), tools (node fetch), smolvm and docker build checks.
- Docs: using/settings (a company's CA), using/troubleshooting (TLS errors
behind a company proxy), internals/network and internals/images,
safety/network, design (assets written out), oci README, doctor's help.
- Structure: Dirs at 38 methods, trust.Env a table, trust above backends.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
165 lines
7.7 KiB
Plaintext
165 lines
7.7 KiB
Plaintext
# Network policy 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.
|
|
env DEVVM_MESSAGES=names
|
|
env DATA=$XDG_DATA_HOME/devvm
|
|
env VMS=$XDG_DATA_HOME/devvm/vms
|
|
env RUN=$XDG_DATA_HOME/devvm/run
|
|
|
|
# --no-network-policy: off, with no proxy and no CA.
|
|
mkdir $WORK/off
|
|
cd $WORK/off
|
|
exec devvm --no-network-policy --no-git-protect base
|
|
stdout '^==> creating_from image=base vm=devvm-off-[0-9a-f]{14}$'
|
|
exec sh -c 'cat "$VMS"/devvm-off-*'
|
|
stdout '^net=off$'
|
|
! stdout 'proxy_|net_check'
|
|
stub_calls
|
|
! stdout curl
|
|
! exists $DATA/ca
|
|
|
|
# --network-policy: devvm's CA (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.
|
|
mkdir $WORK/net
|
|
cd $WORK/net
|
|
exec sh -c ': > "$STUB_LOG"'
|
|
exec devvm --network-policy --no-git-protect base
|
|
stdout '^==> starting vm=devvm-net-[0-9a-f]{14}$'
|
|
exists $DATA/ca/ca.pem $DATA/ca/ca.key
|
|
exec sh -c 'cat "$VMS"/devvm-net-*'
|
|
stdout '^net=on$'
|
|
stdout '^net_check=ok$'
|
|
stdout '^proxy_key=[0-9a-f]{32}$'
|
|
stdout '^proxy_salt=[0-9a-f]{32}$'
|
|
stdout '^ssh_port=[0-9]+$'
|
|
stdout '^proxy_port=[0-9]+$'
|
|
stub_calls
|
|
[darwin] stdout '^tmutil addexclusion \S*/data/devvm/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}\nlimactl shell --workdir / devvm-net-[0-9a-f]{14} sh -c .*/etc/ssh/ssh_host_.*\n(limactl list --json\n)*ssh -F none -M .*\nlimactl shell --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 --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=//p" "$VMS"/devvm-net-*); ! 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_port=//p" "$VMS"/devvm-net-*)" "$RUN"/devvm-net-*.sb'
|
|
# The proxy said it listens on that port, for that VM; its password is in
|
|
# a file, never in its arguments.
|
|
exec sh -c 'grep -F "listening on 127.0.0.1:$(sed -n "s/^proxy_port=//p" "$VMS"/devvm-net-*) for devvm-net-" "$DATA"/logs/devvm-net-*.proxy.log'
|
|
exec sh -c 'cat "$RUN"/devvm-net-*.proxy.auth'
|
|
stdout '^[0-9a-f]{32}$'
|
|
exec sh -c 'cat "$RUN"/devvm-net-*.secrets.json'
|
|
stdout '^\[\]$'
|
|
# The run log never holds the key.
|
|
exec sh -c 'cat "$DATA"/logs/runs/*.log'
|
|
stdout 'devvm:devvm-proxy-password@'
|
|
! stdout 'devvm:[0-9a-f]{32}@'
|
|
|
|
# A VM devvm started confined that still reaches the internet directly:
|
|
# stopped, no setup, no shell.
|
|
mkdir $WORK/leak
|
|
cd $WORK/leak
|
|
exec sh -c ': > "$STUB_LOG" && : > "$STUB_DIR/net-direct"'
|
|
! exec devvm --network-policy --no-git-protect base
|
|
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 --workdir /\S*/leak'
|
|
exec sh -c 'cat "$VMS"/devvm-leak-*'
|
|
stdout '^net_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 'pp=$(sed -n "s/^proxy_port=//p" "$VMS"/devvm-net-*); pkill -f -- "_proxy -listen 127.0.0.1:$pp "; sleep 0.5; echo k > "$WORK/squat.key"; devvm _proxy -listen "127.0.0.1:$pp" -auth-file "$WORK/squat.key" -lifeline "$WORK/squat.none" >/dev/null 2>&1 & echo $! > "$WORK/squat.pid"; sleep 1'
|
|
exec sh -c ': > "$STUB_LOG"'
|
|
! 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 --workdir /\S*/net'
|
|
exec sh -c 'kill "$(cat "$WORK/squat.pid")"'
|
|
|
|
# Secrets: claude comes with the image. The proxy gets its binding, with
|
|
# the VM's own placeholder and never the token, and its host on 443.
|
|
mkdir $WORK/agent
|
|
cd $WORK/agent
|
|
env CLAUDE_CODE_OAUTH_TOKEN=sk-ant-oat01-testfake
|
|
exec devvm --network-policy --no-git-protect claude
|
|
exec sh -c 'cat "$RUN"/devvm-agent-*.secrets.json'
|
|
stdout '^\[\{"name":"claude","hosts":\["api\.anthropic\.com"\],"header":"Authorization","placeholder":"sk-ant-oat01-devvm-proxy-managed-[0-9a-f]{32}"\}\]$'
|
|
! stdout testfake
|
|
exec sh -c 'grep -F "$(sed -n "s/^proxy_salt=//p" "$VMS"/devvm-agent-*)" "$RUN"/devvm-agent-*.secrets.json'
|
|
exec sh -c 'cat "$RUN"/devvm-agent-*.secrets.policy'
|
|
stdout '^api\.anthropic\.com:443$'
|
|
# Its proxy's policy files: base's, claude's, the user's, the VM's own and
|
|
# its secrets' hosts.
|
|
exec sh -c 'cat "$RUN"/devvm-agent-*.proxy.policy'
|
|
stdout '/data/devvm/assets/[0-9a-f]{16}/layers/base\.policy,\S*/data/devvm/assets/[0-9a-f]{16}/shared-tools/claude\.policy,\S*/config/devvm/policy,\S*/data/devvm/vms/devvm-agent-[0-9a-f]{14}\.policy,\S*/data/devvm/run/devvm-agent-[0-9a-f]{14}\.secrets\.policy$'
|
|
env CLAUDE_CODE_OAUTH_TOKEN=
|
|
|
|
# A Codex login on the host: its bindings and hosts, with the VM's
|
|
# placeholders.
|
|
mkdir $HOME/.codex
|
|
cp $WORK/codex.json $HOME/.codex/auth.json
|
|
mkdir $WORK/codex
|
|
cd $WORK/codex
|
|
exec devvm --network-policy --no-git-protect codex
|
|
exec sh -c 'cat "$RUN"/devvm-codex-*.secrets.json'
|
|
stdout '"name":"codex-key","hosts":\["api\.openai\.com"\]'
|
|
! stdout sk-testfake
|
|
exec sh -c 'cat "$RUN"/devvm-codex-*.secrets.policy'
|
|
stdout '^api\.openai\.com:443$'
|
|
|
|
# devvm network: on, off or unenforced, as devvm ls shows it. on and off
|
|
# change the VM's state, applied when it next starts.
|
|
mkdir $WORK/none
|
|
cd $WORK/none
|
|
! exec devvm network
|
|
stderr '^devvm: no_vm dir=\S*/none$'
|
|
! exec devvm network sideways
|
|
stderr '^devvm: usage_error reason='
|
|
cd $WORK/off
|
|
exec devvm network
|
|
stdout '^off$'
|
|
exec devvm network on
|
|
stdout '^==> net_set_running state=on vm=devvm-off-[0-9a-f]{14}$'
|
|
stderr '^net_on_old_tokens vm=devvm-off-[0-9a-f]{14}$'
|
|
exec sh -c 'cat "$VMS"/devvm-off-*'
|
|
stdout '^net=on$'
|
|
exec devvm network on
|
|
stdout '^==> net_already state=on 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 off
|
|
stdout '^==> net_set_running state=off vm=devvm-off-[0-9a-f]{14}$'
|
|
! stderr .
|
|
# Stopped, it changes at its next start.
|
|
exec sh -c 'limactl stop "$(cd "$VMS" && ls devvm-off-* | grep -v "\.")"'
|
|
exec devvm network on
|
|
stdout '^==> net_set_stopped state=on vm=devvm-off-[0-9a-f]{14}$'
|
|
exec devvm network
|
|
stdout '^on$'
|
|
|
|
# Without a flag, and without a terminal to ask in: on, unasked.
|
|
mkdir $WORK/default
|
|
cd $WORK/default
|
|
exec devvm --no-git-protect base
|
|
stdout '^==> creating_from image=base vm=devvm-default-[0-9a-f]{14}$'
|
|
! stderr 'net_about|net_ask|net_off_'
|
|
exec sh -c 'cat "$VMS"/devvm-default-*'
|
|
stdout '^net=on$'
|
|
stdout '^net_check=ok$'
|
|
|
|
-- codex.json --
|
|
{"OPENAI_API_KEY":"sk-testfake-codex","last_refresh":null}
|