Container and Image Security

Topics Covered

The Container Security Model

What a container is

The shared kernel

Capabilities

System call filtering

Mandatory access control

Root inside the container

Privileged containers

Host mounts and sockets

Host namespaces

Containers do not fix application bugs

What attackers do after getting in

Stronger isolation options

The image is part of the attack surface

User namespaces

Rootless runtimes

Kernel patching

Configuration is the common failure

Containers package an application with its dependencies and run it in an isolated environment on a shared host. They have transformed how software is built and deployed, but their security model is often misunderstood. A container is not a virtual machine, and the isolation it provides depends heavily on configuration. This section explains how container isolation works, where it is weak and the common settings that undermine it.

What a container is

A container is a process, or group of processes, running on a host kernel with restricted views of the system. Linux namespaces give the process its own view of process IDs, network interfaces, mount points, users and hostnames. Control groups limit how much CPU, memory and other resources it can use. The container image provides the files the process sees as its root filesystem. Underneath, every container on a host shares the same kernel.

Namespaces, control groups, dropped capabilities, seccomp and access control profiles wrap each process, but every container still shares one host kernel, which is the boundary an escape would cross.

The shared kernel

Because containers share the host kernel, a vulnerability in the kernel can allow a process in one container to affect the host or other containers. Virtual machines, by contrast, run separate kernels on a hypervisor that exposes a much smaller interface. This difference matters most when running untrusted code. For trusted workloads from the same organisation, container isolation combined with good configuration is usually adequate; for hostile workloads, stronger isolation is needed.

Capabilities

Traditional Unix divides users into root and everyone else. Linux capabilities split root powers into distinct privileges, such as binding to low ports, changing file ownership, loading kernel modules or administering the network. Container runtimes drop many capabilities by default, but some remain. Dropping all capabilities and adding back only those a workload needs reduces what a compromised process can do.

System call filtering

Seccomp profiles restrict which system calls a process may make. Most applications use a small fraction of the hundreds of available calls. Blocking rarely used, dangerous calls reduces the kernel attack surface reachable from the container. Runtimes ship a default profile that blocks many risky calls, but orchestrators have not always applied it by default, so it must be enabled explicitly in many environments.

Mandatory access control

Mandatory access control systems such as AppArmor and SELinux confine processes according to policies that even root inside the container cannot override. They restrict file access, mounts and other operations. Default container profiles block common escape techniques. Leaving these profiles enabled, and customising them for sensitive workloads, adds another layer that an attacker must defeat.

Root inside the container

Many images run their process as the root user by default. Root inside a container is not the same as root on the host when user namespaces and other controls are in place, but it is still more powerful than an unprivileged user. Combined with a misconfiguration or kernel bug, root in a container makes escape far easier. Running as a non root user is one of the simplest and most effective hardening steps.

Of 300 workloads, 190 ran as root and 240 had writable root filesystems. 41 mounted host paths, 33 added capabilities, 18 were privileged, 12 used the host network and 7 mounted the runtime socket.

Privileged containers

A privileged container has almost all capabilities, access to host devices and relaxed security profiles. It is effectively root on the host. Privileged mode is sometimes needed for system components such as network plugins or storage drivers, but application workloads almost never need it. Each privileged container should have a documented reason and run only in controlled namespaces.

Host mounts and sockets

Mounting host directories into a container gives it access to host files. Mounting sensitive paths, such as the root filesystem, system configuration or the container runtime socket, can allow full control of the host. A container with access to the runtime socket can start new privileged containers. These mounts should be rare, reviewed and restricted by policy.

Host namespaces

Containers can be configured to share the host network, process or IPC namespace. Sharing the host network lets a container see and bind to host interfaces and reach services listening on localhost. Sharing the process namespace lets it see and possibly signal host processes. These options remove isolation that containers otherwise provide and should be used only by trusted system components.

Containers do not fix application bugs

Containers limit what a compromised process can reach, but they do not prevent the compromise. An injection flaw, deserialisation bug or leaked credential in the application is just as exploitable inside a container. The attacker then operates with whatever access the container has: its network reach, mounted secrets and cloud identity. Container hardening reduces blast radius; application security reduces the chance of compromise.

What attackers do after getting in

After compromising a containerised application, attackers typically look for credentials in environment variables and mounted files, query cloud metadata services for instance credentials, scan the internal network, try to reach the orchestrator API and attempt to escape to the host. Each of these steps can be blocked or detected: minimal secrets, metadata protection, network policies, restricted service account tokens and hardened runtimes.

Stronger isolation options

For untrusted or multi tenant workloads, stronger isolation is available. Sandboxed runtimes intercept system calls in a user space kernel, lightweight virtual machines give each container its own kernel and dedicated nodes separate sensitive workloads physically. These options cost some performance and compatibility but greatly reduce the impact of kernel vulnerabilities.

The image is part of the attack surface

Everything inside the image is available to an attacker who compromises the container: shells, package managers, network tools and compilers make post exploitation easy. Minimal images without these tools make an attacker work harder. The image also determines which vulnerable packages are present. Image security and runtime security are two halves of the same problem.

User namespaces

User namespaces map the root user inside a container to an unprivileged user on the host. If a process escapes the container, it lands on the host without root powers, which blunts many escape techniques. Support has matured in recent runtimes and orchestrators, though some workloads and storage drivers still need adjustment. Enabling user namespaces where possible is a strong defence in depth step, especially for workloads that must run as root inside the container for compatibility reasons.

Rootless runtimes

Rootless container runtimes run the runtime itself, not just the container process, as an unprivileged user. A bug in the runtime then gives the attacker only that unprivileged user rather than host root. Rootless mode is common on developer machines and build hosts, where it limits the damage from building untrusted projects. It has some limits on networking and storage performance, so teams should test it before adopting it for production nodes.

Kernel patching

Because the kernel is the shared boundary, keeping it patched matters more for container hosts than for many other systems. Kernel escape vulnerabilities are found several times a year. Hosts should run supported kernels, receive security updates promptly and be replaced or rebooted on a regular cycle so that patches actually take effect. Immutable node images that are rebuilt and rolled out automatically make this practical across large fleets of container hosts.

Configuration is the common failure

Real container compromises rarely require a novel kernel exploit. Far more often the attacker benefits from a configuration choice: a privileged container, a mounted runtime socket, a host path mount or broad cloud credentials. This is good news, because configuration can be checked automatically and enforced by policy. A cluster where every workload meets a hardened baseline removes the easiest paths, leaving attackers with much harder options.

Isolation depends on configuration

Containers are processes on a shared kernel, isolated by namespaces, control groups, capabilities, seccomp and access control profiles. Running as root, privileged mode, host mounts, runtime sockets and host namespaces undo that isolation. Harden configuration for every workload and use stronger isolation for untrusted code.