-
Notifications
You must be signed in to change notification settings - Fork 28
chore: add trufflehog scan #1238
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
Draft
isaiah-grafana
wants to merge
23
commits into
main
Choose a base branch
from
pr/trufflehog-scan
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+104
−0
Draft
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
214c9d9
Test
isaiah-grafana 2929715
Testing
isaiah-grafana 3eb0c48
Testing
isaiah-grafana af08945
Testing
isaiah-grafana 7a37b3a
Testing
isaiah-grafana 32d4273
Testing
isaiah-grafana b45a2ff
Updated
isaiah-grafana ae40386
test
isaiah-grafana 9661385
Added
isaiah-grafana 7d2e829
Added this for testing
isaiah-grafana 10f65ba
Interesting
isaiah-grafana 564b9e9
Testing
isaiah-grafana d177777
Testing
isaiah-grafana 5c3586e
Made updates
isaiah-grafana 4c01a66
Testing this
isaiah-grafana 7a9d410
Testing this
isaiah-grafana deaf6f2
Made updates
isaiah-grafana feb1163
Testing
isaiah-grafana 331c613
Findings
isaiah-grafana dba73c1
Updated to pinned commit
isaiah-grafana 22663e8
Fixed zizmor findings
isaiah-grafana f7944fd
chore: fix Prettier formatting
isaiah-grafana 24cda0e
Fixes pre-commit failure
isaiah-grafana 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,104 @@ | ||
name: Reusable Trufflehog Secret Scan | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
fail-on-secrets: | ||
description: "Fail the workflow if secrets are found" | ||
required: false | ||
default: "true" | ||
type: string | ||
extra_args: | ||
description: "Extra arguments to pass to Trufflehog" | ||
required: false | ||
default: "" | ||
type: string | ||
|
||
jobs: | ||
trufflehog-scan: | ||
runs-on: ubuntu-x64-small | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
|
||
- name: Remove old Trufflehog (if present) | ||
run: | | ||
pip uninstall -y truffleHog || true | ||
pip uninstall -y trufflehog || true | ||
|
||
- name: Install Trufflehog (pinned to commit) | ||
run: | | ||
curl -sSfL https://raw.githubusercontent.com/trufflesecurity/trufflehog/0f58ae7c5036094a1e3e750d18772af92821b503/scripts/install.sh | sh -s -- -b /usr/local/bin | ||
trufflehog --version | ||
|
||
- name: Run Trufflehog | ||
env: | ||
EXTRA_ARGS: ${{ inputs.extra_args }} | ||
run: | | ||
trufflehog filesystem . \ | ||
--json \ | ||
--no-update \ | ||
--results=verified,unknown \ | ||
--fail \ | ||
--exclude-paths=.git,.github,node_modules,venv,env \ | ||
"$EXTRA_ARGS" \ | ||
> trufflehog-results.json || true | ||
|
||
- name: Debug Trufflehog output | ||
run: cat trufflehog-results.json || echo "No trufflehog-results.json found" | ||
|
||
- name: Comment on PR with all Trufflehog findings (full JSON, clean format) | ||
if: ${{ github.event.pull_request != null }} | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const fs = require('fs'); | ||
let findings = []; | ||
try { | ||
const lines = fs.readFileSync('trufflehog-results.json', 'utf8') | ||
.split('\n') | ||
.filter(Boolean); | ||
for (const line of lines) { | ||
let finding; | ||
try { | ||
finding = JSON.parse(line); | ||
} catch (e) { | ||
continue; | ||
} | ||
if (finding.Raw) { | ||
findings.push( | ||
[ | ||
'---', | ||
'**Trufflehog Finding:**', | ||
'', | ||
'```json', | ||
JSON.stringify(finding, null, 2), | ||
'```', | ||
'' | ||
].join('\n') | ||
); | ||
} | ||
} | ||
} catch (e) { | ||
findings = ['(Could not parse Trufflehog report)']; | ||
} | ||
const body = findings.length | ||
? `🚨 **Trufflehog found secrets in this PR!**\n\n${findings.join('\n')}` | ||
: "✅ Trufflehog ran and no secrets were found."; | ||
github.rest.issues.createComment({ | ||
issue_number: context.payload.pull_request.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body | ||
}); | ||
|
||
- name: Fail if any secrets found | ||
if: ${{ inputs.fail-on-secrets == 'true' && hashFiles('trufflehog-results.json') != '' }} | ||
run: | | ||
if grep -q '"Raw":' trufflehog-results.json; then | ||
echo "Secrets found! Failing the workflow." | ||
exit 1 | ||
fi |
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.