Skip to content

last-user-not-root

Dockerfilecorrectnessno fixdefault: warndockerfile/hadolint

Reports a stage whose last USER is root, on that USER. That is root or 0, also root:group and 0:group. Every stage is checked, build stages too. A stage with no USER instruction is not reported.

The container’s main process runs as the last user. If the application is compromised, the attacker is root inside the container, which makes it easier to damage mounted volumes or to break out of the container, and files the process writes to a volume are owned by root.

End the stage with an unprivileged USER (a numeric one, see numeric-user-id).

Reported
...
FROM alpine@sha256:abc
USER root
USER app
USER 0:0
COPY --from=build /a /b
...
COPY --from=BUILD /a /b
...
USER app
CMD ["a"]
USER root
dockerfile:
lint:
rules:
last-user-not-root: warn # off, warn (default), error

Enabled by the presets: dockerfile/hadolint.

Suppress one line with sudsy-disable-next-line last-user-not-root in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
hadolint DL3002 full