Container & Kubernetes Security

Container & Kubernetes Security

Containers share the host kernel — there is no hypervisor wall — and Kubernetes adds an API server, etcd, kubelets, a CNI, a runtime, and an image supply chain, each independently attackable. This foundational lesson builds the mental model: layered defense across build-time and run-time. It walks the 4 C's of cloud-native security, build-time image hardening, supply-chain integrity (signing, SBOM, SLSA), RBAC and least privilege, Pod Security Standards and admission control, default-deny NetworkPolicy, secrets handling, namespaces as a soft boundary, runtime threats from privileged containers, real container-escape CVEs, the MITRE ATT&CK Containers matrix, and the real defensive tooling and benchmarks that tie it together.

The fourteen pillars of container & Kubernetes security

From why container isolation differs from VMs to the defensive tooling that ties it together — each grounded in real standards, technique IDs, and CVEs.

1

Overview — why container & Kubernetes security is different

Key points

  • Containers share the host kernel: unlike VMs there is no hypervisor boundary, so a kernel-level weakness or an over-privileged container can become a full host compromise. The security model is namespaces + cgroups + capabilities + seccomp/LSM, not hardware isolation.
  • Kubernetes massively expands the attack surface: an API server, etcd datastore, kubelets, a CNI, a container runtime (containerd/CRI-O) and an image supply chain — each is an independently attackable component.
  • This is the FOUNDATIONAL lesson; /examples/kubernetes is the concrete worked example. The mental model to carry through: defense must be layered across build-time and run-time, because no single control (scanning, RBAC, or NetworkPolicy alone) is sufficient.
  • Authoritative baseline document for the whole topic: NIST SP 800-190 (Application Container Security Guide), which enumerates image, registry, orchestrator, container and host OS risks.
  • The canonical adversary reference is the MITRE ATT&CK Containers matrix, which models real techniques used against containerized environments.

References

NIST SP 800-190 Application Container Security Guide
ATT&CK Matrix: Containers
CWE-653 Improper Isolation or Compartmentalization
2

The 4 C's of cloud-native security (Cloud, Cluster, Container, Code)

Key points

  • Defense-in-depth layering popularized by the Kubernetes documentation: each outer layer protects the inner ones, and a weakness in an outer layer (e.g. Cloud IAM) cannot be fully fixed by hardening an inner one (e.g. Code).
  • Cloud: the infrastructure trust base — provider IAM, node host hardening, control-plane network exposure, and encrypted etcd. A misconfigured cloud IAM role or an internet-exposed kubelet/API server undermines everything above it. Align with NIST SP 800-207 Zero Trust principles.
  • Cluster: Kubernetes-level controls — RBAC, authentication, admission control, Pod Security Standards, NetworkPolicy, and secrets handling. This is where most exploitable misconfiguration lives (OWASP Kubernetes Top 10).
  • Container: image provenance, minimal base images, dropped capabilities, non-root, read-only root filesystem, seccomp/AppArmor/SELinux profiles.
  • Code: the application itself — dependency hygiene, no hardcoded secrets, TLS, and the standard AppSec controls (OWASP Web/API Top 10) — still applies inside the container.
  • Benchmark the Cluster and Container layers against the CIS Kubernetes Benchmark and CIS Docker Benchmark.

References

NIST SP 800-207 Zero Trust Architecture
OWASP Kubernetes Top 10
CIS Kubernetes Benchmark
CIS Docker Benchmark
CWE-16 Configuration
3

Container image security (build-time)

