How can secrets leak through Docker image layers?
IntermediateConceptSupply Chain, SBOM, Signing and Image/IaC Scanning
Answer
Every RUN, COPY and ENV is stored in a layer. COPY .env . followed by RUN rm .env still leaves the file in the earlier layer. Build ARGs are visible in docker history.
Use BuildKit secret mounts, which expose the secret only during that RUN and never write it to a layer:
RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm ci
docker build --secret id=npmrc,src=$HOME/.npmrc .
More on Supply Chain, SBOM, Signing and Image/IaC Scanning
What is a software supply chain attack? Give examples.BeginnerExplain dependency confusion and typosquatting.IntermediateWhat is an SBOM and why do we need one?BeginnerCycloneDX vs SPDX: how do they differ?IntermediateHow do you generate and use an SBOM with Syft and Grype?BeginnerWhat is VEX?Intermediate