Files
devvm/testdata/script/layout.txtar
T
w3cjandClaude Opus 5.5 aeea3135b2 feat(proxy): the proxy's broker and its child
A VM's proxy runs as two processes, as design.md's "The proxy's broker"
says: devvm _proxy, the broker, which keeps what only the host should
do, and devvm _proxy-child, which reads the VM's network and can be
confined by the follow-ups.

- wire.go: the protocol over one socketpair (close-on-exec from the
  start: SOCK_CLOEXEC on Linux, ForkLock elsewhere), length-prefixed JSON
  frames of at most 2 MiB, unknown fields refused, bytes as base64, one
  descriptor on a frame's first bytes (SCM_RIGHTS, MSG_CTRUNC breaks the
  rules), wire types for every secret (redact.Secret at once).
- broker.go: newBroker, the start (handshake: version 1 and each side's
  executable's SHA-256, within 4 s), the answers (value through lookups,
  kept 30 s or 5 min, a failure 5 s, dropped when the bindings change;
  file by number; link connected by the broker and passed as a
  descriptor; token exchanged by the broker), each by something in its
  own config, with caps 1/8/4/256; live: the lifeline closes the socket
  and kills the child 6 s later, SIGTERM stops it within a second, a
  child that ends ends the broker, a rule broken stops the child.
- child.go: the start (startOf), the child's server (newChildServer),
  the broker as hostSide over the socket (brokerClient), runChildOn;
  ready only after it reads the host's addresses (kept: the last good
  read), roots and time zone loaded first.
- process.go: Main(ctx, ...) and ChildMain; the child spawned with
  /proc/self/exe on Linux, PR_SET_PDEATHSIG from a locked thread
  (daemon.Cmd.DieWithThread), descriptors 3 and 4, and TZ, SSL_CERT_*
  and GODEBUG with updatemaxprocs=0 alone; run/proxy-child.pid and
  run/proxy.confined ("none" until the follow-ups); KeepLogs in the
  broker. ChildMain refuses to start unless descriptors 3 and 4 are a
  unix socket and an IP one (checkInherited): run by hand, without
  them, those numbers can be the Go runtime's own, which closing
  crashed it (signal_recv: inconsistent state).
- capture.go: a captured token request goes to the broker
  (captureToken, exchanger), so a login's real tokens never enter the
  child; an error reply passes up to 1 MiB, longer gets 502.
- watched.go: the child stats each changing file and asks the broker
  for it once it changed, keeping the stamp of what the broker read.
- rotate.go: proxy.log rotated by both through its descriptor, under a
  lock of a description of its own; OpenLog opens a log never through a
  link, one link, yours, replacing what a child left in its place.
- nixcache.go: the trim and its count through a safefile.Root, nar/
  only as a folder, links deleted as themselves; reads never through a
  link; the lock tried for 5 s (ErrNixLocked, nix_cache_locked).
- daemon: Cmd.Err, Files, Env, DieWithThread; Handle.Kill, Exit;
  WritePID.
- netpolicy: Proxy.Stop also stops a child that outlived its broker
  (run/proxy-child.pid, _proxy-child -for); proxy.log opened with
  OpenLog; a refused launch keeps a running VM only while both run.
  devvm network log and lock read the event log through safefile.
- vm, vmssh, vmlog: links.log and ports.log opened with OpenLog, read
  through safefile, trimmed only as a regular file with one link.
- backend: the build proxy's logs in a logs/ folder of their own.
- cli: _proxy-child; _proxy waits for its child on a signal
  (StopsItsOwn); the child reads none of devvm's folders (no
  makePrivate); ui.Files.
- Tests: FuzzBrokerFrames, the frames' rules, the handshake and the
  pair's end in synctest bubbles, the caps, the broker naming its own
  alone, the client over a real socketpair with a passed descriptor,
  ChildMain, TestInheritedSocket and proxy.txtar's child run by hand,
  the frozen 0.1.0 configs starting a broker and child,
  two writers rotating once, planted links, FIFOs and hard links; the
  testscript runner stops _proxy-child too; e2e: broker and child, their
  arguments, descriptors and environment, stop, SIGKILL either, planted
  files in the logs folder and the Nix cache, build proxies gone.
