Skip to content

Commit 131f5a6

Browse files
committed
secret scanning workflow
0 parents  commit 131f5a6

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

.github/workflows/secret-scan.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Secret Scan
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
secret-scan:
7+
name: Secret Scan
8+
runs-on: ubuntu-latest
9+
permissions:
10+
contents: "read"
11+
12+
outputs:
13+
latest_release: ${{ steps.trufflehog_release.outputs.latest_release }}
14+
latest_tag_name: ${{ steps.trufflehog_release.outputs.latest_tag_name }}
15+
16+
steps:
17+
- name: Checkout Code
18+
uses: actions/checkout@v4
19+
20+
- name: Install Cosign
21+
uses: sigstore/[email protected]
22+
23+
- name: Pin Trufflehog to a know good release
24+
id: trufflehog_release
25+
shell: bash
26+
# run: |
27+
# LATEST_TAG_NAME=$(curl -s https://api.github.com/repos/trufflesecurity/trufflehog/releases/latest | jq -r .name)
28+
# LATEST_RELEASE=$(echo ${LATEST_TAG_NAME:1})
29+
# echo "latest_tag_name=$LATEST_TAG_NAME" >> "$GITHUB_OUTPUT"
30+
# echo "latest_release=$LATEST_RELEASE" >> "$GITHUB_OUTPUT"
31+
run: |
32+
echo "latest_tag_name=v3.80.3" >> "$GITHUB_OUTPUT"
33+
echo "latest_release=3.80.3" >> "$GITHUB_OUTPUT"
34+
35+
- name: Download and verify TruffleHog release
36+
run: |
37+
curl -sLO https://github.com/trufflesecurity/trufflehog/releases/download/${{ steps.trufflehog_release.outputs.latest_tag_name }}/trufflehog_${{ steps.trufflehog_release.outputs.latest_release }}_checksums.txt
38+
curl -sLO https://github.com/trufflesecurity/trufflehog/releases/download/${{ steps.trufflehog_release.outputs.latest_tag_name }}/trufflehog_${{ steps.trufflehog_release.outputs.latest_release }}_checksums.txt.pem
39+
curl -sLO https://github.com/trufflesecurity/trufflehog/releases/download/${{ steps.trufflehog_release.outputs.latest_tag_name }}/trufflehog_${{ steps.trufflehog_release.outputs.latest_release }}_checksums.txt.sig
40+
curl -sLO https://github.com/trufflesecurity/trufflehog/releases/download/${{ steps.trufflehog_release.outputs.latest_tag_name }}/trufflehog_${{ steps.trufflehog_release.outputs.latest_release }}_linux_amd64.tar.gz
41+
42+
cosign verify-blob trufflehog_${{ steps.trufflehog_release.outputs.latest_release }}_checksums.txt \
43+
--certificate trufflehog_${{ steps.trufflehog_release.outputs.latest_release }}_checksums.txt.pem \
44+
--signature trufflehog_${{ steps.trufflehog_release.outputs.latest_release }}_checksums.txt.sig \
45+
--certificate-identity-regexp 'https://github\.com/trufflesecurity/trufflehog/\.github/workflows/.+' \
46+
--certificate-oidc-issuer "https://token.actions.githubusercontent.com"
47+
48+
sha256sum --ignore-missing -c trufflehog_${{ steps.trufflehog_release.outputs.latest_release }}_checksums.txt
49+
50+
51+
- name: Extract TruffleHog
52+
run: |
53+
tar xzf trufflehog_${{ steps.trufflehog_release.outputs.latest_release }}_linux_amd64.tar.gz -C /usr/local/bin
54+
chmod +x /usr/local/bin/trufflehog
55+
56+
- name: Run TruffleHog scan
57+
continue-on-error: true
58+
id: scan
59+
run: |
60+
if [ -e .secret_scan_ignore ]; then
61+
trufflehog git file://. --only-verified --github-actions --fail --exclude-paths=.secret_scan_ignore --exclude-detectors="datadogtoken"
62+
else
63+
trufflehog git file://. --only-verified --github-actions --fail --exclude-detectors="datadogtoken"
64+
fi
65+
- name: Send Alert to Panther
66+
id: alert
67+
if: steps.scan.outcome != 'success'
68+
run: |
69+
curl "${{vars.SECRET_SCAN_PANTHER_WEBHOOK_URL}}" \
70+
--header "Authorization: Bearer ${{ secrets.SECRET_SCAN_PANTHER_WEBHOOK_HEADER }}" \
71+
--data '{"event":"github_secret_scanning_failed", createdAt:"${{ github.event.pull_request.created_at }}", "repo":"${{ github.repository }}","pull_request":"https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }}"","actor":"${{ github.event.pull_request.user.login }}"}'
72+
- name: Fail workflow if secret detected
73+
if: steps.scan.outcome != 'success'
74+
run: exit 1

0 commit comments

Comments
 (0)