Key points

  • Minimal / distroless base images: shipping no shell, package manager, or extra binaries shrinks the attack surface and removes the tools an attacker needs after a foothold (e.g. Google Distroless, Chainguard/Wolfi). Smaller image = fewer CVEs to patch.
  • Image scanning (SCA): tools such as Trivy (Aqua) and Grype (Anchore) detect known-vulnerable OS packages and language dependencies before deploy. This addresses use of vulnerable/outdated components.
  • Run as non-root, drop ALL Linux capabilities and add back only what is needed, set readOnlyRootFilesystem, and apply a seccomp RuntimeDefault profile plus AppArmor/SELinux. Running as root inside a container is execution with unnecessary privilege.
  • Pin images by SHA-256 digest, not by mutable tags like :latest. Tags can be repointed at a malicious image after you test the 'good' one — a classic time-of-check/time-of-use integrity gap; digest pinning gives content-addressable integrity.
  • Never bake secrets into image layers — they persist in the layer history and registry even if 'deleted' in a later layer.
  • Multi-stage builds keep build tooling (compilers, credentials) out of the final runtime image.

References

CWE-1104 Use of Unmaintained Third Party Components
CWE-1395 Dependency on Vulnerable Third-Party Component
CWE-250 Execution with Unnecessary Privileges
CWE-494 Download of Code Without Integrity Check
CWE-367 Time-of-check Time-of-use (TOCTOU) Race Condition
CWE-798 Use of Hard-coded Credentials
NIST SP 800-190 Application Container Security Guide
4

Supply-chain integrity — signing, SBOM, provenance, SLSA

Key points

  • Image signing with Sigstore/cosign: Fulcio issues short-lived signing certificates bound to an OIDC identity, signatures are recorded in the Rekor transparency log, and verifiers enforce that only signed images run. This counters deploying tampered/unverified images.
  • Verify signatures at admission time (e.g. a Kyverno or Gatekeeper/OPA policy, or cosign verification) so unsigned or untrusted-signer images are rejected — failure to verify a cryptographic signature is itself a weakness class.
  • SBOM (Software Bill of Materials): generate with syft (or Trivy) in SPDX or CycloneDX format so you can answer 'am I affected by CVE-X?' across the fleet. SPDX is standardized as ISO/IEC 5962:2021.
  • Rekor's append-only transparency log is conceptually modeled on Certificate Transparency, providing tamper-evident, publicly auditable signing records.
  • SLSA (Supply-chain Levels for Software Artifacts, OpenSSF) Build track: Build L1 = provenance exists; L2 = signed provenance from a hosted build service; L3 = hardened, non-falsifiable provenance from an isolated builder. Higher levels reduce the risk of a compromised build pipeline injecting code.
  • Align the secure build process with the NIST Secure Software Development Framework (SSDF).

References

CWE-829 Inclusion of Functionality from Untrusted Control Sphere
CWE-347 Improper Verification of Cryptographic Signature
CWE-1357 Reliance on Insufficiently Trustworthy Component
ISO/IEC 5962:2021 SPDX Software Bill of Materials
RFC 6962 Certificate Transparency
NIST SP 800-218 Secure Software Development Framework (SSDF)
OWASP Kubernetes Top 10: K02 Supply Chain Vulnerabilities
5

Build-time vs run-time — two distinct control planes

Key points

  • Build-time controls are preventive and shift-left: base-image selection, SCA scanning, SBOM generation, signing, and policy gates in CI. They stop a bad artifact from ever being produced or admitted.
  • Run-time controls are detective/responsive: admission control at deploy, behavioral monitoring of running containers, NetworkPolicy enforcement, and host-level threat detection. They catch what scanning missed and what only manifests during execution (e.g. a process spawning a shell, an unexpected outbound connection).
  • A scanned-and-signed image is necessary but not sufficient: a zero-day, a runtime misconfiguration, or a compromised legitimate dependency only becomes visible at run-time. This is why Falco-style syscall/eBPF monitoring complements Trivy/Grype scanning.
  • Admission control is the hinge between the two: it is the last build-time gate and the first run-time gate, rejecting workloads that violate policy before a Pod ever schedules.

References

NIST SP 800-190 Application Container Security Guide
OWASP Kubernetes Top 10: K04 Lack of Centralized Policy Enforcement
OWASP Kubernetes Top 10: K05 Inadequate Logging and Monitoring
6

Kubernetes RBAC & least privilege

