Join our Newsletter — 33% off our NHI Course
Home› Guides› Linux Namespaces and cgroups Security Guide: Isolation Boundaries…
Guide Endpoint Security

Linux Namespaces and cgroups Security Guide: Isolation Boundaries Explained

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 8 November 2026 13 min read
On this page

Containers are not a security boundary in themselves: they are ordinary Linux processes that the kernel shows a partitioned view of the system through namespaces and limits through cgroups. Knowing exactly what each namespace does and does not isolate is what separates a sound container or sandbox risk decision from a guess. Many escapes and noisy-neighbour outages trace back to a namespace that was shared with the host, a capability that reached further than expected, or a cgroup limit that was never set. This guide explains the eight namespace types, how user namespaces change the meaning of root and capabilities, what cgroups v1 and v2 control, which settings break isolation, and how to detect and measure it. It is for Linux, container platform and security engineers. For the basics of Linux processes and permissions, start with the Linux Fundamentals for Defenders Guide.

Key takeaways

  • All containers on a host share one kernel: namespaces change what a process can see, not the kernel it talks to, so a kernel bug reachable from the container can cross every namespace.
  • User namespaces change what root means: root inside a user namespace has full capabilities only over resources that namespace owns, and none in the parent; this is the strongest namespace control and the one most often left off.
  • Some things are not namespaced at all: the kernel keyring, system time (outside the time namespace's limited clocks), kernel modules and many /proc and /sys paths are global, which is why seccomp, capabilities and LSMs are still needed.
  • Sharing host namespaces undoes isolation: hostPID, hostNetwork, hostIPC and privileged mode each remove a layer, and together they amount to host access.
  • cgroups are a security control too: without memory and pids limits, one compromised workload can exhaust a node; on cgroup v1, the writable release_agent has been an escape path.

How identity and access work in namespaces

A namespace wraps a global resource so processes inside it see their own instance. Every process belongs to exactly one namespace of each type, visible as links under /proc/<pid>/ns/ (for example uts:[4026531838]); two processes are in the same namespace when the inode numbers match. Namespaces are created with clone(2) or unshare(2) and joined with setns(2), which is what nsenter and docker exec use.

NamespaceFlagIsolatesDoes not isolate
MountCLONE_NEWNSMount table, so the container sees its own root filesystemFiles reachable through bind mounts or shared volumes; host paths mounted in
PIDCLONE_NEWPIDProcess ID numbering and visibilityProcesses in the host or a shared PID namespace, which can be signalled or inspected
NetworkCLONE_NEWNETInterfaces, routing, firewall rules, portsTraffic once it leaves through a bridge; host network if shared
IPCCLONE_NEWIPCSystem V IPC and POSIX message queuesShared memory through mounted files such as /dev/shm if shared
UTSCLONE_NEWUTSHostname and NIS domain nameNothing security-relevant beyond identity confusion
UserCLONE_NEWUSERUser and group IDs, and the scope of capabilitiesFiles on host filesystems are still checked against mapped host IDs
CgroupCLONE_NEWCGROUPThe view of the cgroup hierarchy (the cgroup root)Resource limits themselves, which are set by the cgroup, not the namespace
TimeCLONE_NEWTIMEBoot-time and monotonic clocks (Linux 5.6 and later)Wall-clock time: setting the system clock is still global

User namespaces, UID mapping and capabilities

User namespaces are where namespace security becomes an identity question. According to the user_namespaces(7) manual:

  • Capabilities are scoped: a process that creates or joins a user namespace gets a full capability set inside it but none in the parent, even if it was root before.
  • Ownership decides reach: every non-user namespace is owned by a user namespace, and capabilities only allow privileged operations on resources governed by namespaces that user namespace owns. Loading kernel modules, setting the system time and creating devices still need privileges in the initial user namespace, and mounting block-device filesystems needs CAP_SYS_ADMIN in the initial namespace.
  • But some mounts open up: CAP_SYS_ADMIN inside a user namespace permits bind mounts and mounting proc, sysfs, tmpfs, mqueue, bpf and overlayfs. That is why unprivileged user namespaces expand the kernel code an unprivileged user can reach.
  • ID maps: /proc/<pid>/uid_map and gid_map map IDs inside to IDs outside, can be written once, and an unprivileged writer may only map its own ID. Unmapped IDs appear as the overflow ID (usually 65534).
  • Unprivileged creation: since Linux 3.8, any user can create a user namespace, and creating it together with other namespaces gives the creator privileges over those too. This is a deliberate design that many kernel exploits rely on, which is why distributions now offer controls to restrict it (Ubuntu does this through AppArmor, requiring a profile to permit user namespace use).

Creating any other namespace type normally needs CAP_SYS_ADMIN. Per-user limits under /proc/sys/user/ (max_user_namespaces, max_net_namespaces and so on) cap how many can be created; setting max_user_namespaces to 0 disables new user namespaces entirely, at the cost of breaking rootless containers and browser sandboxes that depend on them.

cgroups: resource limits and their security role

Control groups organise processes into a hierarchy and apply resource controllers. Modern distributions and Kubernetes use the unified cgroup v2 hierarchy; cgroup v1 still appears on older hosts.

Controlcgroup v2 fileSecurity purpose
Process limitpids.maxContains fork bombs; forks beyond the limit fail with EAGAIN
Memory hard limitmemory.maxOOM kill inside the cgroup only, never outside it
Memory throttlememory.highSlows a runaway workload without killing it
CPUcpu.max, cpu.weightStops cryptomining or loops starving neighbours (ATT&CK T1496 Resource Hijacking)
I/Oio.maxLimits disk bandwidth and IOPS
Device accesseBPF program of type BPF_CGROUP_DEVICE (no interface files in v2)Controls which device nodes a container can create or open
Emergency stopcgroup.kill, cgroup.freezeKill or freeze every process in a cgroup tree, useful in incident response
  • v1 release_agent: in cgroup v1 the hierarchy root has a release_agent file naming a program the kernel runs, as root on the host, when a cgroup with notify_on_release set becomes empty. A container that can mount or write a v1 hierarchy can abuse it to run code on the host. v2 removes both files. Keep kernels patched against cgroup flaws as well as moving to v2.
  • Delegation: v2 lets a less privileged user manage a subtree by owning its cgroup.procs, cgroup.threads and cgroup.subtree_control files, or automatically through the nsdelegate mount option. A delegatee cannot escape its parent's limits, and moving a process needs write access to the common ancestor.
  • No limits on depth by default: cgroup.max.depth and cgroup.max.descendants default to max, so delegated subtrees can create unlimited cgroups unless you cap them.

Admin roles and privileged access

Namespaces and cgroups have no administrator role of their own. Control comes from who holds capabilities in which user namespace, and who can talk to the components that create namespaces.

Who or whatPower over isolationControl
Host rootCan enter any namespace with nsenter, change any cgroupPrivileged access management for node logins. See the Unix and Linux Privileged Access Guide
Container runtime socket (/var/run/docker.sock, containerd socket)Can start a privileged container with host namespaces, which equals host rootNever mount runtime sockets into workloads; restrict socket group membership
Kubernetes users who can create podsCan request hostPID, hostNetwork, hostIPC, privileged or hostPathPod Security Admission Baseline or Restricted; RBAC on pod creation. See the Kubernetes RBAC Guide
Kubernetes users with pods/execCan run commands inside a container's namespaces (ATT&CK T1609)Grant exec sparingly, audit its use
Containers with CAP_SYS_ADMINCan mount, create namespaces and reach far more kernel codeDrop ALL capabilities and add back only what is needed. See the Linux Capabilities Guide

Integrations, API tokens and service accounts

Namespaces decide which credentials a process can see. Breaking a namespace boundary is often a credential exposure first and a code execution problem second.

  • Shared PID namespace exposes environment and memory: with hostPID: true or a shared process namespace, a sufficiently privileged process can read other processes' /proc/<pid>/environ and command lines, where tokens and passwords are often passed.
  • Mount namespace and volumes: Kubernetes mounts the service account token and Secrets on tmpfs inside the pod's mount namespace. A hostPath mount of /var/lib/kubelet exposes every pod's tokens on the node. See the Kubernetes Service Account Token Guide.
  • Network namespace and metadata services: pods in their own network namespace can still reach the cloud instance metadata endpoint unless blocked, and with hostNetwork: true they share the node's network identity. Block or restrict metadata access and use workload identity for cloud credentials.
  • Runtime and kubelet credentials: the kubelet's client certificate and the runtime socket live on the host. Anything that escapes to the host mount namespace can use them to act as the node.
  • User namespaces reduce the payoff: with user namespaces, root in the container maps to an unprivileged host UID, so host files owned by root stay protected even after an escape from the mount namespace.

User namespaces in containers and Kubernetes

  • Kubernetes: set spec.hostUsers: false to run a pod in its own user namespace. The kubelet picks non-overlapping host ID ranges per pod. The UserNamespacesSupport feature is beta and enabled by default from v1.33 and stable from v1.36. Requirements include idmap mount support on the filesystems used (in practice Linux 6.3 or later, because tmpfs gained idmap support then), runc 1.2 or crun 1.9 or later, and containerd 2.0 or CRI-O 1.25 or later. It cannot be combined with hostNetwork, hostIPC or hostPID. Kubernetes notes several HIGH or CRITICAL vulnerabilities were not exploitable with user namespaces active.
  • Docker: userns-remap maps container root to a high, unprivileged UID range from /etc/subuid and /etc/subgid, using a dockremap user when set to default. The daemon still runs as root; rootless mode runs the daemon unprivileged as well. Enable remapping on a new installation, because existing images and containers are hidden once it is on.

Logging and detection

What to detectSourceWhy
Pods or containers created with hostPID, hostNetwork, hostIPC, privileged or sensitive hostPathKubernetes audit log, admission logsDeliberate removal of isolation
setns or nsenter into container namespaces from unusual parentsauditd or eBPF runtime sensorsHost-to-container or container-to-container movement
unshare or clone with CLONE_NEWUSER inside containersRuntime sensors, seccomp logsCommon first step in kernel exploit chains (T1068)
Writes to release_agent or cgroup v1 mounts inside containersauditd, runtime sensorsKnown escape technique (T1611 Escape to Host)
Containers listing host processes or cgroup hierarchyRuntime sensorsContainer and resource discovery (T1613)
Repeated OOM kills, pids.max hits, CPU throttlingmemory.events, pids.events, node metricsResource abuse or denial of service (T1496, T1499)

Metrics: percentage of production pods running with hostUsers: false or a user-namespaced runtime; number of pods using any host namespace (target: only named system components); percentage of nodes on cgroup v2; percentage of containers with memory and pids limits set; and count of containers with CAP_SYS_ADMIN. Runtime detection is covered in the Container Runtime Security Guide.

Hardening baseline

  1. Move to cgroup v2: confirm /sys/fs/cgroup is a cgroup2 mount on every node; this removes release_agent and brings eBPF device control.
  2. Patch the kernel: because every container shares it, kernel patching is the first container isolation control. Apply your distribution's kernel security updates promptly.
  3. Ban host namespaces and privileged mode: enforce Pod Security Admission Baseline everywhere and Restricted for application namespaces; allow exceptions only for named system DaemonSets.
  4. Drop capabilities and apply seccomp: drop ALL, add back only what is needed, and apply RuntimeDefault seccomp so unshare, mount and setns stay blocked. See the seccomp Guide.
  5. Enable user namespaces: pilot hostUsers: false on a node pool with a supported kernel, filesystem and runtime, then expand. Roll back per pod by removing the field.
  6. Restrict unprivileged user namespaces on hosts that do not need them: use your distribution's control (an AppArmor restriction on Ubuntu, or user.max_user_namespaces) on servers that run no rootless containers or sandboxed browsers.
  7. Set resource limits: require memory and CPU limits through LimitRange or admission policy, and set a node-wide pod pids limit in the kubelet configuration.
  8. Add an LSM: SELinux or AppArmor confinement limits what an escaped process can touch. See the SELinux Guide.
  9. Use stronger isolation for untrusted code: where tenants are mutually hostile, use sandboxed runtimes that run each pod in a lightweight VM or a user-space kernel, or separate nodes.

Small teams running their own trusted workloads get most of the benefit from steps 1 to 4 and 7. Multi-tenant platforms, CI runners executing untrusted builds and AI agent sandboxes should treat namespaces as the minimum and add user namespaces, an LSM and VM-level isolation.

Common misconfigurations

  • Running the Docker socket inside a container: CI agents and monitoring tools mount docker.sock, giving anyone who controls the container the ability to start a privileged one.
  • Privileged containers for convenience: privileged: true grants all capabilities, all devices and no seccomp, so namespaces are the only remaining boundary and they are easy to leave.
  • hostPID or hostNetwork on application pods: added for debugging or performance and never removed, exposing other processes and the node's network identity.
  • Writable hostPath mounts: mounting /, /etc, /var/lib/kubelet or /proc from the host defeats the mount namespace.
  • No resource limits: a compromised pod mines cryptocurrency or fork-bombs the node. Limits contain the damage but are not detection: in the Tesla Kubernetes cryptojacking incident attackers deliberately kept CPU use low so mining would not stand out, so watch per-workload usage trends as well.
  • Assuming containers are VMs: placing mutually untrusted tenants on shared nodes with only namespace isolation.

Framework mapping

AreaNIST SP 800-53 Rev. 5NIST CSF 2.0MITRE ATT&CK
Namespace and user namespace isolationSC-39 Process IsolationPR.PS-01T1611
Capabilities and privileged podsAC-6, CM-7PR.AA-05T1611, T1068
Resource limitsSC-6 Resource AvailabilityPR.IR-04T1496, T1499
Kernel patchingSI-2PR.PS-02T1068
Monitoring namespace changesAU-2, AU-12DE.CM-01T1609, T1613

Practitioner checklist

  • Confirm every node runs cgroup v2 and a supported, patched kernel.
  • Enforce Pod Security Admission so host namespaces, privileged mode and sensitive hostPath mounts are rejected outside named exceptions.
  • Drop ALL capabilities by default and never grant CAP_SYS_ADMIN to application containers.
  • Apply RuntimeDefault seccomp to every pod so unshare, mount and setns stay blocked.
  • Pilot and then roll out hostUsers: false (or userns-remap or rootless mode for Docker hosts).
  • Restrict unprivileged user namespace creation on servers that do not need it.
  • Require memory, CPU and pids limits for every workload.
  • Never mount container runtime sockets into workloads.
  • Alert on host-namespace pods, nsenter into containers, user namespace creation in containers and cgroup release_agent writes.

Standards and references

Related NHI Mgmt Group resources: Linux Fundamentals for Defenders Guide · Container Security Guide · seccomp Guide · Linux Capabilities Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 8 November 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.