All my work / Distributed systems · by Ravindra Sawant
Burrow
Minimal Linux container runtime in Go: namespaces, pivot_root, cgroup v2 limits.
Verified 2026-11-28; CI re-runs the acceptance tests on every push.
The problem
Containers are ordinary processes with namespaces, cgroups and a different root filesystem - not lightweight VMs. This small Go runtime launches a trusted workload in new PID/mount/UTS/IPC/network namespaces with cgroup v2 limits, verified in a disposable Ubuntu VM.
What I found
- The child blocks on a sync pipe until the parent has attached it to its cgroup, so limits apply from the first instruction; injected mount or cgroup failures exit 125 and the workload never runs.
- On the first real run the runtime's own symlink-safe path resolver refused to start: the lab script had turned busybox into a symlink to itself.
- Startup p95 was 12 ms on a busybox rootfs; a 16 MiB memory limit OOM-killed a fixture; 50 run/interrupt cycles left zero cgroups or processes behind.
Architecture
minirun run ─► config.Validate (paths clean/absolute, limits, argv[0] absolute — no shell)
─► preflight: Linux ≥ 5.4, euid 0, cgroup2fs, delegated lab subtree (+cpu +memory +pids), namespaces,
rootfs inside lab (symlinks resolved), command exists in rootfs ── any FAIL ⇒ exit 125, nothing runs
─► mkdir <lab cgroup>/minirun-<id>; write memory.max, memory.swap.max, pids.max, cpu.max
─► exec /proc/self/exe init (CLONE_NEWPID|NEWNS|NEWUTS|NEWIPC|NEWNET, Pdeathsig, empty env)
fd3 = config JSON, fd4 = sync pipe, fd5 = setup-error pipe
─► write child pid to cgroup.procs ─► send 'G' on fd4 (child blocks until then)
child init (PID 1) ─► mount --make-rprivate / ─► bind rootfs ─► pivot_root(rootfs, .oldroot) ─► umount -l old root
─► mount proc, tmpfs /dev (+ mknod null/zero/random/urandom), tmpfs /tmp, optional ro remount
─► sethostname ─► drop capability bounding + ambient sets, no_new_privs ─► CLOEXEC all fds ≥ 3
─► start workload as uid/gid 65534 with no supplementary groups, own process group
─► forward signals to the workload group; reap every child (Wait4(-1)); kill(-1) leftovers
parent ─► forward SIGINT/TERM/HUP/QUIT; timeout ⇒ SIGTERM then cgroup.kill after 2 s; on exit cgroup.kill + wait
empty ─► record stats + state ─► rmdir cgroup (never recursive deletion)
- Network: a fresh network namespace with nothing configured ⇒ no external connectivity.
- Failure injection (
--inject-fail mount|cgroup) proves the workload never executes after a failed setup step. - Threat limitations: no seccomp/LSM/user namespaces; root in the VM is required; treat it as a learning tool.
Requirements → tests
| Req | Pri | Requirement | Proven by | Status |
|---|---|---|---|---|
| FR-01 | P0 | Trusted rootfs, argv, hostname, memory/PID/CPU limits; validate paths, kernel features, privileges; fail closed | T01, T05 | pass |
| FR-02 | P0 | New PID/mount/UTS/IPC/net namespaces; private mounts; pivot_root; isolated proc; no external network | T02 | pass |
| FR-03 | P0 | Dedicated cgroup v2 under delegated subtree; memory.max/pids.max/cpu.max; attach before workload runs | T03, T04 | pass |
| FR-04 | P0 | Non-root workload, dropped capabilities, no_new_privs; signal forwarding, reaping, exit status, cgroup removal | T02, T04, T05 | pass |
| FR-05 | P1 | inspect/stats from cgroup metrics; bounded timeout; read-only rootfs with writable tmpfs | T03, T04 | pass |
| Test | What it proves | Result |
|---|---|---|
| T01 | doctor rejects unsupported host / absent delegated cgroup; invalid rootfs/limits rejected before launch (unit + VM) | pass |
| T02 | Benign fixture shows isolated hostname, PID 1 namespace, small /proc, no host sentinel, uid 65534 (VM) | pass |
| T03 | Bounded memory fixture hits memory.max (oom_kill), PID limit reached, CPU loop throttled (VM) | pass |
| T04 | Injected mount/cgroup failures never execute the workload; timeout signals and reaps descendants (VM) | pass |
| T05 | 50 run/exit/interrupt cycles leave no cgroups/processes; path traversal + symlink escape rejected (unit + VM) | pass |
Benchmark
| Target (hypothesis from the spec) | Goal | Actual | |
|---|---|---|---|
| startup p95 < 250 ms for a prebuilt local rootfs (provisional) | < 250000 us | 10639 us | met |
| zero leftover cgroups after the run | 0 | 0 | met |
startup_p50_us= 8206startup_p95_us= 10639baseline_p50_us= 850baseline_p95_us= 946
vm run · 2026-11-29T03:50:57Z
Design questions
What is a container, really?
An ordinary process placed in new namespaces (what it can see) and cgroups (what it can use), with a different root filesystem and reduced privileges - not a VM.
Why pivot_root instead of chroot?
pivot_root swaps the mount namespace's root and lets you detach the old root entirely; chroot only changes path resolution and is escapable by a privileged process.
Why does PID 1 inside the namespace matter?
PID 1 must reap orphaned zombies and handle signals (default actions are ignored for PID 1); without a proper init, children leak and SIGTERM may do nothing.
Why attach the cgroup before exec?
Otherwise the workload (or its first fork) briefly runs unconstrained; the sync-pipe handshake guarantees limits apply from the first instruction.
What would make it a security boundary?
User namespaces, seccomp, LSM (AppArmor/SELinux), read-only rootfs, masked /proc paths, dropped capabilities audited end-to-end - and even then, kernel attack surface remains; use gVisor/VMs for untrusted code.
Limitations
- Not OCI-compatible; no images, overlayfs, network bridges, seccomp or user namespaces
- Isolation demo only - never run untrusted code
- Needs root in a disposable Linux VM; on macOS only the portable unit tests run
Run it
git clone https://github.com/ravirs/burrow.git && cd burrow
bash vm/from-host.sh demo # demo
bash vm/from-host.sh test # test
bash vm/from-host.sh bench # benchMore systems I've built from scratch
Storage & data systems
- Strata LSM-tree key-value storage engine: WAL, SSTables with Bloom filters, atomic manifest, compaction
- Tidelog Kafka-style durable partitioned log broker: CRC'd records, offsets, generation-fenced consumer groups
- Floe Iceberg-style table format: immutable Parquet, manifests, snapshots, time travel, compare-and-swap commits
- Flint Spark-style batch engine: lazy lineage, stage planning, shuffles, broadcast and salted skew joins
- Watermark Event-time stream processor: windows, watermarks, lateness, exactly-once checkpoints
- Warden Data governance catalog: explainable grants, row filters, column masks, lineage impact
- SnapshotDB MVCC transaction engine: snapshot isolation, the write-skew anomaly, a serializable mode
AI infrastructure
- Nearline HNSW-style vector search index from scratch, measured against exact search
- KVPager Paged KV cache with copy-on-write forks and prefix reuse (PagedAttention-style)
- Batchwise LLM inference scheduler simulator: static vs continuous vs chunked-prefill batching
- Steadyhand Durable AI agent runtime: allowlisted tools, approvals, budgets, crash recovery, replay
- Toolgate Model Context Protocol gateway: curated tools, signed identity, tenant policy, approvals, audit