Project Structure

buildwarden/
├── cmd/
│   ├── relay/              # Relay binary (thin mode-based main)
│   │   ├── main.go            # CLI flags, mode detection, per-mode claim start steps
│   │   ├── mode_host.go       # Host mode: FD ingress via gvisor netstack, built at the claim
│   │   ├── vmlink.go          # vm mode: address the build interface from the claim
│   │   ├── buildif_linux.go   # ...over rtnetlink (stub elsewhere: vm mode needs Linux)
│   │   ├── dhcp.go            # The stateless DHCP answer both modes share
│   │   ├── dhcp_vm.go         # vm mode's responder; dhcp_vm_linux.go binds it to the build interface
│   │   ├── chanlistener.go    # Channel-based net.Listener (for host mode)
│   │   ├── ingress_fd.go      # gvisor netstack: Ethernet frames → TCP/UDP
│   │   └── ingress_dhcp.go    # Host mode's DHCP framing around dhcp.go
│   ├── warden-driver-container/ # The container driver's binary: drivercmd.Main(container.Driver())
│   ├── warden/             # Host binary (CLI + driver dispatch)
│   │   ├── main.go            # Cobra commands: build, shell
│   │   ├── config.go          # Config loading (TOML), runtime detection, validation
│   │   ├── host.go            # warden doctor, setup, hyperv service
│   │   ├── image.go           # warden image prepare / list (all drivers)
│   │   ├── inspect.go         # warden inspect (subcommand registration)
│   │   ├── inspect_impl.go    # warden inspect (implementation)
│   │   ├── clean.go           # warden clean
│   │   └── output.go          # Colored terminal output
│   ├── collector/          # Standalone collector (third-party orchestrators)
│   │   └── main.go            # Claim a running relay, serve inputs, land outputs
│   ├── warden-io/          # Build-environment agent binary
│   │   ├── main.go            # Subcommands: initialize, fetch, post, trust
│   │   ├── initialize.go      # Full init: network, CA + bootstrap config, baseline, script, heartbeats
│   │   ├── baseline.go        # Always-on baseline: Java truststore, bazelrc, CA and default env
│   │   ├── jks.go             # Minimal JKS writer (matches keytool byte for byte)
│   │   ├── trust_linux.go     # Exclusive system trust, OpenSSL subject hash
│   │   ├── platform_darwin.go # macOS: keychain CA install, network config
│   │   ├── platform_linux.go  # Linux: CA install, resolv.conf
│   │   └── platform_windows.go # Windows: cert store, network config
│   ├── warden-pause/       # Container driver's namespace holder (blocks until signalled)
│   │   └── main.go
│   └── warden-vmnet/       # macOS vmnet.framework helper (C, for future use)
│       └── main.c
├── relay/                  # Relay library (core logic)
│   ├── relay.go               # Config, Start(), MITM proxy, input/artifact handlers
│   ├── collector_client.go    # Streams outputs to / pulls inputs from the collector
│   ├── dns.go                 # DNS server (UDP, forwards upstream)
│   ├── proxy.go               # HTTP/HTTPS MITM, SSRF filter, TLS cert generation
│   ├── ledger.go              # Ledger writer (single-writer channel pattern)
│   ├── heartbeat.go           # Forwards guest heartbeats to the collector; completion
│   ├── controlplane.go        # Control plane HTTP (/health, /ca.pem, /v1/output, /v1/complete)
│   ├── capture.go             # Payload capture (streamed to the collector)
│   └── fair.go                # Fair scheduling for concurrent connections
├── bootstrap/              # The bootstrap config the executor fetches (trust policy)
│   └── bootstrap.go
├── collector/              # Collector library (relay's single output path + input source)
│   ├── collector.go           # HTTP handler: artifacts, captures, ledger, output, inputs
│   ├── signals.go             # ready / heartbeat / complete / status signalling
│   └── paths.go               # Shared artifact/context path safety rules
├── relaycfg/               # Claim protocol between orchestrator and relay
│   ├── relaycfg.go            # Serve/Claim: push config, return relay identity
│   ├── buildlink.go           # The claim's build_link and its validation
│   └── tunnel.go              # Host-initiated tunnel carrying the collector (HTTP/2)
├── driver/                 # The kit for drivers, and the drivers; warden's session
│   ├── driver.go              # BuildRequest, BuildResult
│   ├── host.go                # Start, Host, RelayStarted: the build dialogue's Go types
│   ├── drivercmd/             # The driver contract for a Go driver: Main, Call, Setting, Resolve
│   ├── relaysource/           # Where a relay comes from: Bundled, Path, Image, Relay.Verify
│   ├── session.go             # Shared Session: collector, claim, wait, output finalize
│   ├── hostlink.go            # Build-link checks every VM driver runs: host overlap, launcher stamps
│   ├── buildlink/             # The VM build link: default, parse, checks, claim and boot-arg renders, stamps
│   ├── compress.go            # Zstd compression of ledger + CA cert (all drivers)
│   ├── hostutil.go            # Host-side helpers
│   ├── subnet.go              # Address constants, utilities
│   ├── container/             # Container driver (iptables isolation)
│   │   ├── command.go            # Driver(): probe, run, reap, doctor, clean, attach
│   │   ├── runtime.go            # The runtime: finch, podman or docker, and detection
│   │   ├── container.go          # Run/Attach: holder, sidecar, create, copy, start
│   │   ├── network.go            # The per-build network: allocation and its check
│   │   ├── images.go             # Holder + sidecar images: by digest, or built for dev
│   │   ├── images/               # holder.Containerfile, netns.Containerfile
│   │   └── environment.go        # OCI manifest extraction, environment record
│   ├── qemu/                  # QEMU driver (cross-platform VM)
│   │   ├── driver.go             # Run: prepare, boot relay VM, boot build VM, wait
│   │   ├── vm.go                 # QEMU subprocess management (relay VM + build VM args)
│   │   ├── seedfat.go            # FAT seed image for Windows guests
│   │   ├── windows.go            # Windows guest support
│   │   ├── winacq.go             # Windows media acquisition + unattended install
│   │   └── autounattend.go       # Autounattend.xml generation
│   ├── vz/                    # VZ driver (macOS Apple Silicon)
│   │   ├── driver.go             # StartBuild: host relay, boot macOS VM, wait
│   │   ├── image.go              # IPSW restore, image preparation, personalization
│   │   ├── network.go            # Socketpair networking for build VM
│   │   ├── vm.go                 # VM lifecycle helpers
│   │   ├── vz_darwin_arm64.go    # Virtualization.framework CGo bindings (darwin/arm64, cgo)
│   │   ├── vz_darwin.h           # Objective-C header
│   │   ├── vz_darwin_arm64.m     # Objective-C implementation
│   │   └── vz_stub.go            # Stub for every build without the bindings (incl. darwin/arm64 without cgo)
│   ├── hyperv/                # Hyper-V driver (Windows)
│   │   ├── driver.go             # StartBuild: boot relay VM + build VM, claim, wait
│   │   ├── setup.go              # warden setup: durable switches + NAT
│   │   ├── doctor.go             # warden doctor preflight
│   │   ├── service.go            # Privileged helper service (network standup)
│   │   ├── evalimage.go          # Windows Server eval VHD fetch + pin
│   │   └── relayvm.go            # Relay VM lifecycle
│   ├── firecracker/           # Firecracker driver (x86_64 Linux with KVM)
│   │   ├── driver_linux.go       # StartBuild: slot, relay VM + claim, build VM, wait, teardown
│   │   ├── deliver_linux.go      # Both delivery paths: raw rootfs + CIDATA seed, or direct boot
│   │   ├── vm.go, vm_linux.go    # Firecracker config JSON; --no-api process start, pids
│   │   ├── slots.go              # Slot naming, addresses, the setup command list
│   │   ├── slots_linux.go        # Slot locking and stale-VMM reaping
│   │   ├── setup.go, doctor.go   # warden setup / doctor --driver firecracker
│   │   ├── posture.go            # Firewall posture refusals, upstream resolver selection
│   │   ├── images.go, gpt.go     # qemu-img gate + raw conversion cache; GPT root finder
│   │   ├── wait.go               # Exit ordering: build VM exit, completion grace
│   │   ├── clean.go              # warden clean: orphaned VMMs, stale work dirs
│   │   └── driver_other.go       # Stub for non-Linux hosts
│   ├── linuxguest/            # Linux guest family (qemu, firecracker)
│   │   ├── seed.go               # Cloud-init NoCloud seed (runcmd tail per driver)
│   │   ├── seediso.go            # ISO9660 seed image builder
│   │   └── images.go             # Cloud image resolution + download + caching
│   ├── relayvm/               # Relay VM lifecycle shared by qemu and firecracker
│   │   ├── assets.go             # Boot asset lookup (beside warden, then the tools output)
│   │   └── initrd.go             # Append a binary to a prebuilt initramfs as a cpio
│   └── script/                # Dockerfile-to-shell-script translator (every driver)
│       └── translate.go          # COPY expanded against the context on the host
├── conformance/
│   └── driver/                # The driver contract's suite (driver-conformance), the reference
│                              #   fake (warden-driver-fake) and stubrelay
├── ledger/                 # Shared library: wire format, reader, verifier
│   └── ledger.go
├── specs/                  # Ledger format specs, versioned (RELAY-05); published in the book
│   ├── README.md             # Index: layout, $id -> file table, $id policy
│   ├── build-ledger/v1.md    # Wire format (prose only)
│   ├── driver-contract/      # The driver contract: v1.md beside v1.schema.json (GLOBAL-08)
│   ├── metadata-<name>/      # A record metadata schema: v<N>.md beside v<N>.schema.json
│   ├── environment-<type>/   # A signed environment payload: v<N>.md beside v<N>.schema.json
│   └── specs_test.go         # Tier-0: relay header, schemas and book mirror agree; seams page refs match the pins
├── tools/
│   ├── conformance/          # Pins of the seam specifications (buildwarden/buildwarden-specs)
│   │   ├── <directory>/          # One Go module per specification: go.mod pins it, a tool directive names its command
│   │   ├── targets/              # Target files: the relay in each mode and as an image, the disk collector
│   │   ├── conformance.sh        # make conformance: every pinned suite against each target
│   │   ├── pin-specs.sh          # make pin-specs: moves the pins and the seams page's refs together
│   │   └── check-pins.sh         # The conformance workflow's pin job: release tags only, no replace line
│   ├── relay-vm/              # Relay VM assets (Alpine + kernel)
│   │   ├── build-initramfs.sh    # Build the prebuilt relay initramfs
│   │   ├── init                  # ONE relay VM init script (qemu, hyperv, firecracker)
│   │   └── hyperv/               # Hyper-V UKI boot-disk build (/sbin/relay baked in)
│   │       └── build.sh
│   ├── firecracker-vm/       # Firecracker boot assets (x86_64)
│   │   ├── build-kernel.sh       # Pinned 6.1 guest kernel (vmlinux) for both VMs
│   │   ├── kernel-required.config # Options that must be built in (checked by a test)
│   │   ├── build-initramfs.sh    # Direct-boot base initramfs (busybox + launcher)
│   │   ├── init                  # Direct-boot launcher (exec warden-io initialize)
│   │   └── slots.sh              # Hand-made slots for debugging (warden setup does this)
│   ├── build-vm/             # Build VM initramfs builder (direct-boot testing)
│   │   ├── build-initramfs.sh
│   │   └── init                  # Build VM init script (exec warden-io initialize)
│   ├── vz-image-prep/        # Standalone VZ image preparation tools
│   │   ├── personalize.go        # 4-phase macOS image prep pipeline
│   │   ├── netfwd.go             # Transparent TCP/UDP forwarder (image prep)
│   │   └── uv-build-test.go      # End-to-end build validation
│   ├── win-image-prep/       # Windows image preparation notes/tools
│   │   └── README.md
│   ├── tier1/                # Tier-1 static checks, run by make lint (own Go module; LINT-02)
│   │   ├── cmd/tier1/            # Entry point: flags, stages, exit codes
│   │   ├── diff/                 # Base, changed paths and lines, Tier1-Allow trailers
│   │   ├── rules/                # Rule index from docs/development/, rules.yaml self-check
│   │   ├── coupling/             # Path-set checks; design front-matter (FLOW-02)
│   │   ├── surface/              # Cobra flags and toml keys at base and HEAD
│   │   ├── analyzers/            # go/analysis passes for the relay and the executor
│   │   ├── golangci/             # Runs golangci.yml on changed lines, maps issues to rules
│   │   ├── rules.yaml            # Every automated rule: check, owner or follow-up
│   │   └── report.schema.json    # The -json output
│   └── workflow/             # Feature-loop tooling (own Go module; FLOW-03, FLOW-18)
│       ├── cmd/wf/               # Queue tool: next step, leases, done-when checks, native gate
│       ├── native/               # Scheduled native sessions: wrapper, installers, permissions, the native-run.sh launcher and their test
│       └── flow18-check.sh       # Sessions stay out of the public repo
├── docs/
│   ├── book/               # mdBook documentation (guide, concepts, contributing)
│   ├── design/             # Design documents: the archive, plus TEMPLATE.md
│   └── development/        # Development standards and process (the rulebook)
├── Dockerfile.relay        # Multi-arch relay container image
├── Makefile                # build, test, lint, codesign
├── .goreleaser.yaml        # Release configuration
├── AGENTS.md               # Agent context: a map into docs/development and the book
└── CLAUDE.md               # Imports AGENTS.md for Claude Code

