All posts

10 min readPost 37

Landing Podman as a second container runtime: zero core ledger changes, two real bugs caught before merge

On 30 November we landed Obituary’s first non-Docker external resource provider (standalone non-Pod Podman containers) on top of the stdlib-only extres contract with zero core reverse imports and v18 ledger compatibility. Along the way, real Ubuntu 26.04 + Podman 5.7.0 CI caught the empty CONTAINER_HOST remote-mode trap, and cross-platform review caught a Podman Machine --url bug that silently dropped SSH credentials.

On this page
  1. Putting the interface to the test, and why scope stops at standalone containers
  2. First lesson from real CI: Podman 5.7 treats empty CONTAINER_HOST="" as remote mode
  3. Cross-platform review caught a blocker: --url drops Podman Machine SSH keys
  4. Five real-engine E2E contracts in an isolated rootless store

Obituary began by attaching countdowns to local files and directories, moving expired items into a restorable graveyard for 7 days before permanent removal. Later we extended that same safety net to Docker containers and local volumes: expired containers stop instead of disappearing, keeping their writable layers intact until retention runs out.

Not every developer machine runs Docker. Switch a workflow to rootless Podman on Linux, or run Podman Machine on Windows and macOS, and throwaway containers spun up during an AI coding session still pile up silently. The architectural catch is obvious: if every new container runtime forces a fresh wave of if kind == "podman" branches through the ledger, lifecycle engine, obit doctor, and background discovery, the codebase collapses under runtime-specific special cases.

On 30 November we plugged our first non-Docker provider (standalone Podman containers) into the standard-library-only internal/core/extres contract (3d6cafc, 9e6677b, 92feb4e, 26253ab, b3c0aab). The interface held up cleanly, and the real payoff came right after: Ubuntu 26.04 CI and a cross-platform code review caught two sharp bugs before merge.

Architecture and bug-fix diagram: top shows internal/podman implementing seven composable extres traits with zero core reverse imports, strict standalone non-Pod admission, and lock-free lifecycle safety; bottom contrasts the Podman 5.7 empty CONTAINER_HOST trap and the Podman Machine --url SSH identity bug with their fixes
Standalone Podman containers wired through extres with zero core reverse imports (top), and two real bugs caught by Ubuntu 26.04 CI and cross-platform review (bottom).

Putting the interface to the test, and why scope stops at standalone containers ​

The only honest test of an abstraction is landing a second implementation with different operational quirks.

internal/podman (kind: "podman-container") implements seven composable traits from internal/core/extres: Provider, RetentionPolicy, IdentityMatcher, RemovalVerifier, AvailabilityScoper, Doctor, and Discoverer. None of core/extres, core/ledger, core/lifecycle, or auto imports internal/podman.

The ledger schema didn't need a version bump either. Tracked items, burials, and proposal candidates reuse optional external credentials alongside externalIntents on the existing v18 ledger, leaving every v14–v18 Docker container and volume record untouched. Mutations keep the exact same safety discipline: write a durable pre-send intent, invoke podman stop / start / rm outside ledger locks, then read back the live container to verify its full 64-character ID and creation time.

The harder design call was setting a strict admission line. Podman users lean heavily on Pods and podman kube play, where multiple containers share a network namespace and an infra pause container. Stopping one member out from under a Pod leaves the group half-broken.

So we enforced one hard product boundary in code: standalone non-Pod containers only.

  • Any container with Pod, PodName, IsInfra, or kube play's IsService set, or launched with --rm (AutoRemove, which makes the engine delete the writable layer as soon as it stops), is rejected across registration, verification, stop, start, removal, and session discovery.
  • Pods, images, volumes, build caches, and Podman Machine VMs are never touched.
  • When podman is not installed or unreachable, session discovery skips quietly, obit doctor reports podman as INFO (never a false warning), and app.ProposalViews scopes live probes via AvailabilityScoper to mark pending proposals podman-unavailable until the engine comes back.

First lesson from real CI: Podman 5.7 treats empty CONTAINER_HOST="" as remote mode ​

Every unit test against our fake Podman subprocess passed locally. Then we ran the five real-engine E2E contracts on Ubuntu 26.04.1 LTS with podman version 5.7.0, and reality hit back on the first run.

To isolate the test containers from host storage, the E2E harness cleared inherited remote variables with t.Setenv("CONTAINER_HOST", "") and t.Setenv("CONTAINER_CONNECTION", ""). Every podman call immediately failed.

The reason is subtle: Podman 5+ checks whether CONTAINER_HOST is present in the environment, not whether it is non-empty. Leaving CONTAINER_HOST= set to an empty string flips local rootless Podman into --remote mode.

That wasn't just a test-harness quirk. Any user shell with a leftover export CONTAINER_HOST="" would break local obit podman in the exact same way. In 92feb4e we closed it on both sides:

  1. Strip empty vars before local execution: cleanEmptyTargetEnv() in internal/podman/target.go removes empty CONTAINER_HOST and CONTAINER_CONNECTION entries from the child process environment whenever Podman runs in local mode.
  2. Real os.Unsetenv in E2E and strict detection in unit tests: The E2E harness switched to os.Unsetenv (restoring prior state on cleanup) and pinned driver = "overlay" in its isolated storage.conf. Later in b3c0aab, the fake Podman test binary switched to os.LookupEnv so a leaked empty variable fails unit tests right away too.

