-
Notifications
You must be signed in to change notification settings - Fork 119
feat(workflows): add gitleaks binary-based secret scanning as PR gate #734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8d9f2ea
feat(workflows): add gitleaks binary-based secret scanning as PR gate
WilliamBerryiii 121fff9
fix(workflows): remove vestigial scan-mode input from gitleaks workflow
WilliamBerryiii 5d97c3b
fix(build): add .gitleaksignore for false positive test fixtures
WilliamBerryiii 49bfa0d
Merge remote-tracking branch 'origin/main' into feat/260-gitleaks-pr-…
f89a8ee
fix(workflows): scope gitleaks PR scan to current branch commits only
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| name: Gitleaks Secret Scan | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| soft-fail: | ||
| description: 'Whether to continue on secret detection' | ||
| required: false | ||
| type: boolean | ||
| default: false | ||
| upload-sarif: | ||
| description: 'Whether to upload SARIF results to Security tab' | ||
| required: false | ||
| type: boolean | ||
| default: false | ||
| upload-artifact: | ||
| description: 'Whether to upload results as artifact' | ||
| required: false | ||
| type: boolean | ||
| default: true | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| scan: | ||
| name: Gitleaks Secret Scan | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| security-events: write | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4.2.2 | ||
| with: | ||
| persist-credentials: false | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Download and verify gitleaks | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| GITLEAKS_VERSION="8.30.0" | ||
| GITLEAKS_SHA256="79a3ab579b53f71efd634f3aaf7e04a0fa0cf206b7ed434638d1547a2470a66e" | ||
| GITLEAKS_URL="https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz" | ||
| GITLEAKS_TARBALL="gitleaks.tar.gz" | ||
|
|
||
| echo "Downloading gitleaks v${GITLEAKS_VERSION}..." | ||
| curl -fsSL -o "${GITLEAKS_TARBALL}" "${GITLEAKS_URL}" | ||
|
|
||
| echo "Verifying SHA256 checksum..." | ||
| echo "${GITLEAKS_SHA256} ${GITLEAKS_TARBALL}" | sha256sum -c - | ||
|
|
||
| echo "Extracting gitleaks binary..." | ||
| tar -xzf "${GITLEAKS_TARBALL}" gitleaks | ||
| chmod +x gitleaks | ||
|
|
||
| echo "Gitleaks version:" | ||
| ./gitleaks version | ||
|
|
||
| - name: Run gitleaks scan | ||
| id: gitleaks | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| mkdir -p logs | ||
|
|
||
| SCAN_ARGS=( | ||
| "git" | ||
| "--report-format" "sarif" | ||
| "--report-path" "logs/gitleaks-results.sarif" | ||
| "--redact" | ||
| "--log-level" "info" | ||
| ) | ||
|
|
||
| # Respect .gitleaksignore for pre-existing secrets | ||
| if [ -f ".gitleaksignore" ]; then | ||
| echo "Found .gitleaksignore — known secrets will be suppressed." | ||
| fi | ||
|
|
||
| echo "Running gitleaks scan..." | ||
| EXIT_CODE=0 | ||
| ./gitleaks "${SCAN_ARGS[@]}" || EXIT_CODE=$? | ||
|
|
||
| if [ "$EXIT_CODE" -eq 0 ]; then | ||
| echo "No secrets detected." | ||
| echo "leaks-found=false" >> "$GITHUB_OUTPUT" | ||
| elif [ "$EXIT_CODE" -eq 1 ]; then | ||
| echo "::warning::Gitleaks detected secrets in the repository." | ||
| echo "leaks-found=true" >> "$GITHUB_OUTPUT" | ||
| if [ "${{ inputs.soft-fail }}" != "true" ]; then | ||
| echo "::error::Secret scanning failed. Review detected secrets in logs/gitleaks-results.sarif" | ||
| exit 1 | ||
| fi | ||
| else | ||
| echo "::error::Gitleaks encountered an unexpected error (exit code: $EXIT_CODE)" | ||
| exit "$EXIT_CODE" | ||
| fi | ||
|
|
||
| - name: Upload SARIF to Security tab | ||
| if: inputs.upload-sarif && always() | ||
| uses: github/codeql-action/upload-sarif@ce729e4d353d580e6cacd6a8cf2921b72e5e310a # v3.27.0 | ||
| with: | ||
| sarif_file: logs/gitleaks-results.sarif | ||
| category: gitleaks | ||
| continue-on-error: true | ||
|
|
||
| - name: Upload scan results | ||
| if: inputs.upload-artifact && always() | ||
| uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v4.4.3 | ||
| with: | ||
| name: gitleaks-results | ||
| path: logs/gitleaks-results.sarif | ||
| retention-days: 90 | ||
|
|
||
| - name: Add job summary | ||
| if: always() | ||
| shell: bash | ||
| run: | | ||
| LEAKS_FOUND="${{ steps.gitleaks.outputs.leaks-found }}" | ||
| if [ "$LEAKS_FOUND" = "true" ]; then | ||
| STATUS="⚠️ Secrets Detected" | ||
| else | ||
| STATUS="✅ No Secrets Found" | ||
| fi | ||
|
|
||
| cat >> "$GITHUB_STEP_SUMMARY" <<EOF | ||
| ## Gitleaks Secret Scan Results | ||
|
|
||
| | Metric | Value | | ||
| |--------|-------| | ||
| | Status | $STATUS | | ||
|
|
||
| EOF |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # False positives: fake GitHub PAT 'ghp_test123456789' used as test fixture data | ||
| # in Pester security test files for SHA pinning and staleness validation. | ||
| # Rule: generic-api-key | ||
|
|
||
| # Test-SHAStaleness.Tests.ps1 | ||
| 1c9634d8334ebe8e88513f9a531b49d03590c307:scripts/tests/security/Test-SHAStaleness.Tests.ps1:generic-api-key:33 | ||
| 1c9634d8334ebe8e88513f9a531b49d03590c307:scripts/tests/security/Test-SHAStaleness.Tests.ps1:generic-api-key:38 | ||
| 1c9634d8334ebe8e88513f9a531b49d03590c307:scripts/tests/security/Test-SHAStaleness.Tests.ps1:generic-api-key:55 | ||
| 1c9634d8334ebe8e88513f9a531b49d03590c307:scripts/tests/security/Test-SHAStaleness.Tests.ps1:generic-api-key:105 | ||
|
|
||
| # Update-ActionSHAPinning.Tests.ps1 | ||
| 1c9634d8334ebe8e88513f9a531b49d03590c307:scripts/tests/security/Update-ActionSHAPinning.Tests.ps1:generic-api-key:60 | ||
| 1c9634d8334ebe8e88513f9a531b49d03590c307:scripts/tests/security/Update-ActionSHAPinning.Tests.ps1:generic-api-key:92 | ||
| 1c9634d8334ebe8e88513f9a531b49d03590c307:scripts/tests/security/Update-ActionSHAPinning.Tests.ps1:generic-api-key:143 | ||
| 3a11b26086c43b9551e6a7b666ffb6aa5dd8a8d7:scripts/tests/security/Update-ActionSHAPinning.Tests.ps1:generic-api-key:93 | ||
| 3a11b26086c43b9551e6a7b666ffb6aa5dd8a8d7:scripts/tests/security/Update-ActionSHAPinning.Tests.ps1:generic-api-key:127 | ||
| 3a11b26086c43b9551e6a7b666ffb6aa5dd8a8d7:scripts/tests/security/Update-ActionSHAPinning.Tests.ps1:generic-api-key:193 | ||
| 4ef6d20475e42b753c29846aa28489843e70a8ed:scripts/tests/security/Update-ActionSHAPinning.Tests.ps1:generic-api-key:256 | ||
| 4ef6d20475e42b753c29846aa28489843e70a8ed:scripts/tests/security/Update-ActionSHAPinning.Tests.ps1:generic-api-key:488 | ||
| a02335e7c98e5f2e22b1921442e99f01c6781a19:scripts/tests/security/Update-ActionSHAPinning.Tests.ps1:generic-api-key:280 | ||
| a02335e7c98e5f2e22b1921442e99f01c6781a19:scripts/tests/security/Update-ActionSHAPinning.Tests.ps1:generic-api-key:511 | ||
| f7c9b9a6f776e6403f393adf90a67127f3fc3405:scripts/tests/security/Update-ActionSHAPinning.Tests.ps1:generic-api-key:791 | ||
| f7c9b9a6f776e6403f393adf90a67127f3fc3405:scripts/tests/security/Update-ActionSHAPinning.Tests.ps1:generic-api-key:869 | ||
| 6b84a8e49193d266411df9e4b8e8b1be2369eed2:scripts/tests/security/Update-ActionSHAPinning.Tests.ps1:generic-api-key:792 | ||
| 6b84a8e49193d266411df9e4b8e8b1be2369eed2:scripts/tests/security/Update-ActionSHAPinning.Tests.ps1:generic-api-key:874 |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.