Key points

  • RBAC binds subjects (users, groups, ServiceAccounts) to Roles/ClusterRoles via RoleBindings/ClusterRoleBindings. Least privilege means granting the minimum verbs on the minimum resources in the minimum scope (namespace over cluster).
  • Dangerous grants to avoid: cluster-admin to ServiceAccounts, wildcard verbs/resources, and 'escalation primitives' — create/update on pods (can mount secrets/host), the secrets verb (read all secrets), pods/exec, and bind/escalate which let a subject grant itself more rights. Missing or overly broad authorization is the core risk.
  • Every Pod gets a ServiceAccount token by default; disable automountServiceAccountToken where the workload does not call the API, since a compromised app otherwise inherits that identity's RBAC.
  • Audit RBAC regularly — overly permissive RBAC is one of the most common and impactful cluster misconfigurations.
  • Historical reminder of API-server authz weight: CVE-2018-1002105 allowed unauthenticated escalation through the aggregated API proxy, underscoring why control-plane authz must be tight and patched.

References

CWE-862 Missing Authorization
CWE-863 Incorrect Authorization
CWE-269 Improper Privilege Management
CWE-250 Execution with Unnecessary Privileges
CVE-2018-1002105
OWASP Kubernetes Top 10: K03 Overly Permissive RBAC Configurations
CIS Kubernetes Benchmark
7

Pod Security Standards & admission control

Key points

  • PodSecurityPolicy (PSP) was deprecated in Kubernetes 1.21 and removed in 1.25; the built-in replacement is Pod Security Admission (PSA), which enforces the three Pod Security Standards.
  • The three Pod Security Standards: Privileged (unrestricted), Baseline (blocks known privilege escalations — no hostNamespaces, no privileged, restricted hostPath), and Restricted (heavily hardened — non-root, drop ALL capabilities, seccomp RuntimeDefault, no privilege escalation). Aim for Restricted on workload namespaces.
  • PSA is applied per-namespace via labels with enforce/audit/warn modes, letting you roll out enforcement gradually.
  • For policy beyond the three tiers (image-signature verification, registry allow-lists, required labels), use a validating admission webhook engine: OPA/Gatekeeper or Kyverno. This provides centralized policy enforcement across the cluster.
  • Admission control rejects non-compliant Pods before scheduling — the practical enforcement point for the Container-layer hardening defined earlier.

References

OWASP Kubernetes Top 10: K01 Insecure Workload Configurations
OWASP Kubernetes Top 10: K04 Lack of Centralized Policy Enforcement
CWE-250 Execution with Unnecessary Privileges
CWE-16 Configuration
CIS Kubernetes Benchmark
8

NetworkPolicy — default-deny & microsegmentation

Key points

  • By default all Pods can talk to all other Pods across all namespaces — a flat network. A NetworkPolicy selecting Pods switches them to deny-by-default for the specified direction (ingress/egress); you then explicitly allow required flows.
  • Best practice: a default-deny-all policy per namespace, then narrow allow rules using podSelector and namespaceSelector — this is microsegmentation that contains lateral movement after a single Pod is compromised.
  • NetworkPolicy is enforced by the CNI plugin, not the API server: it only works if the CNI supports it (e.g. Calico, Cilium). Applying policies under a non-enforcing CNI gives a false sense of security.
  • Restrict egress too, not just ingress — egress controls hinder data exfiltration and command-and-control callbacks from a compromised workload.
  • Missing network segmentation lets an attacker who lands in one Pod pivot freely; it maps directly to lateral movement in ATT&CK.

References

OWASP Kubernetes Top 10: K07 Missing Network Segmentation Controls
CWE-668 Exposure of Resource to Wrong Sphere
NIST SP 800-207 Zero Trust Architecture
ATT&CK T1610 Deploy Container
9

Secrets handling in Kubernetes

