Containers should run as a non-root user
このページは日本語には対応しておりません。随時翻訳に取り組んでいます。
翻訳に関してご質問やご意見ございましたら、
お気軽にご連絡ください。
Description
Containers should run as a user other than root.
Rationale
A process that escapes a container keeps its user. If it runs as an unprivileged user, it lands on the host without root privileges.
Audit
Show the user of the running containers:
docker ps --quiet | xargs docker inspect --format '{{ .Name }}: User={{ .Config.User }}'
Datadog checks the running containers. It passes the rule when the container’s user, before any :, is set and is other than root and the UID 0, in any spelling that Docker reads as 0, such as 00, and fails it otherwise. A container that drops privileges in its entrypoint fails, and needs a manual review.
Add a user to the image and switch to it with a USER instruction in the Dockerfile:
RUN useradd -r -u 10001 app
USER app
Or run the container with --user.
Impact
Programs that need root inside the container stop working.
Default value
Containers run as root unless the image or the command sets a user.
References
- https://docs.docker.com/reference/dockerfile/#user
- https://docs.docker.com/engine/containers/run/#user