- Review fixes: the lifeline closes the socket and starts the kill's
  timer before logging; every log lock (proxy.log's, the event log's
  rotation) is tried without blocking for 200 ms (flockWithin, which the
  Nix lock shares), then written without or the rotation skipped; a
  copied log's rotation streams at most twice its limit from a line's
  start (copyFrom, copyAtomic); a reply too long to send goes as
  too_long; kept token headers capped at 1 KiB; the child gives up on a
  request whose context ended, dropping its late reply and holding its
  slot until then; a write deadline on the start frame; errors reach the
  child as codes (not_found, refused, busy, too_long, failed), their
  text in the broker's log; FuzzFrameStreams, and FuzzBrokerFrames
  writes from a goroutine; nix_cache_locked links to How it works.
- Docs: processes, network, overview, design (with threat rows for the
  logs' locks and a log made huge), troubleshooting, the proxy's
  README, structure, testing; CHANGELOG.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 22:04:32 -07:00

275 lines
6.2 KiB
Plaintext

# devvm's folders: their layout version, checked before every command
# that reads them, and every file devvm keeps for a VM with network
# policy, ports, a link and a secret, against the listings below. A
# change to the layout changes a listing: consider the layout version
# then (Contributing's state layout).
# The first run gives both folders this devvm's version.
exec devvm ls
cmp $DATA/version want/version
cmp $CFG/version want/version
# A newer devvm's folders are refused, before the command runs, and so
# is a version file devvm can't read; help, completion and the version
# still run.
cp want/newer $DATA/version
! exec devvm ls
stderr '^devvm: layout_newer current=1 path=\S+/data/devvm/version version=2$'
! stdout .
exec devvm --version
exec devvm version
exec devvm help
exec devvm completion bash
cmp $DATA/version want/newer
cp want/version $DATA/version
cp want/newer $CFG/version
! exec devvm doctor
stderr '^devvm: layout_newer current=1 path=\S+/config/devvm/version version=2$'
cp want/corrupt $CFG/version
! exec devvm ls
stderr '^devvm: layout_unchecked reason=\S+/config/devvm/version: not a layout version$'
rm $CFG/version
exec devvm ls
cmp $CFG/version want/version
# A target VM that publishes a port, and a client VM with a link to it
# and a secret, both with network policy and forwarding a port, one free
# on this host, so the forwarders start whatever else listens.
free_port PORT
exec devvm ports -g $PORT
project db
exec devvm --network allowlist --no-git-protect
exec devvm link publish 5432
project app
exec devvm --network allowlist --no-git-protect
exec devvm link add db 5432
stdin $WORK/github.token
exec devvm secret set github --stdin
exec devvm secret use github
stdin $WORK/stripe.token
exec devvm secret set stripe --host api.stripe.com --env STRIPE_API_KEY --stdin
exec devvm secret use stripe
vm_name APP app
vm_name DB db
vm_state $APP_dir/vm.json
stdout '^made_by=\S+$'
# Every file and folder, with the VMs' hashes named and other hashes,
# times and versions left out. Each VM's start holds its ssh port for a
# minute (run/ports.ssh-hold in its folder).
exec sh $WORK/list.sh $CFG
cmp stdout $WORK/config.txt
exec sh $WORK/list.sh $DATA
[darwin] cmp stdout $WORK/data.txt
[!darwin] cmp stdout $WORK/data-linux.txt
-- want/version --
1
-- want/newer --
2
-- want/corrupt --
one
-- github.token --
ghp_testfake
-- stripe.token --
sk_test_fake
-- list.sh --
# list.sh FOLDER: every path under FOLDER, sorted, with APP's and DB's
# hashes named and other hashes, times, versions and QEMU's architecture
# as X.
cd "$1" || exit 1
find . -mindepth 1 | sed -E \
-e 's|^\./||' -e 's/qemu-system-[a-z0-9_]+/qemu-system-X/' \
-e "s/${APP##*-}/APP/g" -e "s/${DB##*-}/DB/g" \
-e 's/[0-9a-f]{12,}/X/g' -e 's/[0-9]{8}-[0-9]{6}-[0-9]+/X/g' -e 's/[0-9]+\.[0-9]+\.[0-9]+/X/g' |
LC_ALL=C sort -u
-- config.txt --
version
-- data.txt --
custom-secrets.json
custom-secrets.lock
groups.lock
images
images/X
images/X/record.json
images/locks
images/locks/X
images/locks/packages
images/locks/ubuntu
images/ubuntu.json
logs
logs/runs
logs/runs/X.log
making.lock
packages
packages/sets
packages/sets/X.json
run
run/build-ports
run/builds
run/claims.lock
run/link-X.ctl
run/link-X.sock
settings.json
ssh_config
tools
version
version.lock
vms
vms/APP
vms/APP/lock
vms/APP/logs
vms/APP/logs/links.log
vms/APP/logs/network.jsonl
vms/APP/logs/ports.log
vms/APP/logs/proxy.log
vms/APP/run
vms/APP/run/ca
vms/APP/run/ca/ca.key
vms/APP/run/ca/ca.pem
vms/APP/run/ca/lock
vms/APP/run/ca/next.key
vms/APP/run/ca/next.pem
vms/APP/run/known_hosts
vms/APP/run/links.json
vms/APP/run/links.pid
vms/APP/run/ports.forwarded
vms/APP/run/ports.lock
vms/APP/run/ports.pid
vms/APP/run/ports.ssh-hold
vms/APP/run/ports.status
vms/APP/run/proxy-child.pid
vms/APP/run/proxy.confined
vms/APP/run/proxy.json
vms/APP/run/proxy.pid
vms/APP/run/proxy.status
vms/APP/run/sandbox.sb
vms/APP/run/secrets.json
vms/APP/run/secrets.policy
vms/APP/run/started
vms/APP/vm.json
vms/DB
vms/DB/lock
vms/DB/logs
vms/DB/logs/network.jsonl
vms/DB/logs/ports.log
vms/DB/logs/proxy.log
vms/DB/run
vms/DB/run/ca
vms/DB/run/ca/ca.key
vms/DB/run/ca/ca.pem
vms/DB/run/ca/lock
vms/DB/run/ca/next.key
vms/DB/run/ca/next.pem
vms/DB/run/known_hosts
vms/DB/run/ports.forwarded
vms/DB/run/ports.lock
vms/DB/run/ports.pid
vms/DB/run/ports.ssh-hold
vms/DB/run/ports.status
vms/DB/run/proxy-child.pid
vms/DB/run/proxy.confined
vms/DB/run/proxy.json
vms/DB/run/proxy.pid
vms/DB/run/proxy.status
vms/DB/run/sandbox.sb
vms/DB/run/secrets.json
vms/DB/run/secrets.policy
vms/DB/run/started
vms/DB/vm.json
-- data-linux.txt --
custom-secrets.json
custom-secrets.lock
groups.lock
images
images/X
images/X/record.json
images/locks
images/locks/X
images/locks/packages
images/locks/ubuntu
images/ubuntu.json
logs
logs/runs
logs/runs/X.log
making.lock
packages
packages/sets
packages/sets/X.json
run
run/build-ports
run/builds
run/claims.lock
run/link-X.ctl
run/link-X.sock
run/qemu
run/qemu/qemu-system-X
secrets
secrets/custom.stripe
secrets/github
settings.json
ssh_config
tools
version
version.lock
vms
vms/APP
vms/APP/lock
vms/APP/logs
vms/APP/logs/links.log
vms/APP/logs/network.jsonl
vms/APP/logs/ports.log
vms/APP/logs/proxy.log
vms/APP/run
vms/APP/run/ca
vms/APP/run/ca/ca.key
vms/APP/run/ca/ca.pem
vms/APP/run/ca/lock
vms/APP/run/ca/next.key
vms/APP/run/ca/next.pem
vms/APP/run/known_hosts
vms/APP/run/links.json
vms/APP/run/links.pid
vms/APP/run/ports.forwarded
vms/APP/run/ports.lock
vms/APP/run/ports.pid
vms/APP/run/ports.ssh-hold
vms/APP/run/ports.status
vms/APP/run/proxy-child.pid
vms/APP/run/proxy.confined
vms/APP/run/proxy.json
vms/APP/run/proxy.pid
vms/APP/run/proxy.status
vms/APP/run/secrets.json
vms/APP/run/secrets.policy
vms/APP/run/started
vms/APP/vm.json
vms/DB
vms/DB/lock
vms/DB/logs
vms/DB/logs/network.jsonl
vms/DB/logs/ports.log
vms/DB/logs/proxy.log
vms/DB/run
vms/DB/run/ca
vms/DB/run/ca/ca.key
vms/DB/run/ca/ca.pem
vms/DB/run/ca/lock
vms/DB/run/ca/next.key
vms/DB/run/ca/next.pem
vms/DB/run/known_hosts
vms/DB/run/ports.forwarded
vms/DB/run/ports.lock
vms/DB/run/ports.pid
vms/DB/run/ports.ssh-hold
vms/DB/run/ports.status
vms/DB/run/proxy-child.pid
vms/DB/run/proxy.confined
vms/DB/run/proxy.json
vms/DB/run/proxy.pid
vms/DB/run/proxy.status
vms/DB/run/secrets.json
vms/DB/run/secrets.policy
vms/DB/run/started
vms/DB/vm.json