Key points

  • Kubernetes Secrets are only base64-encoded, NOT encrypted — anyone with read access (or etcd access) sees them in cleartext. Base64 is encoding, not protection.
  • Enable encryption at rest for Secrets in etcd via an EncryptionConfiguration, ideally backed by a KMS provider rather than a static local key.
  • Lock down access with RBAC: the secrets get/list verb effectively exfiltrates credentials, so restrict it tightly and prefer per-namespace scoping.
  • Prefer external secret managers (HashiCorp Vault, cloud KMS via the External Secrets Operator, or SOPS for GitOps) over plaintext manifests committed to git; never hardcode credentials in images or manifests.
  • Mounting secrets as files (tmpfs) instead of environment variables reduces leakage via /proc, crash dumps, and child-process inheritance.
  • ATT&CK models attackers harvesting orchestration credentials — e.g. unsecured container/orchestrator API credentials.

References

CWE-312 Cleartext Storage of Sensitive Information
CWE-522 Insufficiently Protected Credentials
CWE-798 Use of Hard-coded Credentials
ATT&CK T1552.007 Unsecured Credentials: Container API
OWASP Kubernetes Top 10: K08 Secrets Management Failures
10

Namespaces as a soft boundary

Key points

  • Kubernetes namespaces are an organizational/scoping boundary (for RBAC, quotas, NetworkPolicy targeting) — they are NOT a strong security or tenancy boundary by themselves.
  • Cluster-scoped resources (Nodes, PersistentVolumes, ClusterRoles, CRDs) and the shared control plane span all namespaces; a privileged or escaped workload is not contained by a namespace.
  • For hard multi-tenancy treat namespaces as one layer among many: combine them with strict RBAC, default-deny NetworkPolicy, Pod Security Restricted, resource quotas, and ideally separate node pools or separate clusters for untrusted tenants.
  • Relying on namespaces alone for isolation is an improper-isolation weakness.

References

CWE-653 Improper Isolation or Compartmentalization
CWE-668 Exposure of Resource to Wrong Sphere
NIST SP 800-190 Application Container Security Guide
11

Runtime threats — privileged containers & dangerous host access

Key points

  • privileged: true effectively disables container isolation — it grants nearly all capabilities and device access, making host compromise trivial. It is the single most dangerous Pod setting.
  • hostPID lets the container see and signal host processes (and read their /proc, including secrets in memory/cmdline); hostNetwork puts the container directly on the host network namespace, bypassing NetworkPolicy and exposing host-local services; hostIPC shares host shared-memory.
  • hostPath volumes mount host filesystem paths into the container — mounting /, the Docker/containerd socket, or /var/run gives a direct path to host takeover. CVE-2021-25741 abused subPath/hostPath symlinks to escape to arbitrary host files.
  • CAP_SYS_ADMIN is nearly root-equivalent — it enables mount operations and cgroup manipulation used in multiple escape techniques. Drop ALL capabilities and add back only the minimum.
  • containerd-shim host-network exposure (CVE-2020-15257) showed how hostNetwork plus an exposed runtime socket leads to escape — another reason to deny hostNetwork.
  • These map to ATT&CK Escape to Host and Deploy Container; a privileged/hostPath Pod is the classic deployment used to break out.

References

CWE-250 Execution with Unnecessary Privileges
CWE-269 Improper Privilege Management
CWE-668 Exposure of Resource to Wrong Sphere
ATT&CK T1611 Escape to Host
ATT&CK T1610 Deploy Container
CVE-2021-25741
CVE-2020-15257
OWASP Kubernetes Top 10: K01 Insecure Workload Configurations
12

Container escape to the host (real CVEs)

Key points

  • CVE-2019-5736 (runc): a malicious container could overwrite the host runc binary via /proc/self/exe and gain root on the host the next time runc executed — the defining container-escape CVE.
  • CVE-2024-21626 (runc 'Leaky Vessels'): leaked internal file descriptors combined with a crafted WORKDIR let a process gain a handle to the host filesystem and escape; patched in runc 1.1.12.
  • CVE-2022-0492 (Linux kernel): a missing permission check on cgroup v1 release_agent allowed a container with CAP_SYS_ADMIN (or via user namespaces) to execute code on the host.
  • Escape paths cluster into themes: vulnerable runtime/kernel (the CVEs above), over-privileged config (privileged, CAP_SYS_ADMIN, mounted host socket), and host mounts (hostPath / docker.sock). Defense = patch runtimes + deny privilege/host access via Pod Security and admission control.
  • Detect escape attempts at run-time with Falco/eBPF rules (e.g. shell-in-container, sensitive mount, write under /proc) since signatures and scanning cannot catch a zero-day escape in progress.
  • All of these realize ATT&CK Escape to Host (T1611), typically after an initial Exploit Public-Facing Application foothold.

