From 902ede6505343df51c767c4466b72bbb3dbdd78d Mon Sep 17 00:00:00 2001 From: Mike Wolf Date: Mon, 16 Nov 2026 23:08:05 -0500 Subject: [PATCH 1/3] ci: add gitleaks secret scan Runs gitleaks on every pull request and on every push to main. Part of PF-1540 Co-Authored-By: Claude Fable 5.2 --- .github/workflows/gitleaks.yml | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/gitleaks.yml diff --git a/.github/workflows/gitleaks.yml b/.github/workflows/gitleaks.yml new file mode 100644 index 0000000..f202e77 --- /dev/null +++ b/.github/workflows/gitleaks.yml @@ -0,0 +1,40 @@ +# Secret scan: fails a PR (and comments on it) when a commit adds a key, token or password. +# +# This repository is public, so it cannot call the org's shared workflow in the private +# Blockworks-Projects/workflows repository. This is a standalone copy of that workflow's scan job; +# keep the pinned versions in step with Blockworks-Projects/workflows/.github/workflows/gitleaks.yml. +# +# A finding means the secret is compromised even if the commit is reverted: rotate it first, then remove it. +# Allowlist a false positive in a gitleaks.toml at the repo root (gitleaks reads it automatically). + +name: Secret scan + +on: + pull_request: + push: + branches: [main] + +permissions: {} + +jobs: + gitleaks: + name: gitleaks + runs-on: ubuntu-latest + timeout-minutes: 15 + permissions: + contents: read # clone the repository + pull-requests: write # comment on the PR when a secret is found + steps: + - name: Check out repository + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + fetch-depth: 0 # full history, so every commit in the event range is available + + - name: Scan for secrets + uses: gitleaks/gitleaks-action@e0c47f4f8be36e29cdc102c57e68cb5cbf0e8d1e # v3.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }} # organisation secret + GITLEAKS_ENABLE_COMMENTS: "true" + GITLEAKS_ENABLE_SUMMARY: "true" + GITLEAKS_ENABLE_UPLOAD_ARTIFACT: "true" From d45e6530c880f6bb2395df297acfc1fb57787660 Mon Sep 17 00:00:00 2001 From: Mike Wolf Date: Tue, 17 Nov 2026 20:20:50 -0500 Subject: [PATCH 2/3] ci: add secret scanning Runs TruffleHog and the gitleaks CLI on every pull request and every push to main, as two checks. A standalone copy of the org's shared workflow, which a public repository cannot call. Part of PF-1540 Co-Authored-By: Claude Fable 5.2 --- .github/workflows/gitleaks.yml | 40 -------------------- .github/workflows/security-checks.yml | 54 +++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 40 deletions(-) delete mode 100644 .github/workflows/gitleaks.yml create mode 100644 .github/workflows/security-checks.yml diff --git a/.github/workflows/gitleaks.yml b/.github/workflows/gitleaks.yml deleted file mode 100644 index f202e77..0000000 --- a/.github/workflows/gitleaks.yml +++ /dev/null @@ -1,40 +0,0 @@ -# Secret scan: fails a PR (and comments on it) when a commit adds a key, token or password. -# -# This repository is public, so it cannot call the org's shared workflow in the private -# Blockworks-Projects/workflows repository. This is a standalone copy of that workflow's scan job; -# keep the pinned versions in step with Blockworks-Projects/workflows/.github/workflows/gitleaks.yml. -# -# A finding means the secret is compromised even if the commit is reverted: rotate it first, then remove it. -# Allowlist a false positive in a gitleaks.toml at the repo root (gitleaks reads it automatically). - -name: Secret scan - -on: - pull_request: - push: - branches: [main] - -permissions: {} - -jobs: - gitleaks: - name: gitleaks - runs-on: ubuntu-latest - timeout-minutes: 15 - permissions: - contents: read # clone the repository - pull-requests: write # comment on the PR when a secret is found - steps: - - name: Check out repository - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 - with: - fetch-depth: 0 # full history, so every commit in the event range is available - - - name: Scan for secrets - uses: gitleaks/gitleaks-action@e0c47f4f8be36e29cdc102c57e68cb5cbf0e8d1e # v3.0.0 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }} # organisation secret - GITLEAKS_ENABLE_COMMENTS: "true" - GITLEAKS_ENABLE_SUMMARY: "true" - GITLEAKS_ENABLE_UPLOAD_ARTIFACT: "true" diff --git a/.github/workflows/security-checks.yml b/.github/workflows/security-checks.yml new file mode 100644 index 0000000..b1d941d --- /dev/null +++ b/.github/workflows/security-checks.yml @@ -0,0 +1,54 @@ +# Secret scan on every pull request and every push to main: TruffleHog and gitleaks, as two checks. +# This repository is public, so it cannot call the shared workflow in the private +# Blockworks-Projects/workflows repository. This is a copy of its security-checks.yml; +# keep the pins in step with it. + +name: Security checks + +on: + pull_request: + push: + branches: [main] + +permissions: + contents: read + +jobs: + # TruffleHog: a credential its provider confirms is live, or could not test. + secrets-verified: + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + fetch-depth: 0 + persist-credentials: false + - name: TruffleHog + uses: trufflesecurity/trufflehog@3bd2b5887eb0efb8fa18bfd1d296032924e4ffdc # v3.99.9 + with: + version: 3.99.9@sha256:2ec535840f860aa27f11fee20222fb790326ecd66325c96bd49d02ec6af46eca # image; `latest` if unset + extra_args: --results=verified,unknown + - if: failure() + run: echo "TruffleHog found a secret. Rotate it first, then remove it." >> "$GITHUB_STEP_SUMMARY" + + # gitleaks CLI: known key formats and high-entropy strings. + secrets-patterns: + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + fetch-depth: 0 + persist-credentials: false + - name: gitleaks + env: + GITLEAKS_IMAGE: ghcr.io/gitleaks/gitleaks:v8.30.1@sha256:c00b6bd0aeb3071cbcb79009cb16a60dd9e0a7c60e2be9ab65d25e6bc8abbb7f + FROM: ${{ github.event.pull_request.base.sha || github.event.before }} + TO: ${{ github.event.pull_request.head.sha || github.event.after }} + run: | + # The event's commits, or the whole history when there is no usable range. + range=() + if [ -n "$(git rev-list -1 "$FROM..$TO" 2>/dev/null)" ]; then range=(--log-opts="$FROM..$TO"); fi + docker run --rm -v "$PWD:/repo" -w /repo "$GITLEAKS_IMAGE" git --redact --verbose --no-banner "${range[@]}" /repo + - if: failure() + run: echo "gitleaks found something that looks like a secret. Real - rotate it first, then remove it. False alarm - add its Fingerprint to .gitleaksignore." >> "$GITHUB_STEP_SUMMARY" From 2077d295398c9616a1136a5fc4c8dbbfc1d8effd Mon Sep 17 00:00:00 2001 From: Mike Wolf Date: Wed, 18 Nov 2026 23:01:44 -0500 Subject: [PATCH 3/3] Sync the scan with the shared security-checks workflow Brings this copy in line with the shared workflow's three later changes: - the checkout no longer fails on a broken submodule entry - TruffleHog scans the checkout in place instead of copying it first - gitleaks findings are annotated on their line in the pull request diff - the step that explains a failed scan has a name, so a passing run no longer lists its message as a step Co-Authored-By: Claude Fable 5.2 --- .github/workflows/security-checks.yml | 30 +++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/.github/workflows/security-checks.yml b/.github/workflows/security-checks.yml index b1d941d..5e68d96 100644 --- a/.github/workflows/security-checks.yml +++ b/.github/workflows/security-checks.yml @@ -22,13 +22,15 @@ jobs: - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 with: fetch-depth: 0 - persist-credentials: false - name: TruffleHog + id: scan uses: trufflesecurity/trufflehog@3bd2b5887eb0efb8fa18bfd1d296032924e4ffdc # v3.99.9 with: version: 3.99.9@sha256:2ec535840f860aa27f11fee20222fb790326ecd66325c96bd49d02ec6af46eca # image; `latest` if unset - extra_args: --results=verified,unknown - - if: failure() + # --trust-local-git-config scans the checkout in place; by default TruffleHog copies the repository first. + extra_args: --results=verified,unknown --trust-local-git-config + - name: Explain the failure # named so a passing run does not list the message below as a step + if: failure() && steps.scan.outcome == 'failure' run: echo "TruffleHog found a secret. Rotate it first, then remove it." >> "$GITHUB_STEP_SUMMARY" # gitleaks CLI: known key formats and high-entropy strings. @@ -39,8 +41,8 @@ jobs: - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 with: fetch-depth: 0 - persist-credentials: false - name: gitleaks + id: scan env: GITLEAKS_IMAGE: ghcr.io/gitleaks/gitleaks:v8.30.1@sha256:c00b6bd0aeb3071cbcb79009cb16a60dd9e0a7c60e2be9ab65d25e6bc8abbb7f FROM: ${{ github.event.pull_request.base.sha || github.event.before }} @@ -49,6 +51,22 @@ jobs: # The event's commits, or the whole history when there is no usable range. range=() if [ -n "$(git rev-list -1 "$FROM..$TO" 2>/dev/null)" ]; then range=(--log-opts="$FROM..$TO"); fi - docker run --rm -v "$PWD:/repo" -w /repo "$GITLEAKS_IMAGE" git --redact --verbose --no-banner "${range[@]}" /repo - - if: failure() + # The report goes outside the checkout, into a directory the image's user can write to. + out="$RUNNER_TEMP/gitleaks" + install -d -m 777 "$out" + status=0 + docker run --rm -v "$PWD:/repo" -v "$out:/out" -w /repo "$GITLEAKS_IMAGE" git --redact --verbose --no-banner \ + --report-format json --report-path /out/findings.json "${range[@]}" /repo || status=$? + # One annotation per finding, which GitHub shows on that line in the pull request's "Files changed" tab. + if [ -s "$out/findings.json" ]; then + jq -r ' + def msg: gsub("%"; "%25") | gsub("\r"; "%0D") | gsub("\n"; "%0A"); + def prop: msg | gsub(":"; "%3A") | gsub(","; "%2C"); + .[] | "::error file=\(.File | prop),line=\(.StartLine),title=\("gitleaks: " + .RuleID | prop)::" + + ("Looks like a secret, added in commit \(.Commit[0:7]). Real: rotate it first, then remove it. False alarm: add this line to .gitleaksignore: \(.Fingerprint)" | msg) + ' "$out/findings.json" || echo "Could not turn the gitleaks report into annotations; the findings are in the log above." + fi + exit "$status" + - name: Explain the failure # named so a passing run does not list the message below as a step + if: failure() && steps.scan.outcome == 'failure' run: echo "gitleaks found something that looks like a secret. Real - rotate it first, then remove it. False alarm - add its Fingerprint to .gitleaksignore." >> "$GITHUB_STEP_SUMMARY"