Package Boundaries

  • cmd/warden/ — Host-side binary. CLI, driver dispatch, config, inspect, image management, doctor/setup. Finds the driver --driver names (a warden-driver-<name> binary, or a driver linked into it: qemu, vz, hyperv, firecracker) and runs every build through one build sequence.
  • cmd/warden-io/ — Build-environment agent, and the only thing the host puts in the build environment. Bootstraps itself from the relay (CA and trust policy, the baseline, the build script), runs the build, fetches context files, posts artifacts. Cross-compiled for linux (containers, QEMU VMs), darwin (VZ macOS VMs), and windows (QEMU and Hyper-V VMs).
  • cmd/warden-pause/ — The container driver's namespace holder: owns the build's network namespace while it is isolated, and does nothing else.
  • cmd/relay/ — Relay binary. Thin mode-based main that selects container/vm/host mode and calls into the relay/ library. Cross-compiled for linux (container/VM relay) or built natively (host-mode relay for VZ).
  • cmd/collector/ — Standalone collector for third-party orchestrators: claims an already-running relay, serves inputs, lands outputs, exits with the build result.
  • relay/ — Relay library. All core logic: DNS, HTTP/HTTPS MITM proxy, ledger writer, control plane, heartbeat, fairness scheduling, capture. Keeps no build state on disk; streams every output to, and pulls every input from, the collector. Used by cmd/relay/ in all modes.
  • collector/ — The host side of the relay's single output path and the source of its build inputs (artifacts, captures, ledger, build output, build script, bootstrap config, context).
  • bootstrap/ — The bootstrap config: the declarative trust policy the executor fetches from the relay (BOOT-05). Policy only; no paths, contents or commands. Run in-process by every driver (driver.Session) and standalone by cmd/collector.
  • relaycfg/ — The claim protocol: a relay boots unconfigured, the orchestrator pushes the per-build config over a host-initiated tunnel and receives the relay's identity (MITM CA cert + ledger key).
  • cmd/warden-driver-container/ — The container driver as a binary that speaks the driver contract; warden finds it beside itself.
  • driver/ — The kit for writing a driver, warden's session (Session: collector, claim, wait, output finalize), and the drivers. A driver is a binary that speaks the driver contract (specs/driver-contract/), or, until each becomes one, linked into warden; either runs through warden's one build sequence.
  • driver/drivercmd/ — The driver contract for a driver written in Go: command dispatch, describe from the Setting declarations, reading the driver's configuration (Resolve), the result file and the run dialogue.
  • driver/relaysource/ — Where a driver's relay comes from: beside the binary or in the source tree, a path or an image the user named, and its verification.
  • conformance/driver/ — The driver contract's conformance suite: its static tier runs under make test, its lifecycle tier with make driver-conformance; the reference fake and stubrelay.
  • specs/driver-contract/ — The driver contract's specification and its machine schema.
  • driver/container/ — Container driver. Namespace holder isolated by the iptables sidecar before the build container exists; build container created with warden-io initialize as its entrypoint; relay as container.
  • driver/qemu/ — QEMU driver. Two-VM topology with cloud images, cross-platform; Linux and Windows guests.
  • driver/vz/ — VZ driver. Host relay with gvisor netstack, macOS build VM.
  • driver/hyperv/ — Hyper-V driver. Two-VM topology with a host-only NAT switch; Windows guests (a Linux guest seed is not yet implemented). Includes host setup, doctor, and the privileged helper service.
  • ledger/ — Shared wire format library. Binary ledger types, reader, verifier. Used by warden inspect and the relay's test suite.
  • specs/ — The ledger format's documents, not code: one wire-format spec per ledger major version and each schema's document beside its machine schema (RELAY-05). docs/book/src/specs/ mirrors it with one-line includes. Its only Go file is a test.
  • specs/specs_test.go — Besides the ledger documents, holds the seams page to the pins: a tier-0 test fails when a row of docs/book/src/concepts/seams.md links a specification at a ref other than the version its module in tools/conformance/ pins.
  • tools/conformance/ — Not part of any binary. Six Go modules, one per seam specification kept in buildwarden/buildwarden-specs, each pinning one version of that specification and naming its conformance command; the root module requires none of them. The pins are moved with make pin-specs and never with go get, and make conformance builds each pinned command from its own module and runs it against each target file in tools/conformance/targets/, which the conformance workflow does on every change to the relay, the disk collector or a pin. See Component seams.

