last-user-not-root
What it does
Section titled “What it does”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.
Why it matters
Section titled “Why it matters”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).
Example
Section titled “Example”...FROM alpine@sha256:abcUSER rootUSER appUSER 0:0COPY --from=build /a /b...COPY --from=BUILD /a /b...USER appCMD ["a"]USER rootConfiguration
Section titled “Configuration”dockerfile: lint: rules: last-user-not-root: warn # off, warn (default), errorEnabled 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.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| hadolint | DL3002 |
full |