no-secret-in-env
What it does
Section titled “What it does”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.
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”...USER 1000:1000USER $UIDENV DB_PASSWORD=xENV A=1 NPM_TOKEN=yARG GITHUB_TOKENARG VERSION=1ENV AWS_ACCESS_KEY_ID=xConfiguration
Section titled “Configuration”dockerfile: lint: rules: no-secret-in-env: warn # off, warn (default), errorEnabled 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.
Upstream equivalents
Section titled “Upstream equivalents”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. |