|
1 | 1 | # SPDX-License-Identifier: PMPL-1.0-or-later |
2 | | -# Prevention workflow - scans for hardcoded secrets before they reach main |
3 | 2 | name: Secret Scanner |
4 | 3 |
|
5 | 4 | on: |
6 | 5 | pull_request: |
7 | 6 | push: |
8 | 7 | branches: [main] |
9 | 8 |
|
| 9 | +concurrency: |
| 10 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
10 | 13 | permissions: |
11 | 14 | contents: read |
12 | 15 |
|
13 | 16 | jobs: |
14 | | - trufflehog: |
15 | | - runs-on: ubuntu-latest |
16 | | - steps: |
17 | | - - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v4 |
18 | | - with: |
19 | | - fetch-depth: 0 # Full history for scanning |
20 | | - |
21 | | - # The trufflehog GitHub Action wraps a Docker range-scan |
22 | | - # (--since-commit BASE --branch HEAD against :latest) that fails on PRs |
23 | | - # even when there are zero secrets. A full-history filesystem scan is |
24 | | - # deterministic and is the mode actually intended here. Version pinned |
25 | | - # for reproducibility. |
26 | | - - name: Install TruffleHog |
27 | | - run: | |
28 | | - curl -sSfL https://raw.githubusercontent.com/trufflesecurity/trufflehog/main/scripts/install.sh \ |
29 | | - | sh -s -- -b /usr/local/bin v3.95.3 |
30 | | -
|
31 | | - - name: TruffleHog Secret Scan (full history) |
32 | | - run: trufflehog git "file://$GITHUB_WORKSPACE" --only-verified --fail --no-update |
33 | | - |
34 | | - gitleaks: |
35 | | - runs-on: ubuntu-latest |
36 | | - steps: |
37 | | - - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v4 |
38 | | - with: |
39 | | - fetch-depth: 0 |
40 | | - |
41 | | - - name: Gitleaks Secret Scan |
42 | | - uses: gitleaks/gitleaks-action@ff98106e4c7b2bc287b24eaf42907196329070c7 # v2 |
43 | | - env: |
44 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
45 | | - |
46 | | - # Rust-specific: Check for hardcoded crypto values |
47 | | - rust-secrets: |
48 | | - runs-on: ubuntu-latest |
49 | | - steps: |
50 | | - - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v4 |
51 | | - |
52 | | - - name: Check for hardcoded secrets in Rust |
53 | | - run: | |
54 | | - if ! find . -name Cargo.toml -not -path './target/*' -print -quit | grep -q .; then |
55 | | - echo 'No Cargo.toml found — skipping Rust secrets check' |
56 | | - exit 0 |
57 | | - fi |
58 | | - # Patterns that suggest hardcoded secrets |
59 | | - PATTERNS=( |
60 | | - 'const.*SECRET.*=.*"' |
61 | | - 'const.*KEY.*=.*"[a-zA-Z0-9]{16,}"' |
62 | | - 'const.*TOKEN.*=.*"' |
63 | | - 'let.*api_key.*=.*"' |
64 | | - 'HMAC.*"[a-fA-F0-9]{32,}"' |
65 | | - 'password.*=.*"[^"]+"' |
66 | | - ) |
67 | | -
|
68 | | - found=0 |
69 | | - for pattern in "${PATTERNS[@]}"; do |
70 | | - if grep -rn --include="*.rs" -E "$pattern" src/; then |
71 | | - echo "WARNING: Potential hardcoded secret found matching: $pattern" |
72 | | - found=1 |
73 | | - fi |
74 | | - done |
75 | | -
|
76 | | - if [ $found -eq 1 ]; then |
77 | | - echo "::error::Potential hardcoded secrets detected. Use environment variables instead." |
78 | | - exit 1 |
79 | | - fi |
| 17 | + scan: |
| 18 | + uses: hyperpolymath/standards/.github/workflows/secret-scanner-reusable.yml@3e4bd4c93911750727e2e4c66dff859e00079da0 |
| 19 | + secrets: inherit |
0 commit comments