Architecture

BuildWarden executes builds inside isolated environments while recording a tamper-evident ledger of all network activity. Five drivers implement the same lifecycle on different platforms:

DriverFlagPlatformIsolation mechanism
Container--driver container (default)Any Docker/Podman hostiptables sidecar
QEMU--driver qemumacOS, Linux, WindowsTopological (separate VM)
VZ--driver vzmacOS/arm64 onlyTopological (socketpair, no vmnet)
Hyper-V--driver hypervWindowsTopological (separate VM, host-only NAT)
Firecracker--driver firecrackerx86_64 Linux with KVMTopological (microVM on a per-slot host bridge)

All four share a single runtime model: warden (the orchestrator) boots an unconfigured relay, claims it with the build's configuration, then boots the build guest.

relay boots unconfigured --> warden claims it (tunnel + config) --> build guest boots --> warden-io initialize --> fetch build script --> run with heartbeats --> report exit

The relay keeps no build state on disk and mounts nothing. It streams every output (artifacts, captures, the ledger, build console) to, and pulls every input (the build script, the bootstrap config, context files) from, a collector that warden runs on the host. The relay never dials the host and warden never listens on any network: the collector is served to the relay over a tunnel warden opens on the relay's claim port.

Every driver bootstraps the build environment the same way: isolate it, deliver the executor, start it, and let warden-io initialize pull everything else from the relay. The model, its invariants and the one remaining deviation are in docs/development/bootstrap.md; How It Works walks through each component as pseudocode.

High-level topology

                    Container driver
                    ~~~~~~~~~~~~~~~~
  +-----------+     isolated Docker network (100.64.x.0/29)     +-----------------+
  |   Relay   |<-------- only allowed connection -------------->| Build Container |
  | container |                                                 |  (FROM image)   |
  +-----+-----+                                                 +-----------------+
        |                                                        in the holder's
        v  external                                              netns, isolated
                                                                 before it starts
   [ Internet ]


                    QEMU driver
                    ~~~~~~~~~~~
  +------------+     Unix socket pair     +------------+
  |  Relay VM  |<------------------------>|  Build VM  |
  |  (Alpine)  |   sole network path      | (cloud img)|
  +-----+------+                          +------------+
        |
        v  external
   [ Internet ]


                    VZ driver
                    ~~~~~~~~~
  +------------------+     socketpair (raw Ethernet)     +-------------+
  | Relay (host proc)|<--------------------------------->|  macOS VM   |
  | gvisor netstack  |    sole network path              | (IPSW img)  |
  +--------+---------+                                   +-------------+
           |
           v  external
      [ Internet ]


                    Hyper-V driver
                    ~~~~~~~~~~~~~~
  +------------+     Private build switch     +-------------+
  |  Relay VM  |<---------------------------->|  Build VM   |
  |  (Alpine)  |   sole network path          | (Windows)   |
  +-----+------+                              +-------------+
        |  Internal NAT switch
        v  external
   [ Internet ]

In every case the build environment has exactly one network path: through the relay. The relay proxies allowed traffic to the internet and records it in the ledger.

Components

Orchestrator (cmd/warden/)

Runs on the host. Responsibilities:

  1. Resolve the build script (translate a Dockerfile on the host, or stage build.sh / build.ps1)
  2. Start a collector that serves the build script, the bootstrap config and the context, and receives all outputs
  3. Prepare and start the relay, unconfigured (build container image, cross-compile binary, or launch host process / boot relay VM)
  4. Claim the relay: open the collector tunnel, push the build config, receive the relay identity (MITM CA cert + ledger public key)
  5. Isolate the build environment (holder + iptables sidecar, or topological)
  6. Deliver warden-io into it and start it; from then on, only watch
  7. Wait for build completion (heartbeats, exit code) or failure (hung guest, dropped tunnel)
  8. Finalize output (optional zstd compression)
  9. Teardown

The host-side build logic (driver.Session) is shared by every driver; drivers differ only in how they start the relay and the build guest, and in the claim address they hand the session.

Collector (collector/ library, cmd/collector/ binary)

The protocol between the relay and the collector is specified in two documents, the outputs a collector stores and the inputs and signals it serves; the specifications are the contract, and the seams page links them at the version this repository implements. This section explains it.

