Skip to content

ci: scan the commits of the PR with gitleaks - #6

Merged
tabedzki merged 3 commits into
masterfrom
tabedzki/ci/gitleaks-pr-scan
Oct 16, 2026
Merged

tabedzki merged 3 commits into
masterfrom
tabedzki/ci/gitleaks-pr-scan

Conversation

@tabedzki

@tabedzki tabedzki commented Oct 15, 2026 •

Copy link
Copy Markdown

🤖 AI text below 🤖

Problem

The gitleaks hook runs gitleaks git --pre-commit --staged, which scans the staged diff. In CI, prek run --all-files runs on a fresh checkout with nothing staged, so the hook passed without scanning anything. Secrets were only caught if someone had prek installed locally.

What changed

The hook's entry now points at .github/scripts/gitleaks-changes.sh (the script from U19-pipeline-python #154), which scans only what is being introduced:

Where What is scanned
On commit (pre-commit) the staged changes, as before; on a merge commit, only what the merge itself introduces
In CI every commit of the PR (or push), plus the lines each merge commit in that range introduced itself
Manual run (workflow_dispatch) gitleaks is skipped: there is no base to scan from

In the lint workflow:

  • the general prek step skips gitleaks (SKIP=gitleaks), since there it can only see staged changes;
  • a dedicated step "Scan the commits of the PR (or push) for secrets" runs it with GITLEAKS_BASE set to the PR base commit (or the commit before a push); a missing base (first push of a branch, force-pushed base) scans the last commit only;
  • the checkout fetches the full history (fetch-depth: 0).

Testing

With prek, GITLEAKS_BASE set to the base and a token committed in the second of three commits, uvx prek run gitleaks --all-files --verbose fails with one github-pat finding (3 commits scanned). A clean range passes. The script was also exercised for: unset base with a staged leak (fails), unset base with nothing staged (passes), all-zeros base, and empty base.

Assisted-by: ClaudeCode:claude-sonnet-5-5

The gitleaks hook ran `gitleaks git --pre-commit --staged`. In CI,
`prek run --all-files` runs on a fresh checkout with nothing staged, so
the hook passed without scanning anything.

The hook's entry is now .github/scripts/gitleaks-changes.sh. On commit it
scans the staged changes (a merge commit: only what it introduces itself).
In CI the general prek step skips gitleaks and a dedicated step runs it
with GITLEAKS_BASE set to the PR base (or the commit before a push), so
every commit of the PR is scanned, plus the lines merge commits introduced.
A run without a base (workflow_dispatch) scans the whole history.

Assisted-by: ClaudeCode:claude-sonnet-5-5
A manual run has no base to scan from. Drop workflow_dispatch from the
standalone gitleaks workflows and skip the gitleaks step on a manual run of
the lint workflow. Make the script fail on an empty GITLEAKS_BASE instead of
falling back to a full-history scan, so a missing base can never pass
silently.

Assisted-by: ClaudeCode:claude-sonnet-5-5
Keep both the gitleaks step and the AI attribution step in the lint workflow.

Assisted-by: ClaudeCode:claude-sonnet-5-5
@tabedzki
tabedzki merged commit 88aed65 into master Oct 16, 2026
4 checks passed
@tabedzki
tabedzki deleted the tabedzki/ci/gitleaks-pr-scan branch October 16, 2026 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant