-
Notifications
You must be signed in to change notification settings - Fork 1
PDP-684 Add TruffleHog secret scanning workflow for PR validation #16
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
Open
GAdityaVarma
wants to merge
65
commits into
main
Choose a base branch
from
agottumu_dev
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.
Open
Changes from 7 commits
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
43162b1
Add TruffleHog secret scanning workflow and docs
GAdityaVarma 200cee2
Update README.md
GAdityaVarma bf7b85b
Update trufflehog-scan.yml
GAdityaVarma 527f3f2
Update trufflehog-scan.yml
GAdityaVarma 599658f
Update trufflehog-scan.yml
GAdityaVarma f42179b
Enhance TruffleHog workflow with PR comments and commit status
GAdityaVarma e496bac
Update trufflehog_readme.md
GAdityaVarma d279b66
Update trufflehog-scan.yml
GAdityaVarma 1aae01b
Update trufflehog-scan.yml
GAdityaVarma 77909eb
Update trufflehog-scan.yml
GAdityaVarma c120b09
Update trufflehog-scan.yml
GAdityaVarma 174b7d0
Update TruffleHog workflow to handle resolved secrets
GAdityaVarma 7ded023
Update trufflehog-scan.yml
GAdityaVarma 40260d7
Update trufflehog-scan.yml
GAdityaVarma 5907188
Update trufflehog-scan.yml
GAdityaVarma c38506c
Update trufflehog-scan.yml
GAdityaVarma 6f0f819
Remove workflow_dispatch trigger for ruleset compatibility
GAdityaVarma 2a55bbb
Update trufflehog-scan.yml
GAdityaVarma e1358eb
Update trufflehog-scan.yml
GAdityaVarma f30fed0
Update trufflehog-scan.yml
GAdityaVarma 3f65074
Improve TruffleHog scan workflow and update docs
GAdityaVarma 467594b
Update trufflehog-scan.yml
GAdityaVarma 693b2e7
Update trufflehog-scan.yml
GAdityaVarma 8770dab
Update trufflehog-scan.yml
GAdityaVarma 1a61036
Update trufflehog-scan.yml
GAdityaVarma aa00512
Update trufflehog-scan.yml
GAdityaVarma d57e46b
Update trufflehog-scan.yml
GAdityaVarma 0bff560
Update trufflehog-scan.yml
GAdityaVarma cbfc2c8
Update trufflehog_readme.md
GAdityaVarma f610f23
Update trufflehog_readme.md
GAdityaVarma 47a4ca6
PDP-684: updated the workflow for updating the pullrequest comment
brijeshp56 7ad1df9
PDP-684: Updated to update the comment
brijeshp56 0666566
PDP-684: Update the existing pull request comment if secrets are reso…
brijeshp56 06a1ac7
PDP-684: Updated workflow to make sure to scan renamed files
brijeshp56 518c5d2
Merge branch 'agottumu_dev' into brijesh-dev
brijeshp56 41f9c2d
Merge pull request #19 from marklogic/brijesh-dev
brijeshp56 e7e2b95
PDP-684 : Update trufflehog-scan.yml
brijeshp56 38832a6
Merge pull request #20 from marklogic/brijesh-dev
brijeshp56 09da209
PDP-684 : Update trufflehog-scan.yml
brijeshp56 df754f4
Merge pull request #21 from marklogic/brijesh-dev
brijeshp56 08e940a
PDP-684 : Update trufflehog-scan.yml
brijeshp56 7ba41eb
Merge pull request #22 from marklogic/brijesh-dev
brijeshp56 d385450
PDP-684 : Update trufflehog-scan.yml
brijeshp56 b9540ef
Merge pull request #23 from marklogic/brijesh-dev
brijeshp56 34848a0
PDP-684 : Update trufflehog-scan.yml for detecting the renamed files
brijeshp56 d64d46d
Merge branch 'agottumu_dev' into brijesh-dev-backup
brijeshp56 6cb4ee6
Merge pull request #25 from marklogic/brijesh-dev-backup
brijeshp56 a0015e2
PDP-684 : Update trufflehog-scan.yml
brijeshp56 20049b3
Merge pull request #26 from marklogic/brijesh-dev-backup
brijeshp56 f4e15b5
PDP-684 : Update trufflehog-scan.yml
brijeshp56 709c401
Merge pull request #27 from marklogic/brijesh-dev-backup
brijeshp56 9494c79
PDP-684 : Update trufflehog-scan.yml
brijeshp56 7cc1131
Merge pull request #28 from marklogic/brijesh-dev-backup
brijeshp56 0a33191
PDP-684: updated workflow to checkout only head commit
brijeshp56 e6fa7a0
Merge branch 'agottumu_dev' into brijesh-dev
brijeshp56 74e685b
Merge pull request #29 from marklogic/brijesh-dev
brijeshp56 d653ce8
PDP-684: updated workflow to checkout only head commit1
brijeshp56 2029065
Merge branch 'brijesh-dev' of https://github.com/marklogic/pr-workflo…
brijeshp56 46305c1
Merge pull request #30 from marklogic/brijesh-dev
brijeshp56 a7b8ecd
PDP-684 : Reverting my changes for trufflehog
brijeshp56 4f60581
Merge pull request #31 from marklogic/brijesh-dev
brijeshp56 f21206b
Update trufflehog-scan.yml
GAdityaVarma 1be8f21
Improve secret scan comment update logic
GAdityaVarma 99b8e96
Update trufflehog-scan.yml
GAdityaVarma c395591
Update trufflehog-scan.yml
GAdityaVarma 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
Some comments aren't visible on the classic Files Changed page.
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,175 @@ | ||
| name: TruffleHog Secret Scan | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened] | ||
| pull_request_target: | ||
| types: [opened, synchronize, reopened] | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
| statuses: write | ||
|
|
||
| # Default exclusion patterns (regex format) | ||
| # Supports: exact filenames, wildcards, regex patterns | ||
| # Examples: | ||
| # Exact file: ^config/settings\.json$ | ||
| # Directory: ^node_modules/ | ||
| # Extension: \.lock$ | ||
| # Wildcard: .*\.min\.js$ | ||
| # Regex: ^src/test/.*_test\.py$ | ||
|
|
||
| env: | ||
| DEFAULT_EXCLUDES: | | ||
| ^node_modules/ | ||
| ^vendor/ | ||
| ^\.git/ | ||
| \.lock$ | ||
| ^package-lock\.json$ | ||
| ^yarn\.lock$ | ||
| ^pnpm-lock\.yaml$ | ||
| \.min\.js$ | ||
| \.min\.css$ | ||
|
|
||
| jobs: | ||
| trufflehog-scan: | ||
| name: Scan PR for Secrets | ||
| runs-on: ubuntu-latest | ||
| # Run pull_request_target only for fork PRs, pull_request only for same-repo PRs | ||
| # This prevents duplicate runs | ||
| if: | | ||
| (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository) || | ||
| (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) || | ||
| github.event_name == 'workflow_dispatch' | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Fetch PR head commits | ||
| if: github.event_name != 'workflow_dispatch' | ||
| run: | | ||
| # Fetch PR commits using GitHub's merge ref (works for all PRs including forks) | ||
| git fetch origin +refs/pull/${{ github.event.pull_request.number }}/head:refs/remotes/origin/pr-head | ||
| echo "Fetched PR #${{ github.event.pull_request.number }} head commit: ${{ github.event.pull_request.head.sha }}" | ||
|
|
||
| - name: Setup exclude config | ||
| id: config | ||
| run: | | ||
| if [ -n "${{ vars.TRUFFLEHOG_EXCLUDES }}" ]; then | ||
| echo "Using repo/org-level TRUFFLEHOG_EXCLUDES variable" | ||
| # Support both comma-separated and newline-separated patterns | ||
| echo "${{ vars.TRUFFLEHOG_EXCLUDES }}" | tr ',' '\n' | sed '/^$/d' > .trufflehog-ignore | ||
| else | ||
| echo "Using default exclusions from central workflow" | ||
| cat << 'EOF' > .trufflehog-ignore | ||
| ${{ env.DEFAULT_EXCLUDES }} | ||
| EOF | ||
| fi | ||
|
|
||
| echo "Exclusion patterns:" | ||
| cat .trufflehog-ignore | ||
| echo "exclude_args=--exclude-paths=.trufflehog-ignore" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: TruffleHog Scan | ||
| id: trufflehog | ||
| uses: trufflesecurity/trufflehog@main | ||
GAdityaVarma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| continue-on-error: true | ||
| with: | ||
| base: ${{ github.event.pull_request.base.sha }} | ||
| head: ${{ github.event.pull_request.head.sha }} | ||
| extra_args: --json ${{ steps.config.outputs.exclude_args }} | ||
|
|
||
| - name: Process scan results | ||
| id: process | ||
| if: github.event_name != 'workflow_dispatch' | ||
| run: | | ||
| # Check if TruffleHog found any secrets | ||
| if [ "${{ steps.trufflehog.outcome }}" == "failure" ]; then | ||
| echo "has_secrets=true" >> $GITHUB_OUTPUT | ||
| echo "status=failure" >> $GITHUB_OUTPUT | ||
| echo "description=Secret scanning found exposed credentials" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "has_secrets=false" >> $GITHUB_OUTPUT | ||
| echo "status=success" >> $GITHUB_OUTPUT | ||
| echo "description=No secrets detected in PR changes" >> $GITHUB_OUTPUT | ||
| fi | ||
|
|
||
| - name: Post PR comment on findings | ||
GAdityaVarma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if: steps.process.outputs.has_secrets == 'true' && github.event_name != 'workflow_dispatch' | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const commentMarker = '<!-- TRUFFLEHOG-SCAN-COMMENT -->'; | ||
GAdityaVarma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const body = `${commentMarker} | ||
| ## :rotating_light: Secret Scanning Alert | ||
|
|
||
| **TruffleHog detected potential secrets in this pull request.** | ||
|
|
||
| ### What to do: | ||
| 1. **Review the workflow logs** for detailed findings (file, line number, secret type) | ||
| 2. **Remove the exposed secret** from your code | ||
| 3. **Rotate the credential immediately** - assume it's compromised | ||
| 4. **Push the fix** to this branch | ||
|
|
||
| ### Finding Details | ||
| Check the [workflow run logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for: | ||
GAdityaVarma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - File paths containing secrets | ||
| - Line numbers | ||
| - Secret types (API key, password, token, etc.) | ||
| - Verification status (verified = confirmed active) | ||
|
|
||
| --- | ||
| *This scan only checks files modified in this PR. Secrets are classified as **verified** (confirmed active) or **unverified** (potential match).* | ||
| `; | ||
|
|
||
| // Find existing comment | ||
| const { data: comments } = await github.rest.issues.listComments({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.payload.pull_request.number, | ||
| per_page: 100 | ||
| }); | ||
|
|
||
| const existing = comments.find(c => c.body && c.body.includes(commentMarker)); | ||
|
|
||
| if (existing) { | ||
| await github.rest.issues.updateComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| comment_id: existing.id, | ||
| body: body | ||
| }); | ||
| } else { | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.payload.pull_request.number, | ||
| body: body | ||
| }); | ||
| } | ||
|
|
||
| - name: Set commit status | ||
| if: github.event_name != 'workflow_dispatch' | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| await github.rest.repos.createCommitStatus({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| sha: '${{ github.event.pull_request.head.sha }}', | ||
| state: '${{ steps.process.outputs.status }}', | ||
| target_url: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}', | ||
| description: '${{ steps.process.outputs.description }}', | ||
| context: 'TruffleHog Secret Scan' | ||
| }); | ||
|
|
||
| - name: Fail workflow if secrets found | ||
| if: steps.process.outputs.has_secrets == 'true' | ||
| run: | | ||
| echo "::error::Secrets detected in PR. Review the logs and PR comment for details." | ||
| 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.