All posts

8 min readPost 34

Beyond files: why we refuse to auto-delete WSL distros and images, and how os.Root locks down Docker volume graves

Expanding Obituary beyond local files raises an unforgiving question: where must automatic deletion stop? Across 25–28 November we enforced a four-gate admission rule barring WSL distros and Docker images from auto-cleanup, fought three review rounds of Windows cmd /c quoting to block wsl --unregister, confined Docker volume graves inside Go os.Root, and landed our stdlib-only extres.Provider contract.

On this page
  1. Four admission gates: why WSL distros and Docker images are barred from auto-delete
  2. Guarding wsl --unregister: three review rounds inside Windows cmd /c quoting
  3. Four hidden Docker volume bugs—and 3-hop os.Root grave confinement
  4. Finishing cleanly: a zero-cycle, stdlib-only extres.Provider

Obituary started by attaching countdowns to local files and folders. Yet developer SSDs rarely fill up from kilobyte logs—they fill up from tens of gigabytes of Docker containers, local volumes, images, build caches, and WSL distributions.

Expanding a cleanup tool beyond files carries an obvious trap: treating every space-hogging object as fair game for automatic burial. Whenever an object lacks a lossless, non-overwriting restore path, automation turns from safety net into landmine.

Across 25–28 November we shipped four interlocking pieces of our external-resource foundation: a four-gate admission boundary, real-engine Docker container contract tests with StartedAt drift protection, a three-round Windows cmd /c parser battle guarding wsl --unregister, Go os.Root confinement for Docker volume graves, and a zero-cycle extres.Provider contract.

Systems diagram showing the 4-gate external resource admission boundary across three tiers (Docker/Podman containers allowed auto-lifecycle, Docker volumes explicit + guard, WSL distros and images guard/read-only only) above, and the 3-hop os.Root Docker volume grave confinement pipeline and extres.Provider contract below
The four-gate external-resource admission boundary (top), paired with our 3-hop os.Root volume grave confinement and stdlib-only extres.Provider contract (bottom).

Four admission gates: why WSL distros and Docker images are barred from auto-delete ​

Nothing outside plain files enters Obituary's automatic burial/purge lifecycle unless it satisfies all four prerequisites: verifiable immutable identity, reliable lossless no-overwrite restore, proof that failure keeps the original intact, and an isolated automated E2E suite that never touches host state.

Evaluating real developer resources against those four gates drew sharp lines:

  • Docker containers pass: full 64-character ID, pinned DaemonID, and creation timestamp provide immutable identity; expiry runs docker stop (keeping writable layers intact), obit resurrect runs docker start, and post-retention purge runs docker rm without -v or -f. On 25 November we closed a subtle reclamation bug with StartedAt drift detection (2bfbba6): if a user manually started a buried container during its 7-day retention and later stopped it again, checking only Running=false used to purge it; comparing the recorded StartedAt now detects the newer run and keeps the container as reclaimed. On 27 November we added a five-subtest real-engine E2E suite (TestDockerContainerRealEngine, 4744adf, 9185071) running in CI against Docker Engine 29.10.0. Standalone non-Pod Podman containers follow the exact same model as our planned first non-Docker pilot.
  • Docker local volumes stay explicit + guarded: opt-in only via --docker-volume, archived via a pinned-digest read-only offline Debian container with SHA-256 and Docker event verification, and never overwriting an existing volume on restore.
  • Docker images, build caches, VHDX disks, local VMs, and k8s are forbidden from auto-delete: locally built images and expired private tags have no lightweight lossless offline restore loop, so they remain read-only diagnostics, manual guides, and docker system prune --volumes delete-guard denials.
  • WSL distributions are strictly barred from auto-burial and auto-unregister: wsl --export + wsl --import looks reversible until you inspect what breaks—wsl --import generates a brand-new GUID and loses DefaultUid, Microsoft Store package links, and Windows Terminal profiles; exporting multi-GB tarballs risks filling the host disk; and automated WSL tests would mutate real HKCU\...\Lxss registry keys, violating test isolation.

Guarding wsl --unregister: three review rounds inside Windows cmd /c quoting ​

Because Obituary refuses to auto-delete WSL distributions, the right protection is intercepting wsl --unregister statically in the delete guard—zero subprocess calls, zero registry reads—and pointing users to wsl --export <distro> <backup.tar> (validating distro names against ^[a-zA-Z0-9][a-zA-Z0-9_.-]*$ ≤ 128 chars to avoid untrusted string injection, and halting option parsing at --/-e/--exec so wsl -d Ubuntu -- echo --unregister passes untouched).

