mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 21:36:40 -10:00
ls, images, tools, size, ports, network (and -g), network log (and --blocked), ssh-agent, git-protect, secret, history, space, retention and doctor take --json: one JSON object on stdout with "version": 1 first, messages on stderr (ui.DataOnly), lists [] when empty. Settings commands only show with --json and refuse a value (json_shows_only). doctor --json replaces --fixes: problems with key, fix (null without one) and message, warnings, docker and every backend's features; it prints nothing else and succeeds whatever is missing, and install.sh reads its problems with awk. TestJSONShapes holds each command's field names and types. Each shape is documented on its command's page, with the contract under Everyday commands' Output for scripts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
236 lines
10 KiB
Plaintext
236 lines
10 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: arg_not_choice choices=on, off command=devvm network given=sideways$'
|
|
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$'
|
|
|
|
# devvm network -g: what new VMs get, ask until it's saved; ask is only
|
|
# for new VMs.
|
|
exec devvm network -g
|
|
stdout '\Aask\n\z'
|
|
! exists $XDG_CONFIG_HOME/devvm/network
|
|
! exec devvm network ask
|
|
stderr '^devvm: net_ask_global$'
|
|
! exec devvm network -g sideways
|
|
stderr '^devvm: arg_not_choice choices=ask, on, off command=devvm network given=sideways$'
|
|
! exec devvm network -g on off
|
|
stderr '^devvm: args_too_many args=\[on\|off\] command=devvm network given=on off$'
|
|
|
|
# A saved off: new VMs get none, unasked and unwarned; --network-policy
|
|
# beats it. The VMs that exist keep theirs.
|
|
exec devvm network -g off
|
|
stdout '^==> network_default mode=off$'
|
|
exec cat $XDG_CONFIG_HOME/devvm/network
|
|
stdout '\Aoff\n\z'
|
|
exec devvm network -g
|
|
stdout '\Aoff\n\z'
|
|
exec devvm network -g --json
|
|
stdout '\A{\n "version": 1,\n "policy": "off"\n}\n\z'
|
|
mkdir $WORK/offsaved
|
|
cd $WORK/offsaved
|
|
exec devvm --no-git-protect base
|
|
! stderr 'net_about|net_ask|net_off_'
|
|
exec sh -c 'cat "$VMS"/devvm-offsaved-*'
|
|
stdout '^net=off$'
|
|
mkdir $WORK/offflag
|
|
cd $WORK/offflag
|
|
exec devvm --network-policy --no-git-protect base
|
|
exec sh -c 'cat "$VMS"/devvm-offflag-*'
|
|
stdout '^net=on$'
|
|
cd $WORK/default
|
|
exec sh -c 'limactl stop "$(cd "$VMS" && ls devvm-default-* | grep -v "\.")"'
|
|
exec devvm
|
|
exec sh -c 'cat "$VMS"/devvm-default-*'
|
|
stdout '^net=on$'
|
|
stdout '^net_check=ok$'
|
|
|
|
# A saved on: new VMs get it; --no-network-policy beats it.
|
|
exec devvm network -g on
|
|
stdout '^==> network_default mode=on$'
|
|
mkdir $WORK/onsaved
|
|
cd $WORK/onsaved
|
|
exec devvm --no-git-protect base
|
|
! stderr 'net_about|net_ask|net_off_'
|
|
exec sh -c 'cat "$VMS"/devvm-onsaved-*'
|
|
stdout '^net=on$'
|
|
mkdir $WORK/onflag
|
|
cd $WORK/onflag
|
|
exec devvm --no-network-policy --no-git-protect base
|
|
exec sh -c 'cat "$VMS"/devvm-onflag-*'
|
|
stdout '^net=off$'
|
|
|
|
# ask again, and a file edited by hand that says something else: a new
|
|
# VM without a flag is refused, naming the file, and one with a flag
|
|
# doesn't read it.
|
|
exec devvm network -g ask
|
|
stdout '^==> network_default mode=ask$'
|
|
exec cat $XDG_CONFIG_HOME/devvm/network
|
|
stdout '\Aask\n\z'
|
|
exec sh -c 'echo maybe > "$XDG_CONFIG_HOME/devvm/network"'
|
|
! exec devvm network -g
|
|
stderr '^devvm: net_default_failed reason=\S*/config/devvm/network:1: '
|
|
mkdir $WORK/badsaved
|
|
cd $WORK/badsaved
|
|
! exec devvm --no-git-protect base
|
|
stderr '\S*/config/devvm/network:1: '
|
|
exec devvm --network-policy --no-git-protect base
|
|
|
|
-- codex.json --
|
|
{"OPENAI_API_KEY":"sk-testfake-codex","last_refresh":null}
|