Interview Prep/Kubernetes/Security Hardening & Compliance

Why should containers run as non-root?

BeginnerProductionSecurity Hardening & Compliance
Answer

If an attacker gets code execution as root in a container, a runtime or kernel bug gives them root on the node more easily, and writes to volumes happen as root. Set runAsNonRoot: true, a numeric runAsUser, and build images with a dedicated user. Restricted PSA enforces this.

RUN addgroup -S app && adduser -S app -G app
USER 10001
All Kubernetes questions Roadmap: Kubernetes networking, storage & scaling

More on Security Hardening & Compliance