Key Patterns

Runtime model

Every driver follows one sequence: start a collector, boot the relay unconfigured, claim it, isolate the build environment, deliver and start warden-io, and stream everything back through the relay. The step-by-step pseudocode is in How It Works, and the bootstrap rules every driver follows are in docs/development/bootstrap.md.

Single-writer ledger

All ledger writes go through one goroutine (Ledger.loop()), so records are strictly ordered without locks. The rule is RELAY-01 in docs/development/relay.md.

Relay modes

The relay binary detects its mode at startup:

  • Container mode: binds :53, :80, :443, :8300 directly (isolation via iptables)
  • VM mode: same as container but the relay runs in its own Alpine VM, and addresses its build interface from the claim and serves the build VM's DHCP lease there
  • Host mode: receives connections via gvisor netstack on an inherited FD (no port binding on host); SSRF filtering active

Trust and the baseline

warden-io initialize installs the relay CA and a fixed baseline itself, from the relay; support for a new tool goes in cmd/warden-io/baseline.go so it reaches every driver. See Trust and the Build Baseline.

Dynamic subnet allocation

The container driver allocates /29 subnets from 100.64.87.0/24 (CGNAT range), in driver/container: after each create it checks the runtime's networks and yields a /29 another network also has, since the runtime's own overlap check is not atomic across builds of different HOMEs. VM drivers use one build link per build segment, [vm] build_link (default 100.127.255.252/30), defined once in driver/buildlink and delivered per build: the claim for the relay, the seed, kernel command line or the relay's DHCP lease for the guest.

Transparent MITM

The relay generates per-host TLS certificates on the fly, signed by an ephemeral CA. The CA is installed into the build environment's trust store by warden-io during initialization.