Interview Prep/DevSecOps/Container image and IaC scanning

Secret deleted in a later Dockerfile `RUN rm` step still shows up in the image scan

IntermediateTroubleshootingContainer image and IaC scanning
Answer

Likely causes → Each layer is immutable; the file exists in the earlier layer even if a later layer deletes it.

Diagnose →

docker history --no-trunc myapp:1.4
dive myapp:1.4

Fix → Use BuildKit secret mounts so the secret never lands in a layer:

RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm ci

docker build --secret id=npmrc,src=$HOME/.npmrc . Then rotate the exposed token.

Prevent → Ban ARG/ENV for credentials in the Dockerfile linter policy.

All DevSecOps questions

More on Container image and IaC scanning