The collector is the relay's single output path and the source of its build inputs, so the relay needs no shared filesystem. The relay authenticates every request with a bearer token. Its endpoints, what each takes and what each answers, are listed in the two specifications.

The ledger is streamed throughout the build, so even a relay that dies mid-build leaves a truncated-but-verifiable ledger. cmd/collector is the standalone host side for third-party orchestrators: it claims an already-running relay, serves inputs, lands outputs, and exits with the build result.

Claim protocol (relaycfg/)

The claim is specified in its own document; the specification is the contract, and the seams page links it at the version this repository implements. This section explains it.

A relay boots unconfigured and listens for a single claim on port 8301. The orchestrator:

  1. Opens a tunnel (POST /v1/tunnel on the claim port, upgraded to a raw connection) and serves the collector to the relay over it as HTTP/2.
  2. Pushes the build config (POST /v1/claim): collector URL (the tunnel), collector bearer token, capture mode, upstream CA PEMs, system-CA flag, and an optional environment record: a typed descriptor of what the build runs on (the container image manifest, or for VM drivers a vm-disk-chain/v1 descriptor of the boot disks and per-build seed files; see the ledger spec's Environment Record). The relay signs it as the ledger's first record and lands the payload as <output>/environment.json. The VM drivers also send the build link (below).
  3. Receives the relay identity: the ephemeral MITM CA certificate (written to <output>/ca.cert.pem) and the ledger's Ed25519 public key.

The claim listener closes after one claim, before the build guest boots. Pushing the config (rather than having the relay fetch it) keeps the relay ignorant of host topology: any setup where the host can reach the claim port works, with no host listener or firewall rule, relays can be started warm and claimed later, and concurrent relays never race for a fixed config endpoint. An optional per-instance claim token (WARDEN_CLAIM_TOKEN) stops another local process from claiming a warm relay first.

The build link. A claim may carry build_link, the private segment between the relay and the build environment:

"build_link": {"prefix": "100.127.255.252/30",
               "relay":  "100.127.255.253",
               "guest":  "100.127.255.254"}

How a relay validates build_link, and what each mode does with it or without it, are the claim specification's requirements, linked from the seams page. warden itself is stricter than a relay requires: it sends only a /30 link, disjoint from its own ranges.

A relay refuses a claim it cannot apply (a link another interface already uses, a field its mode does not take) with 400 and stays claimable: its start step returns an error wrapping relaycfg.ErrRefused. A relay that predates the field refuses a claim carrying it (unknown field "build_link"), which warden turns into a fix naming the driver's rebuild.

Ordering rule. A relay replies to a claim only after its build segment is configured: the reply is written after the mode's start step returns, and the step addresses the segment and starts its DHCP responder. Every VM driver boots the build guest only after the claim returns.

Relay (relay/ library, cmd/relay/ binary)

The relay is the network gateway for the build environment. Core services:

  • MITM HTTPS proxy — intercepts TLS using an ephemeral CA
  • DNS server — resolves cwd and artifacts to itself, forwards all else to its upstream resolvers in order: the claim's upstream_dns (every VM driver sends [vm] dns or the host's), else the relay's own resolv.conf
  • Build-input serving — serves the build script and context to the guest, pulling them from the collector
  • Artifact store — accepts uploads via http://artifacts/<name>, streamed to the collector
  • Ledger writer — records requests with chained Ed25519 signatures, streamed to the collector
  • Control plane — health check, CA distribution, heartbeat, exit reporting
  • Fairness scheduler — prevents single-origin starvation of concurrent requests

cmd/relay/ is a thin main that selects a mode:

ModeFlagUsed byBehavior
container--mode=containerContainer driverBinds ports directly on container interface
vm--mode=vm [-build-if NAME]QEMU, Firecracker, Hyper-V driversBinds ports directly inside the relay VM; addresses the build interface from the claim and serves the build VM's DHCP lease on it
host--mode=host --fd=NVZ driverReads raw Ethernet from FD via gvisor netstack, built from the claim's build link (--subnet without one); SSRF filtering active

warden-io (cmd/warden-io/)

The sole agent inside the build environment. Subcommands:

  • initialize — configure DNS, wait for relay, install the CA per the bootstrap config, apply the baseline (Java truststore, bazelrc, CA and default env), fetch the build script, run it, report exit
  • fetch — download a file from the relay context endpoint
  • post — upload an artifact to the relay
  • trust — install the ephemeral CA into system trust stores

