chore: add Gitleaks secret detection to pre-commit#2613
Merged
lpichler merged 4 commits intoRedHatInsights:masterfrom Apr 20, 2026
Merged
chore: add Gitleaks secret detection to pre-commit#2613lpichler merged 4 commits intoRedHatInsights:masterfrom
lpichler merged 4 commits intoRedHatInsights:masterfrom
Conversation
Contributor
Reviewer's GuideAdds Gitleaks secret scanning to both local pre-commit hooks and GitHub Actions CI, including configuration, documentation, and minor pre-commit hook version bumps. Sequence diagram for CI Gitleaks scan on pull requestsequenceDiagram
actor Developer
participant GitHub
participant WorkflowDispatcher as GitHub_Actions_Workflow
participant Checkout as actions_checkout_v4
participant Gitleaks as gitleaks_gitleaks_action_v2
participant GitHistory as Git_history
Developer->>GitHub: Push branch and open pull request
GitHub->>WorkflowDispatcher: Trigger gitleaks workflow (on pull_request)
WorkflowDispatcher->>Checkout: Run with fetch-depth 0
Checkout->>GitHistory: Fetch full git history
WorkflowDispatcher->>Gitleaks: Run Gitleaks with GITHUB_TOKEN
Gitleaks->>GitHistory: Scan repository and history for secrets
Gitleaks-->>WorkflowDispatcher: Report pass or failures
WorkflowDispatcher-->>GitHub: Update PR checks status
GitHub-->>Developer: Display Gitleaks check result on PR
Flow diagram for local pre-commit Gitleaks executionflowchart TD
A[Developer stages changes] --> B[Developer runs git commit]
B --> C[pre-commit framework starts]
C --> D[Run formatting and lint hooks]
D --> E[Run Gitleaks hook]
E --> F{Secrets detected?}
F -- Yes --> G[Fail commit and show Gitleaks findings]
G --> H[Developer removes secrets and re-stages changes]
H --> B
F -- No --> I[All hooks passed]
I --> J[Commit succeeds and is recorded in local history]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
.pre-commit-config.yaml, theopenapi-spec-validatorrepo now appears indented under the newgitleaksrepo (note the- repoline), which will break the YAML structure—move it back to the top-levelreposlist so it remains a separate repo block. - The
gitleakspre-commit hook is currently added with default settings only; consider specifying the command/args (e.g.,args: ["protect", "--staged", "--no-git"]and any config path) to ensure it scans only staged changes as intended and behaves consistently with your CI configuration.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `.pre-commit-config.yaml`, the `openapi-spec-validator` repo now appears indented under the new `gitleaks` repo (note the `- repo` line), which will break the YAML structure—move it back to the top-level `repos` list so it remains a separate repo block.
- The `gitleaks` pre-commit hook is currently added with default settings only; consider specifying the command/args (e.g., `args: ["protect", "--staged", "--no-git"]` and any config path) to ensure it scans only staged changes as intended and behaves consistently with your CI configuration.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
02e5b17 to
263965e
Compare
44db4f0 to
1732ef3
Compare
Add Gitleaks to the pre-commit configuration to automatically scan staged changes for hardcoded secrets (API keys, passwords, tokens) before each commit. This prevents secrets from entering git history, which is critical because removing them after the fact requires rewriting history. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add documentation covering: - How to install and configure pre-commit with Gitleaks - Warning about what happens if pre-commit is not installed - How to verify Gitleaks is running (look for "Detect hardcoded secrets") - CI safety net via .github/workflows/pre-commit.yml - Troubleshooting common issues Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1732ef3 to
4c3870d
Compare
Contributor
Author
|
/retest |
astrozzc
approved these changes
Mar 19, 2026
Contributor
Author
|
/retest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link(s) to Jira
Description of Intent of Change(s)
What
Adds Gitleaks secret detection as a pre-commit hook, along with developer setup documentation.
Why
Hardcoded secrets (API keys, passwords, tokens) in git history are a significant security risk. Once committed, removing them requires rewriting git history. Gitleaks scans staged changes before each commit and blocks the commit if a secret is detected.
How
gitleakshook to.pre-commit-config.yaml(v8.30.1)docs/pre-commit-setup.mdwith:.github/workflows/pre-commit.yml) acts as a safety netLocal Testing
pip install pre-commitpre-commit installpre-commit run gitleaks --all-filesChecklist
Secure Coding Practices Checklist Link
Secure Coding Practices Checklist