Repository navigation
Conversation
Frando
force-pushed
the
feat/containers
branch
from
November 23, 2026 14:21
e0d3f64 to
1e19791
Compare
Integration tests often need an auxiliary service next to the code under test: an ACME test server like Pebble, a database, a real DNS server. `Lab::add_container(name, image)` runs one as a lab device. The builder mirrors the device builder for wiring and adds env, args, volumes, tmpfs, run_arg, ready_tcp and runtime. The returned `Container` derefs to `Device` and adds exec, logs, stop, write_file/read_file and copy_to/copy_from. It is removed when the last handle drops. Containers run with podman, forked from the device's namespace worker, so `--network=host` joins the device's network namespace. Docker cannot do this rootlessly, because its daemon runs in a separate namespace. podman runs in a user namespace nested in patchbay's, laid out like its own rootless one: root is the host user, 1.. the subordinate ids in host order. Every podman call joins it as root with the _CONTAINERS_USERNS_CONFIGURED/ROOTLESS_UID/ROOTLESS_GID variables set, the state after podman's own rootless re-exec. podman therefore uses the user's normal rootless storage and images, while patchbay keeps the user's uid. podman cannot build this namespace itself: its re-exec calls newuidmap, whose setuid bit has no effect inside patchbay's namespace. The podman child detaches the device worker's /proc/<pid>/net bind mount before it joins the nested namespace. That namespace would lock the mount, and the kernel then refuses the container's proc mount. Container root has no capabilities in the lab's network namespaces, so build() sets ip_unprivileged_port_start and ping_group_range in the device. Containers carry a patchbay.owner=<pid>:<start time> label. The first build() in a process removes containers whose owner is gone, so a SIGKILL or Ctrl-C does not leak them for good. A failed `podman run` removes its container. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Frando
force-pushed
the
feat/containers
branch
from
November 23, 2026 15:38
102bbc7 to
9b17357
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Integration tests written against patchbay often need an auxiliary service next to the code under test: an ACME test server like Pebble, a database, a real DNS server. These are usually easier to run as a container than to embed. This lets patchbay run one as an ordinary lab node.
A container is a device.
Lab::add_container(name, image)returns a builder that mirrors the device builder for wiring (uplink,iface,default_via,mtu) and adds container configuration on top. It creates the device namespace and veth uplink like any device, then runs the image joined to that namespace, so the service is reachable from other lab devices at the container's lab IP.The returned
Containerdereferences toDeviceand addsexec,logs,stop,write_file/read_fileandcopy_to/copy_from. Volumes come in read-write, read-only and tmpfs forms. The container is removed when the last handle drops.Runtime and requirements
Containers run with podman, which must be on
PATH. podman is daemonless, sopodman run, forked from the device's namespace worker, joins that namespace with--network=host. Docker cannot do this rootlessly: its daemon runs in a separate namespace.The host needs the standard rootless-podman setup:
newuidmap/newgidmaponPATHand an/etc/subuidand/etc/subgidentry for the user. Without it,build()fails with an error that names these requirements.User namespaces
Builds on #94:
init_userns()keeps the caller's uid and maps the subordinate range (0 to the first subordinate id, the rest to itself).podman runs in a user namespace nested in patchbay's, laid out like podman's own rootless one: root is the host user, and 1.. are the subordinate ids in host order. Every podman call joins it as root, with
_CONTAINERS_USERNS_CONFIGURED,_CONTAINERS_ROOTLESS_UIDand_CONTAINERS_ROOTLESS_GIDset, which is the state after podman's own rootless re-exec. So podman uses the user's normal rootless storage and images, while the patchbay process keeps its uid for the session D-Bus or PipeWire portals.Two details follow from the nesting:
/proc/<pid>/net. The nested namespace would lock that mount, and the kernel then refuses the container's proc mount. The podman child detaches it before it joins.build()setsip_unprivileged_port_startandping_group_rangein the device so services can still bind low ports and ping.podman cannot set up this namespace itself: its rootless re-exec calls
newuidmap, whose setuid bit has no effect inside patchbay's namespace. A supported flag for "run in an already-configured user namespace" is the open request podman-container-tools/podman#7774.Cleanup
Containers carry a
patchbay.owner=<pid>:<start time>label. The firstbuild()in a process removes containers whose owner is gone, so aSIGKILLor Ctrl-C does not leak them for good. A failedpodman runremoves its container.Notes
The API borrows its shape from testcontainers-rs (bind mounts with an access mode, tmpfs, copy in and out) but stays smaller:
ready_tcpcovers the common readiness case.A container gets a copy of the device's
/etc/resolv.confat start, so the lab DNS server works if it exists by then.Device::set_hostentries do not reach the container.Testing
ping_group_range, and orphan detection.🤖 Generated with Claude Code