Skip to main content

SKY-D343 · Deployment and infrastructure

Dockerfile bakes a secret into the image

High

A Dockerfile ENV or ARG that gives a password, token, key or other secret-looking variable a literal value. ENV values are stored in the image configuration, and ARG defaults are recorded in the image history.

Languages
Dockerfile
Quality gate
counted toward the gate limits (full and diff scans). Reported under security (danger). It counts toward max_high and max_security; the detector never reports CRITICAL.
Finding type
review
Catalog name
Dockerfile literal secret build value
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

Anyone who can pull the image can read the value with docker inspect or docker history, including everyone with access to the registry, the CI cache or a leaked image tarball. Rotating the secret also means rebuilding and redeploying every image that contains it.

What Skylos flags

Dockerfile · DockerfileReported on line 4
FROM node:22-alpineWORKDIR /appENV NODE_ENV=productionENV DATABASE_PASSWORD=orders-prod-2024COPY package*.json ./RUN npm ci --omit=devCOPY . .CMD ["node", "server.js"]

What Skylos leaves alone

Dockerfile · Dockerfile
FROM node:22-alpineWORKDIR /appARG NPM_TOKENENV NODE_ENV=productionENV DATABASE_PASSWORD_FILE=/run/secrets/db_passwordENV DATABASE_PASSWORD=${DATABASE_PASSWORD}COPY package*.json ./RUN npm ci --omit=devCOPY . .CMD ["node", "server.js"]

Why Skylos leaves it alone

Every name here looks secret, but no value is a literal secret: ARG NPM_TOKEN has no default, DATABASE_PASSWORD_FILE holds a path (names ending in _FILE, _PATH, _DIR, _NAME or _ARN are references), and ${DATABASE_PASSWORD} is a reference to another variable.

How Skylos decides

  1. Runs with --danger. Reads the same Dockerfiles as SKY-D342 (Dockerfile, Dockerfile.*, *.dockerfile) and joins lines that end in \.
  2. For ARG, reads each NAME=value; an ARG without = has no default and is skipped. For ENV, reads each NAME=value, or the older ENV NAME value form.
  3. A name counts as secret when it contains PASSWORD, PASSWD, SECRET, TOKEN, API_KEY, ACCESS_KEY, CLIENT_SECRET, CREDENTIAL(S) or PRIVATE_KEY as a whole underscore-separated part, in any case, and does not end in _FILE, _PATH, _DIR, _NAME or _ARN.
  4. The value must be a literal: not empty and not starting with $.
  5. Reports HIGH on the line where the instruction starts, once per instruction even when it sets several secret names.

How to fix it

Keep secrets out of the image. Give the container the secret at run time, here as a file mounted by Docker or Kubernetes secrets, and let the image say only where to find it. A token needed during the build belongs in RUN --mount=type=secret.

Dockerfile · Dockerfile · the fix, against the flagged file
FROM node:22-alpineWORKDIR /appENV NODE_ENV=productionRemoved: ENV DATABASE_PASSWORD=orders-prod-2024Added: ENV DATABASE_PASSWORD_FILE=/run/secrets/db_passwordCOPY package*.json ./RUN npm ci --omit=devCOPY . .CMD ["node", "server.js"]

When it can be wrong

  • Settings whose names merely contain a secret word are reported: ENV PASSWORD_MIN_LENGTH=12 and ENV AUTH_TOKEN_TTL=3600 both are.
  • Placeholder values such as changeme are reported like real ones, which is usually right: the default ends up in production.
  • Only ENV and ARG are read. A secret written into a file with RUN echo ... > /root/.npmrc is not reported by this rule.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Put the marker on a comment line directly above the ENV or ARG. After the value, # is not a comment in a Dockerfile; it becomes part of the value.

    Dockerfile
    # skylos: ignore[SKY-D343] throwaway database for the CI image onlyENV DATABASE_PASSWORD=orders-prod-2024
  • [tool.skylos] ignore = ["SKY-D343"] turns the rule off for the project.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.