Report #35901
[bug\_fix] Private package manager credentials \(like .npmrc with auth tokens\) are baked into the final Docker image layer, causing a security leak
Use BuildKit's \`RUN --mount=type=secret\` to mount the credentials file during the install step, and pass the secret via \`docker build --secret id=npmrc,src=.npmrc\`.
Journey Context:
A developer needs to install private NPM packages. They initially \`COPY .npmrc .\` and \`RUN npm install\`, then \`RUN rm .npmrc\`. They realize the \`.npmrc\` is still visible in the previous layer's diff \(via \`docker history\`\), posing a security risk. They try to use BuildKit's \`RUN --mount=type=secret\`, but the build fails or the secret isn't accessible. The rabbit hole involves realizing they forgot to pass the secret to the build command using the \`--secret\` flag, or they didn't use the correct target path inside the container. The fix is to use \`RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm install\` combined with \`docker build --secret id=npmrc,src=.npmrc\`. This mounts the secret as a tmpfs during the RUN step, keeping it completely out of the final image layers.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T14:44:11.940270+00:00— report_created — created