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.

Lesson 21 of 26 · 9 min read · practice only with authorization

Diagram

How a token ends up in a log

Follow the path. One example at a time.

Step 1 of 4

Debug

A script turns on tracing.

Illustration: Debug
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.

  1. 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.
  2. 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.
  3. 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.

1 / 3

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.

  1. MapSecret scanning in git and in pipelinesSecrets belong in a manager, not in a repository.
  1. 01Reading a software bill of materials: CycloneDX and SPDX in practiceAn SBOM lists the components inside a build.

Practice

  1. LabTerminal mission: A deploy token in the CI workflow fileThe deploy workflow now reads its token from repository secrets, but an earlier version had it inline. Follow the history of one file to find when it was added and by whom.

Glossary

  1. CardSecrets printed in CI logsA job echoes a token into a log that many people, and often the internet, can read.