diff --git a/.github/workflows/gitleaks.yml b/.github/workflows/gitleaks.yml new file mode 100644 index 0000000..8e503f7 --- /dev/null +++ b/.github/workflows/gitleaks.yml @@ -0,0 +1,38 @@ +# Free: the MIT gitleaks CLI, not the separately licensed Action wrapper. +# PR scans block merge; main-push scans only warn (history is already published). +name: gitleaks +on: + pull_request: + push: + branches: [main] +permissions: + contents: read +jobs: + gitleaks: + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + persist-credentials: false + - name: Install checksum-pinned gitleaks CLI 8.30.1 + id: install + run: | + set -euo pipefail + cd "$RUNNER_TEMP" + curl -fsSL --max-time 60 -o gl.tar.gz \ + https://github.com/gitleaks/gitleaks/releases/download/v8.30.1/gitleaks_8.30.1_linux_x64.tar.gz + echo '551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb gl.tar.gz' | sha256sum --check --strict + tar -xzf gl.tar.gz gitleaks + test "$(./gitleaks version)" = '8.30.1' + - name: Scan only this event's commits + id: scan + continue-on-error: ${{ github.event_name == 'push' }} + env: + RANGE: ${{ github.event_name == 'pull_request' && format('{0}..{1}', github.event.pull_request.base.sha, github.event.pull_request.head.sha) || format('{0}..{1}', github.event.before, github.event.after) }} + run: | + "$RUNNER_TEMP/gitleaks" git --no-banner --redact --exit-code 1 --log-opts="$RANGE" . + - name: Alert on a main-push finding + if: always() && github.event_name == 'push' && steps.scan.outcome == 'failure' + run: echo '::warning::gitleaks found candidates on main; operator review required.'