Platform-specific initialization handles network configuration differences between Linux (containers, VMs) and macOS (VZ).

Ledger (ledger/)

Binary format with chained Ed25519-SHA512 signatures. Magic BLDL, version 0x01. CBOR metadata. Record types: open, checkpoint, close, artifact. The library provides write (single-writer via channel), read, and verification.

Driver interface (driver/)

Each driver implements a common interface covering:

  • Environment preparation (image pull, VM boot)
  • Relay startup (mode-specific)
  • Build environment startup
  • Network isolation application
  • Teardown

Driver details

Container driver

warden build .
  |-- Translate the Dockerfile to build.sh (COPY expanded against the context)
  |-- Start a collector serving the build script, bootstrap config + context
  |-- Create isolated Docker network (100.64.x.0/29); check it against the runtime's
  |     networks and take the next /29 if another network overlaps it
  |-- Start relay container, unconfigured, with its claim port published on 127.0.0.1
  |-- Claim the relay (tunnel + build config); write ca.cert.pem
  |-- Start the namespace holder on the network (no capabilities)
  |-- Run the iptables sidecar in the holder's netns (applies rules, exits)
  |-- Create the build container from the FROM image in the holder's netns,
  |     entrypoint warden-io initialize --gateway=<relay_ip> (not started)
  |-- Copy warden-io in (tar stream, mode 0755)
  |-- Start it: warden-io initialize runs as PID 1
  |-- Wait for the completion report (or the container exiting without one)
  '-- Teardown containers + network

Network isolation: the build's network namespace belongs to a holder container that runs nothing. A privileged one-shot sidecar applies iptables rules to it that allow traffic only to the relay IP, then exits, all before the build container exists. The build container has no CAP_NET_ADMIN.

QEMU driver

warden build .
  |-- Cross-compile relay + warden-io for linux
  |-- Start a collector serving the build script + context
  |-- Prepare relay VM (Alpine direct-boot; the current relay binary is appended to the prebuilt initramfs as a second cpio at /sbin/relay)
  |-- Prepare build VM (cloud image QCOW2 + cloud-init seed ISO with warden-io)
  |-- Boot relay VM, unconfigured, with its claim port forwarded to a free 127.0.0.1 port (user-net hostfwd)
  |-- Claim the relay (tunnel + build config); write ca.cert.pem
  |-- Boot build VM (sole network path is the relay VM)
  |-- warden-io initialize runs via cloud-init
  |-- Wait for exit
  '-- Teardown VMs

The prebuilt initramfs (tools/relay-vm/build-initramfs.sh) only needs rebuilding when the init script or the base image changes; the relay binary is appended fresh each build.

Network isolation is topological: the build VM's only NIC connects to the socket pair whose other end is the relay VM. No host networking, no bridge. Accelerator selection: HVF (macOS), KVM (Linux), WHPX (Windows), TCG (fallback).

VZ driver

warden build .
  |-- Prepare macOS disk image (warden image prepare: personalize, inject warden-io)
  |-- Start a collector serving the build script + context
  |-- Start relay as host process on 127.0.0.1:<free port>, unconfigured
  |     '-- gvisor netstack processes raw Ethernet frames from socketpair
  |-- Claim the relay (tunnel + build config); write ca.cert.pem
  |-- Boot macOS VM via Virtualization.framework
  |     '-- Single NIC: VZFileHandleNetworkDeviceAttachment on socketpair
  |-- warden-io initialize runs on first boot (system daemon)
  |-- Wait for exit
  '-- Teardown VM + relay process

Network isolation is topological: the VM has one network interface backed by a socketpair. The other end is the relay process using gvisor netstack to parse Ethernet frames in userspace. No vmnet, no iptables.

Image preparation (warden image prepare --driver vz) is a separate step:

  1. Restore IPSW to disk image
  2. Personalize with Apple signing server
  3. Install warden-io binary and system daemon plist
  4. Result is a reusable prepared image

Hyper-V driver

