An API key is baked into the image as an environment variable. What do you do first?
The scenario
A Dockerfile sets ENV API_KEY. The image is in the registry. The key can read production data. Someone deletes the line and opens a pull request.
Model answer
What I'd say first:
I would rotate the key before I merge the pull request. The line is how it leaked. The image and the registry already have it.
How I'd work it:
- 1I revoke the key and issue a new one to the runtime secret store, not to the image.
- 2I find tags that still contain the old layer.
- 3I rebuild without the ENV and I delete the old tags. The pull request is not the rotate.
- 4I tell the room the Dockerfile is the easy part.
How I'd explain it:
ENV values live in image history. Deleting a line does not recall a pulled image. A wrong answer is a private registry and the same key.
How I'd prevent it:
Refuse a build that contains a key pattern. Read secrets at runtime. Scan images. Rotate on exposure by default.
The follow-up they'll ask
“Merge the pull request and rotate next sprint?”
No. The key works until you revoke it. I rotate now. The pull request only stops the next build from repeating the leak. That shortcut is how this comes back on the next shift.
Common mistakes
- Waiting on a pull request
- Leaving old tags
- A secret in ENV