Interview Prep/DevSecOps/Container and IaC Security

You find `ENV DB_PASSWORD=...` and `ARG NPM_TOKEN` in a Dockerfile. What is wrong and how do you fix it?

BeginnerScenarioContainer and IaC Security
Answer

Situation read → Values baked into ENV ship in every layer's metadata. ARG values show in docker history.

What I'd do →

  1. Remove the values and rotate the exposed secrets.
  2. Use BuildKit secret mounts for build-time secrets:
RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm ci
docker build --secret id=npmrc,src=$HOME/.npmrc -t app:1.0 .
  1. Inject runtime secrets from Kubernetes Secrets, Vault or Secrets Manager.
  2. Scan images for secrets: trivy image --scanners secret app:1.0.

Why → Secret mounts are not stored in any image layer.

Interview tip → Say "build secrets via mounts, runtime secrets via the platform".

All DevSecOps questions Roadmap: Policy as code

More on Container and IaC Security