Skip to content

no-secret-in-env

Dockerfilesuspiciousno fixdefault: warndockerfile/hadolint

Reports an ARG or ENV whose name suggests a secret. The name contains api_key, client_key, password, private, secret, token or username (any case), or is one of a list of well-known credential variables such as AWS_ACCESS_KEY_ID. Only the name is read, so PASSWORD_FILE and PRIVATE_NET are reported too, and the value is not looked at.

The value of an ENV is stored in the image configuration, and the value of an ARG shows up in docker history. Anyone who can pull the image can read them (docker inspect, docker history), even when a later instruction unsets them.

A secret needed only during the build belongs in a build secret (RUN --mount=type=secret,id=name ...); a runtime secret belongs in the environment of the running container or a secrets store.

Reported
...
USER 1000:1000
USER $UID
ENV DB_PASSWORD=x
ENV A=1 NPM_TOKEN=y
ARG GITHUB_TOKEN
ARG VERSION=1
ENV AWS_ACCESS_KEY_ID=x
dockerfile:
lint:
rules:
no-secret-in-env: warn # off, warn (default), error

Enabled by the presets: dockerfile/hadolint.

Suppress one line with sudsy-disable-next-line no-secret-in-env in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
hadolint DL3064 partial Names are matched in the text of the instruction, so a later pair of a multi-pair ENV with quoted values may be missed.