✳ Field lesson CL3 / 14 min

What a container boundary does not stop

A container is a process that shares the host's kernel. A privileged pod, a host mount, or the host's network can give that process the node's reach. So give each workload its own narrow identity.

cloudcontainerskubernetesworkload-identityCISSP D3Security+ (SY0-701) D2Security+ (SY0-701) D3

Helpful first: Find the path in a posture list · What the hardware and hypervisor must guarantee

Thirty days to Halcyon · Case 12: The long list · Episode 4 of 5

Wednesday. Kael Cho, Staff Infrastructure Engineer, reads the uplink-status pod spec aloud. privileged: true. hostNetwork: true. He stops.

"That's mine," he says. "I set it for a debug session months ago and never set it back. I'll fix it today."

Vera Vance, your mentor, puts down her cold coffee. "Fix it, yes. But what does a container boundary keep in, and what did those two lines take away?"

By the end you can

  • Explain why a container is a process on a shared kernel, not a small virtual machine
  • Identify the pod settings that let a container reach its node
  • Give a workload its own narrow identity instead of the node's

A container is a process on a shared kernel

A virtual machine runs its own kernel on virtual hardware. A container does not. A container is an ordinary process on the host, run with its own view of the file system and its own share of resources. Ordinary containers on a node share that node's one kernel. Sandboxed runtimes, such as gVisor or Kata Containers, add a separate kernel at a cost in speed.

The fence around that process is built from kernel features. Namespaces give it its own view of processes, network interfaces, and mounted files. Control groups, or cgroups, limit how much memory and processor time it may use.

Two more features narrow what it may ask the kernel to do. Linux splits the power of the root user into separate capabilities, and a container gets only some of them. A seccomp filter can refuse whole system calls.

Each of these is a setting, and settings can be switched off. The kernel is still shared when they are on. A flaw in that kernel can let a process in any container on the node break out. That is why a container is not a small virtual machine.

Settings that hand the container the node

In Kubernetes, the smallest unit you run is a pod: one or more containers that start together on one node. The pod spec says how each container is fenced. A few lines in it take the fence down.

privileged: true turns off most of the protections at once. Kubernetes describes a privileged container's processes as essentially equivalent to root on the host. hostNetwork: true puts the pod on the node's own network, with the node's addresses. A hostPath volume mounts a directory of the node's file system into the pod. Added capabilities and running as the root user widen what an escape can do.

The uplink-status pod had the first two. Running on the node's network, it could talk to everything the node talks to. That included the instance metadata service, which hands the node role's credentials to the node. Host networking alone opened that route. A privileged pod on its own network would not get the reply, though it could take over the node in other ways.

None of these lines is always wrong. Some system tools need one of them. The question for each line is whether this workload's job needs it.

WORKED EXAMPLE

Reading the log-shipper pod spec line by line

  1. image: log-shipper@sha256:... Names one exact image by its digest. Harmless.
  2. hostPath: /var/log, read-only Reaches the node. The pod can read every log the node writes. That is the job, so it stays, read-only.
  3. serviceAccountName: log-shipper Reaches the cluster API. Its token lets it ask which pod wrote each log line. Its role allows reading pod details, and nothing else.
  4. runAsNonRoot: true and capabilities: drop: [ALL] Keeps the fence up. If something breaks out of the shipper, it is not root and holds no extra kernel powers.
  5. resources.limits.memory: 256Mi A control group limit. Harmless, and it stops one pod starving the node.

Result: One line reaches the node and one reaches the cluster API, and the job needs both. So log-shipper runs in its own namespace, with its own looser rules, owned by Kael.

SPOT THE PROBLEM

The uplink-status pod spec, as Kael found it. The pod serves a status page and never calls the Kubernetes API. Flag the lines that give it more than that job needs.

Show the answers
  • privileged: true This turns off most of the container's protections. A status page never needs it.
  • hostNetwork: true This puts the pod on the node's network, where the metadata service hands out the node role.
  • automountServiceAccountToken: true This mounts a token for the cluster API into a pod that never calls it.

The cluster has identities of its own

Kubernetes gives each pod a service account, an identity for calling the cluster's own API. Since version 1.22, the kubelet mounts a short-lived token for it that rotates by itself. Since 1.24, Kubernetes no longer creates a permanent token for each service account by default.

What the token may do is set by role-based access control (RBAC). A Role grants actions inside one namespace. A ClusterRole can grant them across the whole cluster. A pod that never calls the API should not have a token mounted at all.

A namespace is a scope for names. It is a useful place to hang RBAC and admission rules. By itself it is not a wall. Pods in different namespaces can reach each other over the network until a network policy says otherwise, and every pod still shares its node's kernel.

A service account is the pod's identity inside the cluster. It is not its identity in the cloud account. Calls to halcyon-downlink need a cloud identity too, which is the next section.

Narrow it at admission and in identity

One of Kael's two lines, hostNetwork: true, opened a path from the pod to the downlink bucket. Each step on it can be narrowed.

A pod on the node's network gets the node's metadata replies, privileged or not. Nothing refused it at admission, and the hop limit had no extra hop to stop.

Kubernetes defines three Pod Security Standards: privileged, baseline, and restricted. Baseline already refuses privileged pods, host networking, and host paths. Restricted also requires a non-root user, dropping every capability, and a seccomp profile. Pod Security Admission, built in and stable since version 1.25, applies a level to a namespace through a label. The older PodSecurityPolicy was removed in that same release.

Kael labels the uplink-status namespace to enforce restricted. The old spec would now be refused before it ever starts. The nodes already required IMDSv2 tokens with a hop limit of 1, so a token reply cannot cross into a pod's own network. The hop limit protects only pods that have a network of their own. Restricted admission now keeps uplink-status among them.

Then the pod gets its own workload identity, through EKS Pod Identity. Its role writes only to halcyon-downlink/status/. The node role keeps what the node itself needs to run, such as joining the cluster, pulling images, and letting the Pod Identity agent fetch pod credentials. For data, it keeps only what ingest needs. It still reads the downlink, so a pod that reaches the metadata service is still one step from it.

SORT IT OUT

Kael reviews five pods in other namespaces. Where can each one's code get to?

  1. A container on its own network, running as a non-root user with every capability dropped and no API token.

  2. A pod that mounts the container runtime's socket from a host path.

  3. A pod whose service account can read every Secret in its namespace.

  4. A pod with a host path volume that mounts the node's root directory.

  5. A container held to 256 MiB of memory by its control group.

Show the answers
  1. Stops at the container. Without root or extra capabilities, the fence holds unless the kernel itself has a flaw.
  2. Reaches the node. Whoever controls the runtime socket can start new containers on the node with any settings.
  3. Reaches the cluster API. Its token can ask the API for those Secrets.
  4. Reaches the node. It can read, and possibly change, the node's own files.
  5. Stops at the container. A resource limit narrows the container. It opens nothing.

An image remembers what you deleted

A container image is built in layers, and a layer never changes once it is made. If one build step copies a key file in and a later step deletes it, the later layer only hides the file. The earlier layer still holds it, and anyone who pulls the image can read it.

Docker's documentation warns that build arguments and environment variables persist in the final image. So secrets do not belong there either. Pass them with a build secret mount, or fetch them when the container runs.

Kubernetes has a Secret object for values a pod needs. Its contents are base64 encoded, which is not encryption. Upstream Kubernetes stores them unencrypted in the cluster's data store unless encryption at rest is turned on. Amazon EKS turns that on by default for clusters on Kubernetes 1.28 or later, with envelope encryption of all API data. That protects the stored copy, not the value. Anyone allowed to read a Secret gets it, so treat read access to Secrets as access to the values.

For uplink-status, the narrow identity means there is no stored cloud key to leak. EKS Pod Identity hands the pod temporary credentials for its own role.

CHECK YOUR JUDGMENT

Kael's fixes are in place. A new pod in the log-shipper namespace, which allows host networking, sets hostNetwork: true. It has its own Pod Identity role. Can it get the node role's credentials?

CASE FILE · CASE 12 · ENTRY 4 OF 5

Answer the closing question correctly to add this entry to your case file.

Host network meant node credentials

uplink-status ran on the node's own network, so the node's metadata service handed it the node role until restricted admission and its own identity closed that route.

Next episode: Kael fixed it by hand. What stops the next change undoing it?

Open the case file ↗

Review sheet: exam notes and quick reference

Find your next idea.

Tip: press / to open search. Escape closes this window.