drydocc Podman Quadlets
drydocc runs containers under rootless podman as the doccap user, with
lifetime managed by systemd user quadlets. This skill documents the
conventions all use-case quadlets must follow.
File locations
Quadlets exist only on the node — never in git:
~/.config/containers/systemd/<slug>-<name>.{container,network,build}
The source of truth is the spec: block in
nodes/<node>/use-cases/<slug>.md. The render function below is a pure
function spec → {filename: ini-text}. /audit-use-case re-renders it and
diffs the result against the on-disk quadlets to detect drift.
The on-node filenames are prefixed with the use-case slug to make
ownership obvious in ls.
Naming
- Container unit:
<slug>-<role>.container → <slug>-<role>.service at
runtime (systemd derives the service name).
- Network:
<slug>-<purpose>.network → unit <slug>-<purpose>-network.service.
- Volume:
<slug>-<volume>.volume → unit <slug>-<volume>-volume.service.
- Built image:
<slug>-<image>.build → unit <slug>-<image>-build.service.
Names listed in the use-case doc frontmatter (containers:, networks:,
volumes:) MUST match these patterns.
Lingering
After /bootstrap-node, loginctl enable-linger doccap is run so the
doccap user's systemd instance survives logout. Without this, quadlets
stop when the admin's ssh session ends.
Reload procedure
After writing or modifying any quadlet file:
systemctl --user daemon-reload
systemctl --user start <slug>-<role>.service
Units rendered from quadlets are generated, and systemd refuses to
enable or disable a generated unit (Unit … is transient or generated) —
enable --now therefore fails before it starts anything. Start-at-boot comes
from the quadlet's own [Install] WantedBy=default.target, which the generator
honours on every daemon-reload. So:
- bring a unit up with
start (or restart), never enable;
- take it down with
stop, never disable; to keep it from returning at the
next boot, remove its quadlet file and daemon-reload.
This applies only to quadlet-generated units. Ordinary unit files a skill
writes under ~/.config/systemd/user/ (backup, maintenance, and telemetry
timers) are enabled and disabled normally.
EnvironmentFile
Quadlets that need secrets reference them with:
[Container]
EnvironmentFile=/etc/drydocc/secrets/<slug>.env
See secrets for how that file gets written.
Networking
Default to a per-use-case network:
[Network]
NetworkName=<slug>-net
Cross-use-case networking is rare and requires explicit declaration in
both use-case docs' depends_on.
A container may join several of the use-case's networks (networks:), e.g.
an internal one to its peers plus one with outbound access.
Host network (network: host) is for a service that cannot sit behind
podman's port forwarding: a relay that binds a large port range on demand, or
a server that must see the real client address (a mail server scoring
senders, a reverse proxy rate-limiting clients). Rootless port forwarding
hides that address. The container then shares the node's network stack:
- it publishes nothing (
ports: under the container is refused), because its
sockets already are the node's;
- the ports it binds are declared in
listens: ("25/tcp", "3478/udp").
They feed § "Privileged ports" and the audit's listening check;
- whatever must be reachable from outside still goes in the document's
top-level
ports:, which drives the firewall exactly as for any other
use-case;
- it has no network unit, no
networks, and no aliases.
Privileged ports
Rootless podman publishes a port as the unprivileged doccap user, and the
kernel refuses an unprivileged bind below
net.ipv4.ip_unprivileged_port_start (1024 by default; the setting covers
IPv6 too). A PublishPort=443:443/tcp therefore fails at container start
unless the floor is at or below 443.
Goal. Before any container that binds a host port is started, the
node's floor is at or below the lowest host port that container binds. That
is the number before the container port in a ports: entry
("443:443/tcp" → 443; "127.0.0.1:53:53/udp" → 53), and for a
host-network container each listens: entry ("25/tcp" → 25; a range
counts by its low end).
LOWEST=<lowest host port across spec.containers.*.ports and spec.containers.*.listens>
FLOOR=$(sysctl -n net.ipv4.ip_unprivileged_port_start)
if [ "$LOWEST" -lt "$FLOOR" ]; then
printf 'net.ipv4.ip_unprivileged_port_start=%s\n' "$LOWEST" \
| sudo install -m 644 /dev/stdin /etc/sysctl.d/99-drydocc-unprivileged-ports.conf
sudo sysctl -p /etc/sysctl.d/99-drydocc-unprivileged-ports.conf
fi
Rules:
- Only ever lower it, and only as far as a declared port needs. Never
raise it: another use-case on the node may depend on the current floor.
/remove-use-case leaves it alone for the same reason.
- Persist it. The drop-in under
/etc/sysctl.d/ survives a reboot; the
99- prefix sorts it after distribution defaults so it wins.
- Say what it costs. Any unprivileged process on the node may then bind
ports at or above the new floor. On a single-responsibility node that runs
only
doccap's services this is the standard rootless trade-off, but the
admin is told before it happens: list the change in the confirmation the
calling command already shows.
- Verification.
sysctl -n net.ipv4.ip_unprivileged_port_start is at or
below $LOWEST afterwards. Journal the old and new values.
Logs
Use journald (the systemd default). Inspect with:
journalctl --user -u <slug>-<role>.service -f
Render from spec
The render function is a pure mapping spec → {filename: ini-text}. It is
called by /apply-use-case (first apply, greenfield or adoption),
/modify-use-case (re-render after a change), and /audit-use-case (re-render
in memory, to compare against what is on disk). /create-use-case authors the
document and delegates the apply; it renders nothing.
Where the renderer lives. The renderer is committed once, at
scripts/drydocc/render.py, and reached through render_quadlets,
diff_quadlets and audit_probe_run (§ "The drydocc tools" below). The
mapping below is the contract that renderer implements. Its one
distro-specific choice, whether mounts carry the relabel option, is the
agent's (the Z option below); every other cross-distro adjustment is the
agent's to work out per run, too.
<slug>-<container>.container (one per spec.containers.*)
[Unit]
Description=<slug>/<container> (drydocc)
After=<slug>-<network>-network.service <slug>-<dep>.service ...
Requires=<slug>-<network>-network.service <slug>-<dep>.service ...
[Container]
Image=<spec.image> # or <slug>-<spec.build>.build for a built image
ContainerName=<slug>-<container>
Network=<slug>-<net>.network # one per spec.network / spec.networks entry; Network=host for network: host
HostName=<spec.hostname> # only if set
User=<spec.user> # only if set
AddCapability=<cap> <cap> ... # only if cap_add is non-empty, space-joined in declared order
EnvironmentFile=<spec.env_from> # only if env_from is set
Environment=KEY=VAL # one line per spec.env entry
Volume=<source>:<target>[:<opts>] # one per mount; <source> below
PublishPort=[<addr>:]<host>:<container>/<proto> # one per port, verbatim
HealthCmd=<healthcheck.cmd> # the five Health* lines only if healthcheck is set,
HealthInterval=<healthcheck.interval> # each only if its field is set
HealthTimeout=<healthcheck.timeout>
HealthRetries=<healthcheck.retries>
HealthStartPeriod=<healthcheck.start_period>
PodmanArgs=--entrypoint=<spec.entrypoint> # only if set
PodmanArgs=--network-alias=<alias> # one per aliases entry
Exec=<spec.exec> # only if non-empty
[Service]
Restart=<spec.restart or on-failure>
TimeoutStartSec=<spec.start_timeout> # only if set
MemoryMax=<spec.resources.memory_max> # the resources lines, fixed order, each only if its key is set:
MemoryHigh=<spec.resources.memory_high> # memory_* render as plain bytes (4.5GiB -> 4831838208;
MemorySwapMax=<spec.resources.memory_swap_max> # infinity stays "infinity"); cpus renders as
CPUQuota=<round(spec.resources.cpus*100)>% # CPUQuota=<round(cpus*100)>% (single %, see Rules), cpu_weight as
CPUWeight=<spec.resources.cpu_weight> # CPUWeight=
[Install]
WantedBy=default.target
A container with oneshot: true is started only by a job (§ "Jobs"), never
at boot. Its [Service] section is Type=oneshot followed by the optional
TimeoutStartSec= line and any resources lines, with no Restart= line,
and it has no [Install] section. Everything in [Unit] and
[Container] renders as for any other container.
Keys are emitted in exactly the order above, and a key whose field is unset
emits no line. That keeps the render byte-identical for documents that use
none of the optional keys, and keeps the audit's diff stable.
Rules: