Secrets printed in CI logs: masking, scanning, and rotating
Build logs are widely readable and kept for months, so a printed token is a leaked token. Common ways secrets reach logs, how masking fails, how to scan logs with gitleaks or trufflehog, and why rotation is the real fix.
Diagram
How a token ends up in a log
Step 1 of 4
Debug
A script turns on tracing.
set -x curl -H "Authorization: Bearer $DEPLOY_TOKEN" https://deploy.example.test/api
The example on the open step is one illustration, or the fix you can paste into an application you own.
What this page is made of
3 pieces. Each one says what fails, who is affected, what you would notice, and what you change.
Tracing
- What fails
- set -x and verbose flags echo every command with expanded variables.
- Who is affected
- Every secret used in traced lines.
- What you would notice
- Logs with + lines containing Authorization or password.
- What you change
- Avoid tracing around secrets, or use set +x blocks.
Derived values
- What fails
- Masking misses secrets that are encoded, concatenated, or split.
- Who is affected
- The same secrets.
- What you would notice
- Base64 strings or URLs with embedded credentials in logs.
- What you change
- Mask derived values too, and prefer short-lived OIDC tokens.
Rotation
- What fails
- Deleting a log does not undo exposure.
- Who is affected
- Systems the secret opens.
- What you would notice
- Exposed secrets still valid days later.
- What you change
- Rotate first, then clean up.
Scanning logs you can export
Download logs for a repository you own and run a secret scanner over them. The gitleaks and trufflehog lessons in the tool library show more options, including verification of live credentials.
$ gh run view 9812 --log > run-9812.log $ gitleaks detect --no-git --source run-9812.log --redact -v Finding: Authorization: Bearer REDACTED RuleID: generic-api-key File: run-9812.log Line: 412
Check yourself
Recognition and the fix. Nothing here is a procedure.
A token printed in a CI log yesterday. What comes first?
Sibling techniques
Pages at the same depth, plus a lab and a glossary card for this one.