Skip to the page

Containers in depth · mid

Non-root containers and image scanning

Running as root in a container gives an attacker a short path to the host if anything escapes. Mounting the Docker socket gives away the host, and scan results need triage, not panic.

The notes

What you must know

  • Root in a container is UID 0 on the shared kernel with reduced capabilities. A container escape then gives host root. Non-root limits the damage.
  • --privileged gives every capability and device, effectively the host. The Docker socket lets a container start a privileged container that mounts the host root, so it is also the host. A read-only mount does not help.
  • Hardening: USER with a numeric id, runAsNonRoot true, allowPrivilegeEscalation false, drop ALL capabilities and add back only what is needed, a read-only root filesystem, and a seccomp profile.
  • For builds in CI, use a rootless builder such as BuildKit or Kaniko instead of mounting the host socket.
  • Scan triage: is the package in the final image and used at runtime, is it reachable, is there a known exploit (CISA Known Exploited Vulnerabilities list, EPSS), and is a fix available.
  • Quickest fix: rebuild on the latest patch of the same base image. Most base image CVEs are already fixed upstream.
  • If no fix exists: a time-limited exception with a reason, owner and expiry (a VEX statement or ignore entry), and compensating controls. Security approves and the release manager decides with the risk visible.
  • Prevent: scheduled rebuilds, minimal bases and a policy that blocks only what matters.

The red pen

Common traps: mistake → fix

  • Mistake: A read-only socket mount is safe

    Fix: the API still lets a container control the host.

  • Mistake: Every critical CVE blocks a release

    Fix: triage by use, reach, exploit and fix.

  • Mistake: Root in a container is harmless

    Fix: it is the shared kernel.

Easy to hard

Questions interviewers ask, easy to hard

  1. Why should containers not run as root?
  2. What does mounting the Docker socket give away?
  3. The image scan fails the night before a release with 14 critical CVEs. What do you do?
  4. Which securityContext settings do you set?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview