Skip to content

Lesson 14 of 14 · 15m

The Hardening Checklist

Every lesson lands in a config line: dropped caps, no-new-privileges, RuntimeDefault seccomp, read-only rootfs, PSA enforcement, and a patch cadence.

The full stack, in order

Every lesson in this course lands in a config line. Here are all of them.

The container spec

Docker, single container:

docker run \
  --cap-drop=ALL --cap-add=NET_BIND_SERVICE \
  --security-opt=no-new-privileges:true \
  --security-opt seccomp=default \
  --read-only --tmpfs /tmp --tmpfs /run \
  --memory=512m --cpus=1.5 \
  -u 1000 \
  app

Each flag maps to a lesson: --cap-drop=ALL collapses the bounding set to nothing and you add back only what's needed; no-new-privileges sets PR_SET_NO_NEW_PRIVS so setuid binaries can't elevate; seccomp=default is the syscall gate (never unconfined); --read-only makes the image filesystem immutable with tmpfs for the directories that must write; --memory/--cpus are DoS meters, not walls; -u 1000 runs non-root so even a full cap set means less. Never --privileged, never --network host / --pid host / --ipc host, never -v /var/run/docker.sock, and keep bind mounts minimal and read-only where possible.

Kubernetes, the equivalent pod spec:

spec:
  automountServiceAccountToken: false
  runtimeClassName: gvisor        # for untrusted workloads
  securityContext:
    runAsNonRoot: true
    runAsUser: 1000
    fsGroup: 1000
    seccompProfile:
      type: RuntimeDefault
  containers:
  - securityContext:
      allowPrivilegeEscalation: false
      readOnlyRootFilesystem: true
      capabilities:
        drop: ["ALL"]
        add: ["NET_BIND_SERVICE"]

Pod-level vs container-level securityContext is a real distinction — capabilities and allowPrivilegeEscalation are per-container; runAsNonRoot/seccompProfile can sit at pod level and cover everything in it.

Enforcement, because YAML drifts

Checking specs by eye fails at scale. The controls that persist:

  • Pod Security Admission — built into Kubernetes since 1.23 (GA in 1.25). Label a namespace pod-security.kubernetes.io/enforce=restricted and every pod there must satisfy the restricted profile: no privileged, no host namespaces, caps dropped, runAsNonRoot, seccomp set. enforce, audit, and warn modes exist per level (privileged/baseline/restricted) so you can phase it in with warn before enforce.
  • Gatekeeper / Kyverno — admission policies for the rules PSA doesn't cover: "no hostPath," "only images from these registries," "runtimeClassName must be gvisor in this namespace."
  • Runtime detection — Falco's syscall rules detect drift after deployment: shells spawned in containers, unexpected mounts, writes to sensitive paths, outbound connections that the workload never makes. Post-exploit detection is the layer for the zero-day you don't have yet.

Images, because the box starts shipped

Hardening the runtime doesn't help if the image itself is hostile or ancient. Pull by digest or signed tag where provenance matters — Sigstore/cosign signatures verify who built it, an SBOM tells you what's in it, and a scanner (Trivy, Grype) maps its packages to known CVEs. Minimal base images pay twice: fewer packages to patch, and fewer tools an attacker inherits — a distroless image with no shell makes "run a shell in the container" a harder post-exploit step. None of this is escape defense strictly, but a compromised workload that can't curl out or sh around moves slower, and slower is detectable. Ship images you can explain.

Audit, because configuration decays

For a running Docker host:

docker inspect --format '{{.HostConfig.Privileged}} {{.HostConfig.CapAdd}} {{.HostConfig.CapDrop}} {{.HostConfig.PidMode}} {{.HostConfig.NetworkMode}} {{.HostConfig.IpcMode}}' <ctr>
readlink /proc/<pid>/ns/*
capsh --decode=<CapBnd hex>

For Kubernetes: kube-bench against the CIS Kubernetes Benchmark; docker bench security for the CIS Docker Benchmark; a cron'd grep over manifests for privileged, hostPath, hostPID, hostNetwork, hostIPC, docker.sock, mountPropagation: Bidirectional, seccompProfile: Unconfined.

For hosts: kernel version vs the distro security channel, kernel.unprivileged_userns_clone, user.max_user_namespaces, runc/containerd/dockerd/kubelet/toolkit versions.

The cadence

Two things hold the wall up after config is done. First, patch cadence — kernel, runtime, kubelet, toolkit — because every LPE is an escape and runc is host code. Second, the architecture choice: namespaces for trusted workloads, userns-remap or rootless for semi-trusted, gVisor or Kata for untrusted code. Pick the wall to match who wrote the code, and the checklist keeps the wall honest.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.