Secrets in code and images
A secret is anything that grants access: passwords, API keys, cloud credentials, tokens, private keys, connection strings. When one ends up in a repository or inside a container image, anyone who can read the code or pull the image can use it.
Why secrets are different
Section titled “Why secrets are different”A vulnerability needs an attacker to find a way to exploit it. A leaked secret is the way in. That is why it has no CVE, no CVSS score and no fix version, and still deserves to be at the top of the list.
Common ways they leak:
- committed by mistake in a configuration file or a test;
- copied into an image by a
COPY . .that takes more than it should; - left in the Git history, even after being deleted from the current code;
- printed in pipeline logs.
What to do when one is found
Section titled “What to do when one is found”- Revoke and rotate it first. Deleting it from the code is not enough: it is still in the history, in old images and maybe in someone’s clone.
- Check whether it was used while it was exposed.
- Remove it from the code and the image, and move it to a secret manager or the pipeline’s protected variables.
- Prevent the next one:
.dockerignore,.gitignoreand a secret scan in every pipeline.
In Leavory
Section titled “In Leavory”Secrets found in your pipelines’ scans and in registry images get their own count on the Dashboard and in Findings, next to vulnerabilities but never mixed with them. The secret’s value is never shown, only the rule that caught it and the file where it is.