CI: scan for leaked secrets with gitleaks (full history) #134

Open
opened 2026-11-28 23:33:19 -05:00 by jared · 0 comments
Owner

This repo's CI has no secret scan. On 2026-11-28 a config backup holding production API keys and a database password turned up in another repo's history, 9 days after it was committed, and crawlers had already downloaded it. The keys were rotated and the history purged. A gitleaks step in CI would have failed the push that added it.

What to do

  1. Scan the full history once, locally, before adding the CI step:
    gitleaks git --redact --no-banner .
    • If it finds a real secret: rotate it first, then purge it from history. In gandalf this was git filter-repo --invert-paths --path <file>, a force-push of the branches and tags, and a server-side update of refs/pull/* followed by git gc.
    • A false positive goes in a .gitleaks.toml allowlist, with a comment saying why.
  2. Add a CI step that runs on every push and pull request and fails on any finding. Copy Pulse's version from .gitea/workflows/ci.yml (the scan job):
    • actions/checkout pinned to a full SHA, with fetch-depth: 0 so the whole history is scanned;
    • gitleaks v8.30.1 downloaded and checked with SHA-256 (551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb);
    • gitleaks git --no-banner --redact --exit-code 1 .
  3. Ignore config backups: if the repo has a config file holding secrets, add patterns like config.json.* and .env* (except .env.example) to .gitignore.

Repos that already do this: pulse, thor, matrix, cinny.

This repo's CI has no secret scan. On 2026-11-28 a config backup holding production API keys and a database password turned up in another repo's history, 9 days after it was committed, and crawlers had already downloaded it. The keys were rotated and the history purged. A gitleaks step in CI would have failed the push that added it. ## What to do 1. **Scan the full history once, locally, before adding the CI step:** `gitleaks git --redact --no-banner .` - If it finds a real secret: rotate it first, then purge it from history. In gandalf this was `git filter-repo --invert-paths --path <file>`, a force-push of the branches and tags, and a server-side update of `refs/pull/*` followed by `git gc`. - A false positive goes in a `.gitleaks.toml` allowlist, with a comment saying why. 2. **Add a CI step** that runs on every push and pull request and fails on any finding. Copy Pulse's version from `.gitea/workflows/ci.yml` (the `scan` job): - `actions/checkout` pinned to a full SHA, with `fetch-depth: 0` so the whole history is scanned; - gitleaks v8.30.1 downloaded and checked with SHA-256 (`551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb`); - `gitleaks git --no-banner --redact --exit-code 1 .` 3. **Ignore config backups:** if the repo has a config file holding secrets, add patterns like `config.json.*` and `.env*` (except `.env.example`) to `.gitignore`. Repos that already do this: pulse, thor, matrix, cinny.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: LotusGuild/tinker_tickets#134