warden build --driver hyperv .
  |-- Preflight: the relay boot VHDX's stamp, the NAT read back from the host
  |     (prefix, host IP; one overlapping the build link refused), the relay's
  |     resolvers ([vm] dns, or the host's default route interface's)
  |-- Start a collector serving the build script + context
  |-- Under a host lock: allocate the relay's NAT address (and, durable, a free
  |     slot switch); write its seed ISO (address, prefix, gateway, claim token)
  |-- Boot relay VM (its /sbin/relay is baked into a UKI boot disk), unconfigured
  |     '-- Reachable on its per-build NAT address, port 8301, with the token
  |-- Claim the relay (tunnel + build config + resolvers); write ca.cert.pem
  |-- Boot build VM on the relay's switch (sole network path is the relay VM)
  |-- warden-io initialize runs on first boot, on the relay's DHCP lease
  |-- Wait for exit
  '-- Teardown VMs

Network isolation is topological, like QEMU. The relay VM and build VM sit on a Private build switch; the relay reaches upstream through an Internal NAT switch. The claim endpoint is only on the host-only NAT switch, so the build VM cannot reach it, and it takes only the per-build token. One-time host setup (warden setup --driver hyperv) creates the durable NAT switch and its slot switches (--slots, default 4), so durable builds run concurrently, one per slot; the relay VM's /sbin/relay is baked into its UKI boot disk by tools/relay-vm/hyperv/build.sh, and its per-build values arrive on a WARDENRELAY seed ISO (see tools/relay-vm/README.md).

Firecracker driver

warden build --driver firecracker .
  |-- Preflight: /dev/kvm, firecracker >= v1.17.0, boot assets, a slot, an off-host resolver
  |-- Stage the build script; record inputs
  |-- Prepare build VM: raw rootfs (converted once, reflink-copied per build) + CIDATA
  |     seed on a read-only drive, or the direct-boot initramfs with warden-io appended
  |-- Start a collector serving the build script + context
  |-- Take a free network slot (host lock); kill VMMs a dead warden left on it
  |-- Boot relay VM (firecracker --no-api; relay appended to the x86_64 initramfs),
  |     unconfigured, on the slot's bridge and upstream TAP
  |-- Claim the relay at the slot's upstream address, port 8301; write ca.cert.pem
  |-- Boot build VM (its only NIC on the slot's bridge)
  |-- warden-io initialize runs via cloud-init, or the direct-boot launcher
  |-- Wait for exit (a completion may land up to 10 s after the build VM exits)
  '-- Teardown VMs, the rootfs copy and the slot's pid file; release the slot

Network isolation is topological, like QEMU, but the link is a host bridge per slot whose only other port is the relay; the bridge has no address, and a bridge-family nft table and the WARDEN-FC iptables chains keep build segments, other slots and other local users apart (see Network Isolation). sudo warden setup --driver firecracker makes the slots once per boot, so builds run unprivileged.

Lifecycle (common)

warden build .
  |-- Resolve the build script (translate Dockerfile, or stage build.sh / build.ps1)
  |-- Start a collector serving the build script + context
  |-- Start relay (unconfigured)
  |-- Claim the relay (open tunnel, push config, receive CA + ledger key)
  |-- Isolate the build environment
  |-- Deliver warden-io and start the environment
  |-- warden-io initialize:
  |     |-- Configure network (point DNS at relay)
  |     |-- Wait for relay health check (http://<relay>:8300/health)
  |     |-- Fetch the CA and the bootstrap config; install the CA
  |     |-- Apply the baseline (Java truststore, bazelrc, CA and default env)
  |     |-- Fetch the build script (http://artifacts/build-script)
  |     |-- Run build script with periodic heartbeats
  |     '-- Report exit code to the relay control plane
  |-- Outputs (ledger, artifacts, console) stream to the collector throughout
  '-- Teardown

Communication paths

The build environment talks only to the relay. The endpoints it sees, the relay's guest API, are specified in their own document, linked from the seams page.

The relay's control plane binds :8300; artifacts and cwd are reserved hostnames that resolve to the relay. The relay in turn serves build inputs from, and streams outputs to, the host collector over the /v1/* API (a separate plane the build environment never sees).

External HTTPS traffic is transparently proxied (MITM) and recorded in the ledger. External HTTP traffic is proxied and recorded without interception.

Network isolation

See Network Isolation for iptables rule details (container driver). For the QEMU, VZ, and Hyper-V drivers, isolation is topological: the build environment physically cannot reach anything except the relay.