Secret scanning in git and in pipelines
Secrets belong in a manager, not in a repository. Scanners exist to catch the moment someone forgets.
Diagram
From a push to a revoked credential
Step 1 of 4
Where
Keys land in git, in CI logs, and in image layers. History keeps them after the file is deleted.
# Where # Keys land in git, in CI logs, and in image layers. # History keeps them after the file is deleted.
The example on the open step is one illustration, or the fix you can paste into an application you own.
Where secrets leak
API keys, cloud credentials, and private certificates land in source code, in committed environment files, in CI logs, and in container layers. Git history keeps them after the file is deleted. A scanner on the push, and another in the pipeline, are how you hear about it in minutes instead of from a stranger.
Tools such as gitleaks, trufflehog, and the secret scanners built into GitHub and GitLab look for known token shapes and for high-entropy strings. They miss secrets that look like ordinary words, and they sometimes flag test data. Both errors are manageable. A missed production key is not.
What you do when one fires
Revoke the credential first. Rotation is the fix. Rewriting history is housekeeping and does not help if anyone cloned the repository, including a fork or a CI cache. Then add a test so that shape of token cannot be pushed again, and move the real value into the secret store the pipeline already has.
A finding that includes the secret in the ticket has doubled the leak. Refer to the file, the commit, and the scanner rule. Let the person who can open the store fetch the value through the normal path, then revoke it.
A small exercise
In a throwaway repository, commit a fake token in the shape the scanner documents as a test fixture, and confirm the hook rejects the push. Remove it. That is the whole drill. Do not commit a real key “just to see.”
The same idea applies to container images. A secret baked into a layer is in every registry that holds the image. Build arguments and a runtime secret store exist so the image can start without shipping the key inside it.
Check yourself
Recognition and the fix. Nothing here is a procedure.
A scanner flags a production key in a commit. What is the first change?
Go deeper
Specific techniques, exercises, and glossary cards for this topic.
- 01Secrets printed in CI logs: masking, scanning, and rotatingBuild logs are widely readable and kept for months, so a printed token is a leaked token. Includes the diagram and a defensive fix.
- 02Reading a software bill of materials: CycloneDX and SPDX in practiceAn SBOM lists the components inside a build. Includes the diagram and a defensive fix.
Exercises
- 01Control benchA failure is on the table. Choose the control that changes the outcome.
- 02Terminal mission: A pushed key, then a new admin userAn access key was pushed to a public repository for one afternoon. Find the commit and the key, then use CloudTrail to see who used it, what they created, and how they kept access.
- 03Terminal mission: The token on a branch nobody mergedA scan of main came back clean, but the repository has other branches. Search every branch for the API token that leaked, find the branch, and the file it sits in.
- 04Terminal mission: Three passwords in one file’s historydatabase.yml has had three different passwords committed over time. Follow one file’s history, list each password, and find the one the team says is still in use.
- 05Terminal mission: Deleted from the code, still in the historyA commit titled “remove secrets” deleted an AWS key from config. The key is still in Git history. Find the commit that added it, the key ID, and who committed it.