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 →
- Remove the values and rotate the exposed secrets.
- 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 .
- Inject runtime secrets from Kubernetes Secrets, Vault or Secrets Manager.
- 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".
More on Container and IaC Security
A team asks whether to use `ubuntu`, `alpine` or a distroless base image. How do you advise?Beginner`trivy image` shows 300 vulnerabilities in your app image. How do you bring this down?BeginnerA Dockerfile runs the app as root. How do you fix it and prove the fix?IntermediateCheckov fails a Terraform PR because an S3 bucket allows public access. What do you change?BeginnerHow do you set up image scanning so nothing vulnerable reaches production?IntermediateAn image passed scanning three weeks ago and runs in production. A new critical CVE is published today. What happens next?Intermediate