A belief that circulates in almost every team that adopts containers: “It runs in its own container, so even if it is hacked, the attacker is stuck inside.” It is half true, and the missing half is where incidents come from. Let us take four such beliefs apart.
Belief one: a container is a small virtual machine
A virtual machine runs its own operating system kernel on emulated hardware, and a hypervisor sits between guests. A container is an ordinary process (or group of processes) on the host, fenced using Linux kernel features: namespaces limit what it can see, control groups limit how much it can use, and capabilities and system-call filters limit what it may ask the kernel to do. Every container on a node shares one kernel.
The consequence is simple. A flaw in the kernel, or a mistake in how the container was set up, can let code inside reach the host and then every other container on it. This is called container escape. It does not happen often against a hardened, up-to-date node, but it is the reason sensitive multi-tenant workloads sometimes use stronger sandboxes, or lightweight VMs per pod, instead of plain containers.
Belief two: the image is safe because it came from a registry
An image is a bundle of an application plus an operating system userland plus libraries. Each layer can carry known vulnerabilities, outdated packages, or leftovers such as secrets baked in during the build. A popular public image is not a vetted image. Practical defences:
- Start from minimal base images, so there is less to patch and less for an attacker to use.
- Scan images in the build pipeline, and again on a schedule, because new CVEs appear against images already deployed.
- Pull from a registry you control, reference images by digest rather than a movable tag, and sign them so the cluster can verify provenance.
- Never put credentials in a layer. Deleting a file in a later layer does not remove it from the image history.
Belief three: Kubernetes is secure by default
Kubernetes is designed for flexibility first. Several defaults are friendly to developers and generous to attackers:
- Flat pod networking. Unless you apply network policies, any pod can usually talk to any other pod. One compromised web pod can probe the database, the internal admin tools and the cluster’s own services.
- Containers often run as root inside the container, which is unnecessary for most applications and makes escapes easier.
- Service account tokens are mounted into pods so applications can call the Kubernetes API. If the account carries broad permissions, a compromised pod can read secrets or create new workloads. Give each workload its own account with minimal role bindings, and switch off token mounting where the app does not need the API.
- Secrets are only encoded, not encrypted, unless you enable encryption at rest for the cluster datastore or integrate an external secrets manager. Anyone allowed to read the secret object reads the value.
- Dangerous pod settings are permitted unless blocked: privileged mode, sharing the host’s network or process space, mounting host directories, or mounting the container runtime’s control socket. Any of these can collapse the boundary entirely. Kubernetes has built-in Pod Security Standards (privileged, baseline, restricted) enforced by the Pod Security admission controller, and policy engines can add organisation-specific rules.
The control plane matters too. The API server should not be open to the internet, and access should be through role-based access control with audit logging turned on. An exposed dashboard or API with weak authentication has been the root of well-publicised cryptomining compromises.
Belief four: we scan at build time, so we are covered
Build-time scanning checks what you shipped. It says nothing about what happens at runtime: a new process spawning inside a container that should only run one web server, an outbound connection to an unfamiliar address, a file changing in a container meant to be read-only. Runtime detection tools watch system calls and flag such behaviour. Containers also make a useful defensive habit possible: treat them as immutable. If a container misbehaves, replace it from a clean image, rather than patching it in place, and keep the root filesystem read-only wherever feasible.
A small illustration
Take an invented e-commerce start-up in Mysuru running 30 pods on a managed cluster. A bug in an image-resize library lets an outsider run commands inside the resize pod. Compare two clusters.
In the permissive cluster, the pod runs as root, carries a service account that may list secrets cluster-wide, and can reach the payments database on its network. The attacker reads secrets, then the database. In the hardened cluster, the same bug yields a non-root process with a read-only filesystem, no useful token, and a network policy that only allows traffic to the object store. The bug is identical; the outcome is a contained incident versus a breach. Nothing about the container boundary changed. What changed was everything surrounding it.
That is the honest summary: containers give you convenient packaging and a modest isolation layer. Security comes from least privilege, network restriction, image hygiene and runtime visibility, layered on top. The cloud provider’s shared responsibility model applies here as well. Managed Kubernetes services usually secure and patch the control plane, but node configuration, workload settings and who may deploy what remain with you.
Figures and names in the examples are illustrative.
Leave a Reply