Rootless Container

Rootless Container

A rootless container is a container that runs without requiring root privileges on the host system, with the container runtime itself executed by an unprivileged user account. Traditional container deployments run their runtime daemon as root, creating a severe security risk: a successful container escape grants an attacker full host control.

Rootless containers address this by isolating the blast radius of any container escape. Key technologies making this possible include Linux user namespaces, tools like slirp4netns for networking, and runtimes such as Podman and rootless Docker.

What Is a Rootless Container?

In a root container, the runtime daemon runs as root on the host, meaning all container operations inherit those privileges. In a rootless container, the entire stack runs under an unprivileged user account.

Inside the container, a process may appear to run as UID 0 (root), but this maps to an unprivileged UID on the host through user namespace remapping. The process has no real host-level privileges.

Runtimes supporting rootless operation natively include:

  • Podman, which runs rootless by default with no daemon required
  • Docker via rootlesskit, enabling unprivileged daemon execution
  • containerd with appropriate user namespace configuration

Why Traditional Root Containers Are a Security Risk

When a container runs as root and an attacker escapes the container namespace, they immediately gain root access on the host. This turns a container vulnerability into a full system compromise.

Historical CVEs illustrate this risk clearly. Vulnerabilities in runc allowed attackers to overwrite the host runc binary from within a container, achieving host root execution. These escapes were catastrophic precisely because the runtime ran as root.

The supply chain threat model amplifies this concern:

  • A malicious container image with an embedded exploit becomes far more dangerous when the runtime holds root privileges
  • Compromised dependencies or base images can deliver payloads targeting the runtime itself
  • Root runtime privileges maximize the damage any such payload can cause

How Rootless Containers Work

Linux user namespaces are the core kernel feature enabling rootless containers. They allow a range of host UIDs to map to UIDs within the container, so UID 0 inside corresponds to an unprivileged UID outside.

The files /etc/subuid and /etc/subgid define the UID and GID mapping ranges available to each unprivileged user. A typical entry allocates 65,536 subordinate IDs to a given user, providing enough range for container processes.

Network connectivity for rootless containers is handled without privileged operations through specialized tools:

  • slirp4netns creates a user-space network stack for the container
  • pasta offers a more modern alternative with improved performance
  • Both tools enable outbound and mapped inbound connectivity without requiring root-level network configuration

Security Benefits of Rootless Containers

Blast radius reduction is the primary security benefit. If an attacker escapes a rootless container, they gain only the privileges of the unprivileged host user, not root access to the entire system.

Rootless containers also support defense-in-depth effectively. They pair well with other controls:

  • seccomp profiles restricting available syscalls
  • AppArmor or SELinux policies limiting resource access
  • Read-only root file systems preventing in-container modification

From a compliance perspective, frameworks such as the CIS Kubernetes Benchmark and NIST SP 800-190 explicitly recommend running containers without root privileges. Adopting rootless containers supports audit readiness and satisfies many control requirements directly.

Limitations and Challenges of Rootless Containers

Some applications require capabilities only available to root. Binding to ports below 1024 is a common example. Workarounds include port forwarding at the host level or using ambient capabilities where kernel support exists.

Storage and network compatibility can also be limiting:

  • Overlay filesystems may require specific kernel versions or configurations for unprivileged use
  • Some CNI network plugins do not support rootless operation and require alternatives
  • Performance overhead from user-space networking tools can affect latency-sensitive workloads

Operational setup adds complexity. Rootless environments require a sufficiently modern kernel (generally 5.11 or later for full feature support), properly configured subuid/subgid entries, and the newuidmap and newgidmap helper binaries with correct permissions.

Implementing Rootless Containers in Practice

For Podman, rootless mode is enabled by default. Verify operation with podman info and confirm the rootless field is true. Docker requires running dockerd-rootless-setuptool.sh and setting DOCKER_HOST to the user socket path.

In Kubernetes, running pods as non-root uses security context fields:

  • runAsNonRoot: true enforces that containers do not run as UID 0
  • runAsUser specifies a particular non-root UID for the container process
  • These fields control container user identity but differ from deploying a fully rootless container runtime

Building a comprehensive posture means combining rootless runtimes with image scanning, signed images verified at admission, and policy controllers like OPA Gatekeeper or Kyverno to enforce security standards across the cluster.

FAQ

What is the difference between a rootless container and a container running as a non-root user?

A non-root user inside a container still runs on a root-privileged runtime daemon. A rootless container means the runtime itself runs without host root privileges. Both reduce risk, but rootless containers provide stronger host-level isolation because a runtime compromise does not yield host root access.

Do rootless containers provide complete protection against container escape attacks?

No. Rootless containers significantly reduce the impact of an escape by limiting attacker privileges to an unprivileged host user. However, kernel vulnerabilities or misconfigured user namespaces can still be exploited. Rootless containers are one important layer in a broader defense-in-depth security strategy.

Can I run rootless containers in Kubernetes?

Yes. Kubernetes supports rootless runtimes when the container runtime such as containerd or CRI-O is configured for rootless operation on each node. Additionally, pod security contexts can enforce non-root execution. Full rootless runtime support requires node-level configuration and compatible kernel versions.

What are the main limitations I should expect when switching to rootless containers?

Expect challenges with privileged port binding, some storage drivers, and network plugin compatibility. Setup requires correct subuid/subgid configuration and modern kernel support. Certain applications that depend on Linux capabilities unavailable to unprivileged users will need redesign or specific workarounds before they run successfully rootless.

Ready to eliminate CVEs at the source?