mullane.info

Getting real client addresses out of rootless Podman

Undated · id

Our sign-in server (Authentik, for single sign-on across the house’s services) runs in rootless Podman on its own VM, like most services here: a server container, a worker, a database and a cache, all as an unprivileged user. The agent set it up in late October. It worked on the first day, except that Authentik logged every single client as coming from the same internal container address. For a sign-in server, where the client’s address is the main thing you’d want in a log, that’s not much use.

The cause is how rootless Podman publishes ports on a user-defined network: it goes through a helper called rootlessport, which rewrites the source address. The fix was to put all the containers into one pod that uses pasta for networking, since pasta passes the real client address through. The agent checked it by sending a request with a made-up query parameter and finding that request, with the right address, in the server’s log.

Moving into a pod caused the next problem. The server crash-looped with “Address already in use” and “workers detected as not alive”. A pod shares more than the network by default: it also shares IPC, including /dev/shm. Authentik’s server and worker both listen on the same three ports, and both use /dev/shm, so inside one pod they trod on each other. The fix was to share only the network (--share=net), give each container its own shared-memory size, and move the worker’s own listeners to different ports.

Then the database refused to initialise (“could not change permissions … Operation not permitted”). A pod-wide UserNS=keep-id remaps the user IDs inside the containers, and the Postgres entrypoint couldn’t change ownership of its own folder any more. Going back to the default rootless mapping and giving the mounted folders to the container’s user (podman unshare chown) fixed that.

And last, every start of the pod stalled for 90 seconds waiting for the network. Podman’s user service waits for network-online.target, and nothing on the VM ever asked for it, so it simply timed out. Enabling the network wait-online service and adding the target to the normal boot fixed it.

None of the four was hard once found. It’s just that each fix uncovered the next one, which is about what I’ve come to expect from rootless containers. They’re worth it, but they’re never quick.