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
More on Security Hardening & Compliance
What is the baseline security checklist for a production cluster?BeginnerHow should human access to the cluster be managed?BeginnerWhat is the purpose of image scanning in CI and in the cluster?BeginnerWhy not store secrets in Git or in ConfigMaps?BeginnerWhat is a default-deny NetworkPolicy baseline?BeginnerWhy should nodes be treated as immutable?Beginner