That first real-runner pass shook out two other practical bugs: the E2E suite had to resolve /usr/bin/podman directly instead of inheriting a test stub on PATH (9e6677b, which also split podman_env_test.go out to keep files concise, alongside updating obit doctor's row-count test for the new podman check), and Contract 1 initially advanced the fake clock by 48 hours (short of the 3-day LeftoverLifespan, or 72 hours, on approved container proposals) before 26253ab bumped it to 8 days so expiry stop and pre-retention purge refusal actually fired.

Cross-platform review caught a blocker: --url drops Podman Machine SSH keys ​

With Linux CI completely green, reading internal/podman/target.go from a Windows and macOS perspective uncovered a bug that would have failed outright on Podman Machine (b3c0aab).

On Linux, rootless Podman talks directly to local storage (podman info reports host.serviceIsRemote: false). On Windows and macOS, podman talks to a Podman Machine VM in implicit remote mode (serviceIsRemote: true), with neither CONTAINER_HOST nor CONTAINER_CONNECTION set in the environment. Under the hood, Podman reads the default named system connection to find the SSH key (Identity) and endpoint.

To pin containers to their originating engine, our initial targetFromInfo had a fallback that looked harmless on paper:

go
if base.URL == "" && base.Connection == "" && mode == "remote" && remoteSocket != "" {
    base.URL = remoteSocket
}

Linux CI never exercised that branch, and on Podman Machine it breaks every follow-up action.

info.Host.RemoteSocket.Path is the guest socket path (without connection credentials). Writing it into Target.URL caused every later podman stop, start, and rm to pass --url <remoteSocket.path>. Passing --url bypasses Podman's named connection config, dropping the SSH identity key and machine routing, so expiry stop and resurrection would both fail to connect.

The fix stops inventing --url values and asks Podman for the active default connection instead:

  • When serviceIsRemote is true and no explicit CONTAINER_HOST or CONTAINER_CONNECTION is set, bind() queries podman system connection list --format json (defaultConnection()), picks the entry with Default: true, and pins Target.Connection so follow-up calls pass --connection <name> with SSH identity intact.
  • If no default named connection is reported, Target.URL and Target.Connection stay empty and Obituary pins the remote target by remote://<graphRoot> (or remote://default) plus EngineID, instead of fabricating a broken --url.

Five more edges tightened in the same review pass ​

Walking the state machine line by line in b3c0aab closed five smaller gaps as well:

  1. kube play IsService rejection everywhere: Container.InPod() now checks IsService alongside Pod, PodName, and IsInfra, enforcing refusal across Inspect, Verify, Stop, Start, Remove, and Discover.
  2. CLI.Start also refuses --rm containers: Closing admission parity on the resurrection path.
  3. Never-started containers can actually be purged: A container created with podman create and never started has an empty StartedAt at burial. The first Reclaimed(stopped) returned an error whenever stopped.StartedAt == "", stranding never-started containers forever. Now a zero StartedAt that stays stopped and zero at purge is safely removable, while starting the container even once (running or non-zero StartedAt) marks it reclaimed and protects it.
  4. Re-checking Due inside BeforeSend under the ledger lock: Previously, if a user ran obit extend or obit spare in the window between Verify and launching podman stop, Obituary still stopped the container and had to restart it via compensation. markExternalStopSent now re-checks sameExternalItem and Due(now) inside the lock before spawning stop, skipping cleanly with zero bounce.
  5. Real Validate in auto-discovery tests: Replacing an always-nil stub with podman.ContainerProvider.Validate so malformed IDs and empty payloads are rejected in discovery tests too.

Five real-engine E2E contracts in an isolated rootless store ​

The podman-e2e CI job runs alongside the existing shards. It provisions a private temporary storage.conf, containers.conf, and XDG_* tree, verifies isolation via verifyIsolatedGraphRoot, pulls busybox:1.36, and runs five end-to-end contracts in 49.11 seconds:

  1. Ownership attribution, full-ID pinning, and expiry stop (10.52s): Starts a bind-mounted container, a compose working_dir-labeled container, an unattributed container, and a pre-session container; session finish proposes only the two project-owned ones, expiry stops only those two, and pre-retention obit purge is refused.
  2. Lossless resurrection within retention (7.85s): Writes a sentinel into /tmp/obit-layer.txt, stops on expiry, resurrects with obit resurrect, and reads the intact writable layer back via podman exec.
  3. Purge preserves named volumes and base image (10.12s): Mounts a populated named volume, advances past the 7-day retention window, lets Tick run podman rm (without -v or -f), and verifies the container is gone while the volume sentinel and base image ID remain untouched.
  4. Manual restart, StartedAt drift, and same-name swap protection (15.77s): Tests a buried container restarted and still running, one restarted then manually stopped (StartedAt drifted), and one removed externally and replaced by a fresh container with the same name; Tick protects all three without touching the replacement.
  5. Pod member and --rm refusal (2.94s): Launches both a Pod member and an --rm container bind-mounted to the repo; AddExternal returns ErrPodMember / ErrAutoRemove, and session Finish produces zero proposals.
Real GitHub Actions podman-e2e terminal output running TestPodmanContainerRealEngine on Ubuntu 26.04.1 LTS with podman version 5.7.0 in an isolated rootless store, passing all five contract subtests in 49.11 seconds
Live CI run of all five real-engine Podman contracts on Ubuntu 26.04.1 LTS + Podman 5.7.0 in an isolated rootless store (49.11s total, all passing).

Two takeaways stick from shipping this provider. First, extres absorbed a second real container runtime without leaking a single Podman import back into the ledger, lifecycle, auto, or obit doctor. Second, unit tests, Linux real-engine CI, and cross-platform code review each catch a completely different class of failure: empty CONTAINER_HOST="" came from real Podman 5.7 behavior, while the Podman Machine --url credential bug could only be spotted by reading target resolution through Windows and macOS eyes.

All posts