Three adversarial review rounds across Bash, PowerShell, and cmd.exe (c4604c5, 36b8a43, 8b22ca5) caught four gnarly Windows shell traps:

  1. 128× exponential PowerShell wrapper blowup: psCommandTailWSLDeletion originally recursed down two paths on the same argument slice, causing 2^7 blowup (63.1× allocation growth) on nested powershell -c wrappers. Removing the double recursion restored strict linear O(depth · N) runtime, guarded by TestWSLWrapperDeepNestingLinear (0.02 s).
  2. cmd.exe /c Rule 2 quoting with trailing redirections: Windows cmd /c strips the first and last " whenever a command begins with " while preserving everything after the closing quote. Checking only trimmed[len-1] == '"' missed cmd /c "wsl --unregister Ubuntu" 2>&1, > nul, and ""C:\Program Files\WSL\wsl.exe" --unregister Ubuntu" 2>&1! Slicing trimmed[1:last] + trimmed[last+1:] closed every trailing-redirection and chained bypass while keeping echo "a && wsl --unregister Ubuntu" clean.
  3. Whitespace-separated @ tokens and glued flags: @ wsl --unregister Ubuntu, @ @ cmd /c "...", /c"wsl...", and /cwsl are all valid CMD invocations. Adding cmdStripAtWords and splitCmdExecFlag (using strings.EqualFold rather than strings.ToLower to avoid UTF-8 byte-length shifts on the Unicode Kelvin sign K) sealed them cleanly.
  4. Locked with two compile-time mutations: detect-wsl-unregister and hook-wsl-unregister-guidance passed across all 26 full-plus-mutation CI jobs.

Four hidden Docker volume bugs—and 3-hop os.Root grave confinement ​

Auditing external-resource coupling revealed Kind == KindContainer checks scattered across 25+ call sites. That duplication hid four real defects affecting KindDockerVolume:

  1. Expired volumes dropped in default graveyard mode: sweepBurials filtered out KindContainer yet missed KindDockerVolume, sending expired volumes into file settlement where Identity == nil refused and dropped them.
  2. Background Tick() routed volumes into file batch purge: purgeContainerRequests similarly missed KindDockerVolume.
  3. sameBurial broke every volume purge with ErrUnsafe: unconditional checks for GraveID != nil && Identity != nil caused beginPurge to reject all Docker volumes.
  4. Tracked volumes broke OnlyNew file registration: RegistrationScope and diagnostics only skipped containers, hitting nil Identity and emitting bogus identity-error events whenever a volume was tracked.

Unifying IsFile() / IsExternal() across 20+ call sites (908eaa0, zero ledger format changes) fixed all four immediately.

Right after those fixes, read-only review flagged a serious blocker: what if a ledger copied from a different OBIT_HOME—or a tampered archive directory replaced by a symlink—pointed b.Grave at a volume.tar outside the active graveyard?

internal/core/lifecycle/volume_archive.go (0f4e097) locks every Docker volume archive operation inside Go's os.Root:

  • Strict path shape: rejects any .. segment, requires basename volume.tar and exact <ID>-<16hex> directory naming, and verifies canonical path equality inside <OBIT_HOME>/graveyard/docker-volumes/<dir>/volume.tar.
  • Three-hop os.OpenRoot + Lstat: walks OBIT_HOME → graveyard → graveyard/docker-volumes → <dir>, rejecting symlinks or Windows reparse points at every hop with ErrUnsafe.
  • Confined verification and removal: openRegularInRoot checks both Lstat and handle Stat for regular files, verifies volume.tar SHA-256, caps volume.tar.json at 1 MiB via io.LimitReader, validates Version == 1, VolumePhase == "removed", and exact ID/Kind/Grave/Digest match, removes files strictly through sub.Remove, and closes sub before removing the empty folder for Windows lock safety.
  • Purge/resurrect mutex and clock-rollback safety: resurrectDockerVolume refuses while PurgeIntent != nil, and interrupted purges with PurgeIntent != nil can safely resume verification and cleanup even if the system clock rolled backward. All 14 new negative tests proved red-first and passed 26/26 full-plus-mutation CI.

Finishing cleanly: a zero-cycle, stdlib-only extres.Provider ​

Only after hardening those real implementations did we extract the abstraction on 28 November: internal/core/extres (a19d1ef) imports only Go's standard library (context, encoding/json, time) with zero dependency on internal/docker:

  • Minimal 6-method Provider: Validate, Inspect, Verify, Bury, Resurrect, and Purge (plus Kind()), modeled on Obituary's safety state machine rather than generic CRUD or brittle runtime plugins.
  • Optional capability interfaces: RetentionPolicy, Doctor, and Discoverer.
  • Zero breaking migration: docker.ContainerProvider and docker.VolumeProvider wrap our battle-tested logic intact (noNameCollision, StartedAt drift, pinned-digest archives, os.Root confinement) while preserving v14–v18 ledger JSON verbatim and enforcing out-of-lock external calls + durable pre-send intents + read-back verification for every external resource to come.

Managing more than files never means loosening deletion discipline—the wider the blast radius, the tighter the admission gates and path confinement have to become.

All posts