You find a database password baked into a Docker image layer that's in a public registry. What do you do?
IntermediateScenarioSecurity incidents
Answer
Situation read → Removing it in a later layer doesn't help; every layer is downloadable. Anyone who pulled the image has the password.
What I'd do →
- Rotate the password now and check database logs for logins from unknown sources.
- Make the repository private or delete the affected tags.
- Find how it got in:
ENV DB_PASSWORD=..., a copied.envfile, orARGvalues (visible indocker history).
docker history --no-trunc myorg/api:1.4.0 | grep -i pass
- Fix the build: add
.envto.dockerignore, use BuildKit secret mounts for build-time secrets, and inject runtime secrets from Secrets Manager or Kubernetes Secrets. - Scan images for secrets in CI (Trivy has a secret scanner) and fail the build on findings.
Why → Image layers are permanent history; the only real fix is rotation.
Interview tip → Mention that ARG values appear in docker history; many people think they're safe.
More on Security incidents
An AWS access key for a production IAM user was pushed to a public GitHub repo 20 minutes ago. What do you do in the first 30 minutes?AdvancedYou find pods in your cluster running a crypto miner. What do you do?AdvancedA critical CVE is announced in a library you use. You have 200 images across 40 repos. How do you find and patch everything fast?IntermediateGuardDuty reports an EC2 instance talking to a known command-and-control IP. What do you do?AdvancedYou discover an S3 bucket with customer data has been public for three months. What now?IntermediateAn engineer left the company three weeks ago and you find their access key was used yesterday. How do you respond and fix the process?Beginner