On 6/16/23 02:00, Johannes Kastl wrote:
You got me wrong. You can create systemd services for your pods etc.
directly via Ansible, without having to write the unit files yourself,
Oh okay, yeah that would be simpler. I've never done that before. I'll
take your word for it and give it a spin. Thanks!
I never needed to fumble around with user namespaces until now, so my
naive question would be: Do you need to chown the files to the
respective user namespaces in the first place? I thought all of that was
handled by podman in the background?
It can be handled by podman (at container run time), and this is the
simplest thing to do. This is what the `:U` volume mount option is for.
Also the `-o o=uid=<ID>,gid=<ID>` option to `podman volume create`
However, podman will manage the ownership by changing the UIDs/GIDs of
the volume content. This is the crux of the issue. On the next
playbook run, the template module will register the managed content as
"changed" - because the UIDs/GIDs don't match. Worse, if the template
module tries to move updated files into place, it may receive a
"permission-denied" - because the user may no-longer "own" the
file's
directory (podman chown'ed it too!).
If you try to overcome this by (calculating the ID offsets and)
specifying UID/GID values to the template module, that can also fail
because the playbook is running as a user. Users aren't permitted to
(directly) chown things to user-namespaced IDs (see `podman unshare` below).
---quick user-namespace primer---
On the host, `/etc/sub{uid,gid}` contain per user ID range allocations,
which don't (typically) overlap each-other, and aren't (typically) used
by anything else on the host (though nothing actually verifies/blocks
this). It's like each user gets their own little (alternate) ID fiefdom
on the system.
The net effect is, a file or directory in a volume used by a rootless
container will be owned (from the host POV) by either the user's UID/GID
(corresponding to `root:root` in the container). Or, the UID/GID in the
container + an offset calculated from the second field of
`/etc/sub{uid,gid}`, bounded by summation of the third field
(effectively, the total number of IDs allocated to the range).
The wrapper `podman unshare <command>` lets a user "enter" their
allocated user-namespace on the host (for <command>), and use or chown
things to their heart's content (within their ID allocation). The
actual ownership (outside <command>) will be the values as described above.