|
1 | 1 | # SPDX-License-Identifier: MPL-2.0 |
2 | | -# Prevention workflow - scans for hardcoded secrets before they reach main |
| 2 | +# Prevention workflow - scans for hardcoded secrets before they reach main. |
| 3 | +# |
| 4 | +# Calls the estate's shared secret scanner (gitleaks + rust-secrets + |
| 5 | +# shell-secrets). The job key MUST stay `scan`: the estate-wide |
| 6 | +# Secret-Scan-Floor ruleset requires the check context `scan / gitleaks`. |
| 7 | +# |
| 8 | +# `secrets: inherit` is REQUIRED - without it the gitleaks action's inner |
| 9 | +# secrets.GITHUB_TOKEN is empty and the scan silently degrades. |
3 | 10 | name: Secret Scanner |
| 11 | + |
4 | 12 | on: |
5 | 13 | pull_request: |
6 | 14 | push: |
7 | 15 | branches: [main] |
8 | | -# Estate guardrail: cancel superseded runs so re-pushes / rebased PR |
9 | | -# updates do not pile up queued runs against the shared account-wide |
10 | | -# Actions concurrency pool. Applied only to read-only check workflows |
11 | | -# (no publish/mutation), so cancelling a superseded run is always safe. |
| 16 | + |
12 | 17 | concurrency: |
13 | 18 | group: ${{ github.workflow }}-${{ github.ref }} |
14 | 19 | cancel-in-progress: true |
| 20 | + |
15 | 21 | permissions: |
16 | 22 | contents: read |
17 | | -jobs: |
18 | | - trufflehog: |
19 | | - runs-on: ubuntu-latest |
20 | | - timeout-minutes: 15 |
21 | | - steps: |
22 | | - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v4 |
23 | | - with: |
24 | | - fetch-depth: 0 # Full history for scanning |
25 | | - - name: TruffleHog Secret Scan |
26 | | - uses: trufflesecurity/trufflehog@a5f3de55cc2065ae4dde8fee24076f137fd62fcf # v3 |
27 | | - with: |
28 | | - # The v3 action injects --fail automatically on pull_request events. |
29 | | - # Passing --fail here triggers "flag 'fail' cannot be repeated". |
30 | | - extra_args: --only-verified |
31 | | - |
32 | | - gitleaks: |
33 | | - runs-on: ubuntu-latest |
34 | | - timeout-minutes: 15 |
35 | | - steps: |
36 | | - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v4 |
37 | | - with: |
38 | | - fetch-depth: 0 |
39 | 23 |
|
40 | | - - name: Gitleaks Secret Scan |
41 | | - uses: gitleaks/gitleaks-action@e0c47f4f8be36e29cdc102c57e68cb5cbf0e8d1e # v3.0.0 |
42 | | - env: |
43 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
44 | | - |
45 | | - # Rust-specific: Check for hardcoded crypto values |
46 | | - rust-secrets: |
47 | | - runs-on: ubuntu-latest |
48 | | - timeout-minutes: 15 |
49 | | - steps: |
50 | | - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # 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 |
| 24 | +jobs: |
| 25 | + scan: |
| 26 | + uses: hyperpolymath/standards/.github/workflows/secret-scanner-reusable.yml@74d2f66f575246cf6e313ae7775f44df6e097ff2 |
| 27 | + secrets: inherit |
0 commit comments