Files
w3cjandClaude Opus 5.5 c0f4b8fb5c feat(netpolicy): network tiers in state, confinement and the proxy
A VM's network is one of four tiers, open, internet, allowlist and none,
in its state's net section (netpolicy.Tier), in place of on/off. Every
VM has its proxy. Confined tiers start on NetProxy; open starts on the
backend's own network with its proxy set in the guest
(Confinement.GuestProxy): on Lima no Seatbelt profile and no QEMU
wrapper, the proxy at 192.168.5.2 on both hosts, propagateProxyEnv off.

The proxy: Config.Open (every host and address, no floor, no
policies), Config.DenyPolicies (files whose denies alone apply), the
rule port :* (any port), and ** matching address literals (the floor
still holds). Policies per tier (netpolicy.PolicySet): internet is
network/internet.policy (**:*) plus your denies; none is the agents'
built-in policies, the secrets' hosts and your denies; open none.

Links: a client links only to a target on its tier or a stricter one,
and a group's VMs are all on one tier. The self-check per tier: open
asks its proxy through the guest's settings and warns
(net_proxy_unreachable). devvm ls and devvm network show the tier. A
backend without egress-proxy offers open alone (net_tier_backend).
devvm network on/off and --network-policy/--no-network-policy map to
allowlist/open. Design note, threat check and docs; e2e in the network
and link sections.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-05 14:32:06 -07:00

73 lines
3.6 KiB
Plaintext

# gc --orphans: what devvm keeps for a VM its backend, asked, no longer
# has (deleted outside devvm), deleted as devvm rm does after its delete.
# Never a VM that exists, one whose backend doesn't answer, one made in
# another Lima home, nor one whose state changed in the last hour (it may
# be being made). Never part of gc's default run.
# Each VM's folder is its name's last 14 characters.
mkdir $VMS/12345612345601 $VMS/12345612345602 $VMS/12345612345603 $VMS/12345612345604 $VMS/12345612345605 $VMS/12345612345607
# This run's Lima home, as a VM's state records it.
exec sh -c 'printf %s "$DEVVM_LIMA_HOME" | { sha256sum 2>/dev/null || shasum -a 256; } | cut -c1-16 > at'
# A Lima VM that exists, and one limactl deleted, with its logs, run and
# port files; one made in another Lima home, and one that doesn't say
# where it was made while this run's home isn't the default; one being
# made.
exec stub vm devvm-live-12345612345601 Stopped
exec sh -c 'for v in live:01 gone:02 new:03; do sh $WORK/vmjson "devvm-${v%:*}-123456123456${v#*:}" "/p/${v%:*}" lima "$(cat at)"; done'
exec sh $WORK/vmjson devvm-moved-12345612345604 /p/moved lima 0000000000000000
exec sh $WORK/vmjson devvm-norec-12345612345605 /p/norec lima
exec sh -c 'cd "$VMS" && for h in 12345612345601 12345612345602; do mkdir $h/logs $h/run && echo x > $h/logs/network.jsonl && echo x > $h/run/sandbox.sb && echo x > $h/logs/ports.log; done'
exec sh -c 'cd "$VMS" && touch -t 202001010000 12345612345601/vm.json 12345612345602/vm.json 12345612345604/vm.json 12345612345605/vm.json'
# A VM of a backend this devvm doesn't have (a newer devvm's), which
# can't be asked.
exec sh $WORK/vmjson devvm-other-12345612345607 /p/other nope
exec touch -t 202001010000 $VMS/12345612345607/vm.json
# The default run leaves them.
exec devvm gc --force
exists $VMS/12345612345602/vm.json
stub_reset
exec devvm gc --force --orphans
stdout '^gc_orphans count=1$'
stdout '^gc_orphan backend=lima dir=/p/gone vm=devvm-gone-12345612345602$'
stderr '^gc_orphans_unknown backend=nope$'
stderr '^gc_orphan_elsewhere vm=devvm-moved-12345612345604$'
stderr '^gc_orphan_elsewhere vm=devvm-norec-12345612345605$'
stderr '^gc_orphan_recent vm=devvm-new-12345612345603$'
stdout '^==> forgot_orphan vm=devvm-gone-12345612345602$'
# Gone: the orphans' folders (state, logs, run and port files). Left:
# everything else's.
! exists $VMS/12345612345602
exists $VMS/12345612345601/vm.json
exists $VMS/12345612345601/logs/network.jsonl
exists $VMS/12345612345601/run/sandbox.sb
exists $VMS/12345612345601/logs/ports.log
exists $VMS/12345612345604/vm.json
exists $VMS/12345612345603/vm.json
exists $VMS/12345612345605/vm.json
exists $VMS/12345612345607/vm.json
exec sh -c 'stub vms | grep -c .'
stdout '^1$'
stub_calls
! stdout 'limactl delete'
# When a backend a VM's state names doesn't answer, gc warns and leaves
# its VMs' state alone.
mkdir $VMS/12345612345602
exec sh -c 'sh $WORK/vmjson devvm-gone-12345612345602 /p/gone lima "$(cat at)" && touch -t 202001010000 "$VMS/12345612345602/vm.json"'
exec sh -c 'touch "$STUB_DIR/list-fails"'
exec devvm gc --force --orphans
stderr '^devvm: gc_backend_skipped backend=lima$'
stderr '^gc_orphans_unknown backend=lima$'
exists $VMS/12345612345602/vm.json
exists $VMS/12345612345604/vm.json
-- vmjson --
# vmjson NAME DIR BACKEND [BACKEND_AT]: a finished VM's state, without
# network policy, in its folder in $VMS.
at=
[ -z "$4" ] || at=", \"backend_at\": \"$4\""
printf '{"version": 1, "id": "x", "name": "%s", "image": "base", "dir": "%s", "backend": "%s"%s, "created": "2020-01-01T00:00:00Z", "net": {"tier": "open"}}\n' "$1" "$2" "$3" "$at" > "$VMS/${1##*-}/vm.json"