Rootless Containers with Podman: Configure SubUID/SubGID and Run Secure Services on Linux

Linux tutorial - IT technology blog
Linux tutorial - IT technology blog

The Risk of Root Daemons: Why Rootful Containers Break Security Boundaries

Most developers pick up containerization through standard Docker workflows. You install the runtime, add your user to the docker group, and spin up an Nginx or PostgreSQL instance. It feels clean and fast. Yet there is a catch: anyone with read/write access to /var/run/docker.sock holds root-equivalent power across your entire host.

Docker relies on a central daemon (dockerd) executed by root. Inside standard containers, processes typically run as UID 0. Because containers share the host kernel, any runtime breakout—like the infamous runc escape (CVE-2019-5736)—instantly drops an attacker into host root space. From there, they own your filesystem, devices, and network interfaces.

On shared development boxes or multi-tenant staging nodes, this model is a serious liability. Adding an intern or junior engineer to the docker group gives them unfiltered sudo in practice. Defense-in-depth demands that application containers run entirely inside user space.

Core Concepts: How Rootless Podman and SubUIDs Work

Podman throws out the daemon model. It operates as a direct child process of whoever runs the command. When you type podman run, your unprivileged user account spawns the container directly. No daemon. No ambient root authority.

Linux User Namespaces

The foundation of rootless isolation is the Linux user namespace (CLONE_NEWUSER). This kernel mechanism gives a process one set of UIDs inside the namespace and a totally different set outside it. Inside the container, Nginx thinks it runs as UID 0, so it can bind standard paths and drop worker privileges cleanly. Outside in the host process table, that exact process maps to an unprivileged UID like 1001.

Subordinate UIDs and GIDs (subuid / subgid)

A standard Linux user has only one UID. Container images, however, often juggle multiple users—such as root for startup, postgres (UID 70) for the engine, and nobody (UID 65534) for unprivileged tasks. Linux solves this with subordinate user and group IDs.

Two files control these subordinate allocations:

  • /etc/subuid: Defines subordinate UID blocks per user.
  • /etc/subgid: Defines subordinate GID blocks per user.

Here is what an allocation in /etc/subuid looks like:

svc-web:100000:65536

This entry grants svc-web a block of 65,536 subordinate IDs starting at 100000. UID 0 inside the container maps to the host account svc-web (UID 1001). Container UID 1 maps to host UID 100000, UID 2 maps to 100001, up through 165535. If an attacker punches out of container UID 0, they land on the host as plain UID 1001. They hold zero host root rights and cannot read other users' files.

Rootless Networking

Standard container bridges modify host iptables and virtual routing tables, requiring elevated privileges. Rootless Podman handles traffic without touching kernel routing by using user-mode network stacks: pasta (default in Podman 4.4+) or slirp4netns. These tools create a tap device inside the network namespace and translate packets to ordinary user-space sockets on the host.

Hands-On Practice: Setting Up and Running Rootless Services

Below is a field-tested setup for provisioning a dedicated service account, configuring subordinate maps, launching a container, and automating systemd restarts across reboots.

Step 1: Install Podman and Mapping Utilities

Ensure you have Podman and the newuidmap/newgidmap helpers installed:

# Debian 12 / Ubuntu 24.04
sudo apt update
sudo apt install -y podman uidmap slirp4netns passt

# RHEL 9 / Rocky Linux 9 / Fedora
sudo dnf install -y podman shadow-utils passt

Step 2: Create a Dedicated Service User

Avoid running background services under personal user accounts. Create an isolated system account named svc-web with home directory support:

sudo useradd -m -s /bin/bash svc-web

Modern Linux tools usually populate subordinate ranges automatically upon user creation. Check both files to be certain:

grep svc-web /etc/subuid
grep svc-web /etc/subgid

If the command returns nothing, assign a 65,536-ID block manually:

sudo usermod --add-subuids 100000-165535 svc-web
sudo usermod --add-subgids 100000-165535 svc-web

Step 3: Inspect Namespace Mappings with podman unshare

Open a login shell as your service user:

sudo su - svc-web

Test the namespace mapping using podman unshare. This tool runs a command inside an isolated user namespace using your assigned subordinate table:

podman unshare cat /proc/self/uid_map

You should see two rows of three numbers (internal ID, host ID, count):

         0       1001          1
         1     100000      65536

Row 1 maps container UID 0 to host UID 1001. Row 2 maps container UIDs 1–65536 to the host range 100000–165535. Your sandbox is ready.

Step 4: Launch an Unprivileged Web Service

Run a lightweight Alpine Nginx container mapped to host port 8080:

podman run -d \
  --name web-app \
  -p 8080:80 \
  docker.io/library/nginx:alpine

Verify that the container is up and inspect the process hierarchy on the host:

podman ps
ps -ef | grep nginx

Notice the owner in the host process list. The parent process runs as UID svc-web (1001), while internal worker threads run as UID 100100 (which corresponds to Nginx's unprivileged internal UID inside the image). Neither process touches root.

On an 8GB Ubuntu 22.04 node running 15 isolated microservices, replacing Docker with rootless Podman dropped idle daemon memory usage by 180MB and eliminated a shared privilege-escalation vector.

Step 5: Bind to Privileged Ports Below 1024 (Optional)

Linux forbids non-root users from binding to ports 1 through 1023. If your rootless container needs to listen on port 80 or 443 directly, lower the unprivileged port threshold to 80:

# Test dynamically
sudo sysctl net.ipv4.ip_unprivileged_port_start=80

# Persist across reboots
echo "net.ipv4.ip_unprivileged_port_start=80" | sudo tee /etc/sysctl.d/99-podman-ports.conf
sudo sysctl --system

Now svc-web can run podman run -p 80:80 ... without root intervention.

Step 6: Ensure Persistence Across Reboots via Systemd

When an unprivileged user logs out, systemd kills their user processes by default. To keep your containers running indefinitely, enable linger on the service account:

sudo loginctl enable-linger svc-web

Next, switch back to svc-web and generate a systemd unit. For Podman 4.x and newer, you can generate a systemd service directly from the running container:

su - svc-web
mkdir -p ~/.config/systemd/user/
podman generate systemd --new --name web-app > ~/.config/systemd/user/container-web-app.service

Enable and start the user-level unit:

systemctl --user daemon-reload
systemctl --user enable --now container-web-app.service

Confirm the service is running:

systemctl --user status container-web-app.service

Your container will start during early boot, restart automatically on crashes, and run under an unprivileged user ID.

Conclusion

Rootless Podman closes a longstanding gap in container security. Combining Linux user namespaces with /etc/subuid ranges confines every container escape to an unprivileged host account. Paired with systemd user sessions, this setup gives you production-grade service management without giving developers or services root access to the host.

Share: