How Rootless Podman Maps Container Users to the Host
Imagine two applications running on the same Ubuntu server. Emailwiz runs under a host account called mail-user , and a web app runs under web-user . Both applications use UID 1000 inside their containers. On the host, those processes show up under different UIDs . Linux user namespaces make this possible. Each namespace defines how the user IDs (UIDs) and group IDs (GIDs) seen inside a container…
In an Ubuntu server environment, two applications named Emailwiz and a web application run inside containers. Each container uses UID 1000 for these applications. Due to Linux user namespaces, the host allows each container to map its UID and GID to different values.
First, create separate service accounts for each application on Ubuntu 24.04. For example, account 'mail-user' gets a host UID of 980 and GID of 980. The same applies to account 'web-user', which gets a host UID of 981 and GID of 981. These accounts also have their subordinate UID and GID ranges allocated by the system.
Next, verify the host account's assigned UIDs and GIDs. The 'mail-user' account, for instance, has an own UID of 980 and a subordinate UID range of 100000–165535. Similarly, the 'web-user' account has an own UID of 981 and a subordinate GID range of 165536–231071.
Podman maps the container's 0:0 to the host account's own UID and primary GID. Starting from container 1:1, it uses the subordinate ranges sequentially. In the given example, container 0:0 maps to host IDs 980:980 under 'mail-user' and 981:981 under 'web-user'. Container 1:1 maps to host IDs 100000:100000 under 'mail-user' and 165536:165536 under 'web-user'. The highest usable UID and GID inside either container is 65536.
This mapping allows a process to run with a high UID and GID, such as 65536:65536, within containers. However, requests to start processes with higher UID and GID pairs (e.g., 65537:65537) are outside the mapping's scope. Containers launched by the same host account under default rootless Podman modes will reuse these ranges. If you choose a different user namespace mode or configure a custom mapping, check the container's uid_map and gid_map to see which IDs are available.
For a rootless Quadlet deployment, enable lingering so each account's systemd user manager starts at boot. Then, run the same image as 1000:1000 under both accounts to observe the differences. After running the commands, both containers will report UID 1000 and GID 1000 on the host. The mapping tables will display where these IDs land on the host.
In cases where a container writes to persistent files, such as Emailwiz's mailbox owner mehmet using 1000:1000 inside the container, Dovecot writes to a persistent Maildir under the mapping. The host records the owner as 100999:100999. Creating a new container with the same volume and mapping will preserve Dovecot's access. An existing host directory owned by the same user (1000:1000) will be accessible by the container as (100999:100999).
Before bind-mounting an existing Maildir, make sure to check its numeric ownership and permissions against the container's mapping.
Rewritten by urgent.news; may contain errors — check the original. How we use AI.
Source: dev.to