SKY-D343 · Deployment and infrastructure
Dockerfile bakes a secret into the image
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 towardmax_highandmax_security; the detector never reports CRITICAL. - Finding type
- review
- Catalog name
- Dockerfile literal secret build value
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
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
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
- Runs with
--danger. Reads the same Dockerfiles as SKY-D342 (Dockerfile,Dockerfile.*,*.dockerfile) and joins lines that end in\. - For
ARG, reads eachNAME=value; anARGwithout=has no default and is skipped. ForENV, reads eachNAME=value, or the olderENV NAME valueform. - A name counts as secret when it contains
PASSWORD,PASSWD,SECRET,TOKEN,API_KEY,ACCESS_KEY,CLIENT_SECRET,CREDENTIAL(S)orPRIVATE_KEYas a whole underscore-separated part, in any case, and does not end in_FILE,_PATH,_DIR,_NAMEor_ARN. - The value must be a literal: not empty and not starting with
$. - 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.
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=12andENV AUTH_TOKEN_TTL=3600both are. - Placeholder values such as
changemeare reported like real ones, which is usually right: the default ends up in production. - Only
ENVandARGare read. A secret written into a file withRUN echo ... > /root/.npmrcis 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
ENVorARG. 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.