Interview Prep/DevSecOps/Container and IaC Security

A Dockerfile runs the app as root. How do you fix it and prove the fix?

IntermediateScenarioContainer and IaC Security
Answer

Situation read → Root in a container increases the impact of any breakout or volume misconfiguration.

What I'd do →

  1. Create a user and switch to it:
RUN addgroup -S app && adduser -S app -G app
USER 10001:10001
  1. Use a numeric UID so Kubernetes runAsNonRoot can verify it.
  2. Set securityContext: runAsNonRoot: true, allowPrivilegeEscalation: false, capabilities.drop: [ALL].
  3. Enforce with Hadolint rule DL3002 and a Kyverno or PSA policy.
  4. Verify: docker run --rm app:1.0 id shows non-zero uid.

Why → Numeric UID matters: kubelet cannot validate a named user.

Interview tip → Mention that ports below 1024 need NET_BIND_SERVICE or a higher port.

All DevSecOps questions Roadmap: Policy as code

More on Container and IaC Security