Overview
Curated: · Written: · Reviewed:
Container & Workload Security
In one line
A container is a namespaced process on the host kernel, so I layer controls across the lifecycle (image, admission, runtime, identity, network, detection) because no single stage stops a compromised process. I reach for this framing whenever asked how to build, admit and run workloads safely on Kubernetes.
Key definitions
- Digest: the sha256 hash of image content. It is the only image reference that cannot be re-pointed; tags are mutable metadata.
- SBOM: a package inventory (SPDX or CycloneDX) that answers exposure questions without rescanning.
- Provenance (SLSA attestation): evidence that a named pipeline built this digest from a given source revision.
- Pod Security Admission: namespace-label enforcement of the privileged, baseline and restricted levels, in enforce, audit or warn mode.
- Reachability: whether a vulnerable package is loaded or executed at runtime. It outranks raw CVSS in triage.
- Drift: a running binary that differs from the image admission approved.
How it works
- The kernel is shared, so a privileged or escaped process reaches the node and every pod on it.
- CI scans and signs the image digest. Admission checks the signature and policy against the digest the kubelet will actually run.
- Runtime controls shrink what a compromised process can do: non-root UID, dropped capabilities, allowPrivilegeEscalation false, read-only root filesystem, RuntimeDefault seccomp.
- Identity and network cut the next rungs: no token mounted unless needed, default-deny NetworkPolicy on a CNI that enforces it.
When to use and when not to
| Decision | Use it for | Does not establish, or choose instead |
|---|---|---|
| Trivy exit 0 | No fixable HIGH/CRITICAL matches in the scanner's data at scan time | Safe configuration, privilege, hostPath or runtime behavior |
| Deploy by tag | Human-readable labels | Release identity: deploy by digest |
| Shared nodes for mutually untrusted tenants | Only with hardening in place | Dedicated nodes or clusters, or a sandboxed RuntimeClass |
| NetworkPolicy | Layer 3/4 segmentation, if the CNI enforces it | Authentication or encryption: use mTLS or a mesh |
| readOnlyRootFilesystem | Blocks writes into image layers | Writable emptyDir or PVC mounts for the paths that need them |
| Distroless base | Smaller CVE surface, no shell for an attacker | Ephemeral debug containers for operators |
Traps interviewers probe
- Reading Trivy exit 0 as safety. Fix: state it narrowly, as no fixable HIGH/CRITICAL matches at scan time. Then check privileged mode, hostPath, hostPID and runtime detection separately.
- Pinning a tag for immutability. Fix: deploy by digest and roll back to the digest that ran. A tag re-pushed by CI, or reused under IfNotPresent with a warm node cache, runs whatever it last pointed to.
- Assuming NetworkPolicy is enforced. Fix: confirm the CNI implements it. Flannel does not, so an accepted policy gives no isolation. Prove it with a connection that must fail.
- Forgetting the namespace in a policy peer. A podSelector alone matches pods in the policy's own namespace. Fix: put a namespaceSelector in the same from element to match pods in another namespace. Ports apply to the pod port after Service targetPort translation.
- Treating Secrets as protected. Secret data is base64 unless etcd encryption at rest is on, and a list verb returns the full objects. Fix: restrict get, list and watch on secrets, restrict pod creation that can mount them, and enable etcd encryption.
Interview tips
Open with: "Containers share the host kernel, so I control what gets built, admitted, run with least privilege, reachable on the network, and detected, and I deploy by digest."
Follow-ups to expect:
- How does admission verify a signature, and what does the signature not prove?
- A base image CVE lands. What do you do in the first day?
- Can a pod that can create pods escalate? Through which mounted secrets, service accounts or privileged settings?
- How do you move existing namespaces to restricted? Set warn and audit labels, fix flagged pods, then enforce. Running pods keep running, but new ones and template changes get rejected.
- When do you need a sandboxed RuntimeClass?
30-second answer outline:
- Threat: shared kernel, and the lateral path pod, service account, API server, node, cloud credentials.
- Build: minimal base, no secrets in layers, scan, SBOM, sign the digest with provenance.
- Admit: verify signature and digest, enforce restricted PSA.
- Run: non-root, dropped capabilities, read-only root, RuntimeDefault seccomp, no token unless needed, default-deny NetworkPolicy on an enforcing CNI.
- Detect and respond: runtime rules, then replace the workload from a known-good digest rather than cleaning it.
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.