-
Notifications
You must be signed in to change notification settings - Fork 26
Add reusable Trufflehog scan workflow #1194
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
24
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.
Draft
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
44c757e
Add reusable Trufflehog scan workflow
isaiah-grafana 95b6c8b
Made changes to format
isaiah-grafana c1337db
modified workflow
isaiah-grafana c6c7c02
modified secrets workflow
isaiah-grafana 04e52ae
modified the workflow
isaiah-grafana de0f70c
Updated reusable workflow
isaiah-grafana 225f4bd
Updated reusable workflows
isaiah-grafana 08097c0
Updated reusable flow
isaiah-grafana efd3a75
modified workflow
isaiah-grafana 538de2e
reverted workflow
isaiah-grafana e6efbed
Modified run
isaiah-grafana 368dcb3
Made updates
isaiah-grafana 62948f0
Updated runner
isaiah-grafana 947433f
Updated workflow
isaiah-grafana cc36904
Modified workflow
isaiah-grafana 5413496
Had to revert
isaiah-grafana b25ba49
test out changes
isaiah-grafana eb08896
Test
isaiah-grafana 6af82c5
Testing this
isaiah-grafana 5c26bf1
Added updates
isaiah-grafana 0c16ffd
Fixed error
isaiah-grafana 886178f
Updates
isaiah-grafana f206bc3
Added changes to workflow
isaiah-grafana 5224a00
Modified workflow
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,67 @@ | ||
name: Reusable Trufflehog Scan | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
fail-on-secrets: | ||
description: "Fail the workflow if secrets are found" | ||
required: false | ||
default: "true" | ||
type: string | ||
|
||
jobs: | ||
trufflehog-scan: | ||
runs-on: ubuntu-x64-small | ||
permissions: | ||
contents: read | ||
pull-requests: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
with: | ||
fetch-depth: 0 | ||
|
||
|
||
- name: Run Trufflehog and print findings | ||
id: trufflehog | ||
run: | | ||
docker run --rm -v ${{ github.workspace }}:/pwd ghcr.io/trufflesecurity/trufflehog:latest \ | ||
filesystem --directory=/pwd --json | tee trufflehog-results.tmp | ||
if [ -s trufflehog-results.tmp ]; then | ||
echo "### Trufflehog Findings" >> $GITHUB_STEP_SUMMARY | ||
jq -r '.[] | "- \(.SourceMetadata.Data.path):\(.SourceMetadata.Data.line // "?") \(.Raw | @json)"' trufflehog-results.tmp >> $GITHUB_STEP_SUMMARY | ||
echo "found_secrets=true" >> $GITHUB_OUTPUT | ||
else | ||
echo "No secrets found." >> $GITHUB_STEP_SUMMARY | ||
echo "found_secrets=false" >> $GITHUB_OUTPUT | ||
fi | ||
|
||
- name: Comment on PR with findings | ||
if: ${{ steps.trufflehog.outputs.found_secrets == 'true' && github.event_name == 'pull_request' }} | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const fs = require('fs'); | ||
let findings = []; | ||
try { | ||
const data = JSON.parse(fs.readFileSync('trufflehog-results.tmp', 'utf8')); | ||
for (const finding of data) { | ||
if (finding.SourceMetadata && finding.SourceMetadata.Data) { | ||
findings.push(`- \`${finding.SourceMetadata.Data.path}\` line ${finding.SourceMetadata.Data.line || '?'}: \`${finding.Raw.slice(0, 80)}...\``); | ||
} | ||
} | ||
} catch (e) { | ||
findings = ['(Could not parse Trufflehog report)']; | ||
} | ||
const body = findings.length | ||
? `🚨 **Trufflehog found potential secrets in this PR!**\n\n${findings.join('\n')}` | ||
: "Trufflehog ran but no findings were parsed."; | ||
github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body | ||
}); | ||
|
||
- name: Fail if secrets found | ||
if: ${{ inputs.fail-on-secrets == 'true' && steps.trufflehog.outputs.found_secrets == 'true' }} | ||
run: exit 1 |
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.