References

CVE-2019-5736
CVE-2024-21626
CVE-2022-0492
ATT&CK T1611 Escape to Host
ATT&CK T1190 Exploit Public-Facing Application
CWE-269 Improper Privilege Management
13

MITRE ATT&CK Containers matrix — adversary mapping

Key points

  • T1610 Deploy Container — adversaries deploy a container (often privileged or with host mounts) to execute code, evade defenses, or stage escape; mitigated by admission control and Pod Security.
  • T1611 Escape to Host — breaking out of the container to the underlying node via privileged config, host mounts, or a runtime/kernel CVE; mitigated by dropping privileges, denying hostPath/hostPID/hostNetwork, and patching runc/kernel.
  • T1613 Container and Resource Discovery — enumerating Pods, nodes, namespaces, and the kubelet/API to map the environment; mitigated by tight RBAC and restricting API/kubelet access.
  • T1609 Container Administration Command — abusing the container runtime or orchestrator administration channel (e.g. kubectl exec, kubelet, Docker API) to run commands in containers; mitigated by RBAC on pods/exec and securing the kubelet.
  • Supporting techniques in the matrix: T1612 Build Image on Host, T1525 Implant Internal Image (poisoning a registry image), T1552.007 Unsecured Credentials: Container API, T1053.007 Scheduled Task/Job: Container Orchestration Job (persistence via CronJob/DaemonSet), and T1496 Resource Hijacking (cryptomining in compromised clusters).
  • Use this matrix as the threat-modeling backbone: each Kubernetes control taught above maps to disrupting one or more of these techniques.

References

ATT&CK T1610 Deploy Container
ATT&CK T1611 Escape to Host
ATT&CK T1613 Container and Resource Discovery
ATT&CK T1609 Container Administration Command
ATT&CK T1612 Build Image on Host
ATT&CK T1525 Implant Internal Image
ATT&CK T1552.007 Unsecured Credentials: Container API
ATT&CK T1053.007 Scheduled Task/Job: Container Orchestration Job
ATT&CK T1496 Resource Hijacking
14

Defensive tooling & benchmarks (real names)

Key points

  • Image/SCA scanning: Trivy (Aqua Security) and Grype (Anchore) — find vulnerable OS packages and dependencies; run in CI and as an admission/registry gate.
  • Supply chain: cosign (Sigstore) for signing/verification, syft for SBOM generation (SPDX/CycloneDX), and SLSA provenance for build integrity.
  • Runtime detection: Falco (CNCF) using syscalls/eBPF to alert on anomalous container behavior (shell spawned, sensitive mount, unexpected egress); pairs with admission engines Kyverno or OPA/Gatekeeper.
  • Benchmarks & posture: CIS Kubernetes Benchmark and CIS Docker Benchmark for configuration hardening; kube-bench automates CIS K8s checks. NIST SP 800-190 for the overall container risk framework.
  • Governance mapping: these technical controls support ISO/IEC 27001:2022 Annex A objectives (e.g. access control, secure development, logging) and the NIST SSDF for the build pipeline.

References

NIST SP 800-190 Application Container Security Guide
CIS Kubernetes Benchmark
CIS Docker Benchmark
NIST SP 800-218 Secure Software Development Framework (SSDF)
ISO/IEC 27001:2022 Information security management systems
ISO/IEC 5962:2021 SPDX Software Bill of Materials

See it on a real cluster

Theory becomes concrete in the worked Kubernetes example: trace how a misconfigured workload, an over-permissive RBAC role, and a privileged container chain into a host compromise — and which control breaks each link.