Repository navigation
chore(deps): bump actions/checkout from 4 to 7 #36
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: secret-scan | |
| # ADVISORY - not a required check. Fails the run if a commit this push/PR ADDS contains a secret. | |
| # | |
| # Runs the gitleaks binary directly instead of gitleaks/gitleaks-action, which needs a | |
| # GITLEAKS_LICENSE secret on organisation-owned repos. The binary needs no secret at all, so | |
| # this job cannot go red for a missing licence. The tarball is verified against a pinned | |
| # SHA-256 before it is unpacked (bump version and hash together; the hash is published in the | |
| # release's gitleaks_<version>_checksums.txt). | |
| # | |
| # --redact is deliberate and must stay: this repository is PUBLIC and so are its Actions logs, | |
| # so a finding must be reported by rule, file and line and never echoed. | |
| # | |
| # Scope, stated plainly: this scans the COMMITS IN THIS PUSH/PR RANGE. It answers "did this | |
| # change add a secret?" and is blind to anything committed before it existed. It reports | |
| # NOT_CHECKED (a warning, not a pass) if the range holds no commits. | |
| on: | |
| push: | |
| branches: ['**'] | |
| pull_request: | |
| permissions: | |
| contents: read | |
| jobs: | |
| gitleaks: | |
| name: gitleaks | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - name: Check out full history | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| - name: Install gitleaks (checksum-pinned) | |
| env: | |
| GITLEAKS_VERSION: 8.30.1 | |
| GITLEAKS_SHA256: 551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb | |
| run: | | |
| set -euo pipefail | |
| curl -sSfL --retry 3 -o "$RUNNER_TEMP/gitleaks.tar.gz" \ | |
| "https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz" | |
| echo "${GITLEAKS_SHA256} $RUNNER_TEMP/gitleaks.tar.gz" | sha256sum -c - | |
| tar -xzf "$RUNNER_TEMP/gitleaks.tar.gz" -C "$RUNNER_TEMP" gitleaks | |
| "$RUNNER_TEMP/gitleaks" version | |
| - name: Scan the commits this event adds | |
| env: | |
| EVENT_NAME: ${{ github.event_name }} | |
| PR_BASE: ${{ github.event.pull_request.base.sha }} | |
| PR_HEAD: ${{ github.event.pull_request.head.sha }} | |
| PUSH_BEFORE: ${{ github.event.before }} | |
| PUSH_AFTER: ${{ github.sha }} | |
| DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} | |
| run: | | |
| set -euo pipefail | |
| zero=0000000000000000000000000000000000000000 | |
| # Work out WHICH commits this event adds. | |
| if [ "$EVENT_NAME" = "pull_request" ]; then | |
| range=("${PR_BASE}..${PR_HEAD}") | |
| elif [ "$PUSH_BEFORE" = "$zero" ]; then | |
| # New branch: everything not already on the default branch. | |
| range=("$PUSH_AFTER" --not "origin/${DEFAULT_BRANCH}") | |
| elif git cat-file -e "${PUSH_BEFORE}^{commit}" 2>/dev/null; then | |
| range=("${PUSH_BEFORE}..${PUSH_AFTER}") | |
| else | |
| # Force-push: the old tip is not in this clone, so scan the new tip only. | |
| range=(-1 "$PUSH_AFTER") | |
| fi | |
| in_range=$(git rev-list --count "${range[@]}") | |
| echo "range: ${range[*]} (${in_range} commit(s) in range)" | |
| # --exit-code 2 = leaks found. A gitleaks crash exits 1, so "found a secret" and | |
| # "the scanner broke" are different codes; both leave the job red. | |
| report="$RUNNER_TEMP/gitleaks-report.json" | |
| log="$RUNNER_TEMP/gitleaks.log" | |
| rc=0 | |
| "$RUNNER_TEMP/gitleaks" git . \ | |
| --log-opts="${range[*]}" \ | |
| --redact --no-banner --no-color --exit-code 2 \ | |
| --report-format json --report-path "$report" 2>&1 | tee "$log" || rc=$? | |
| # Take the count from gitleaks itself, not from `git rev-list`. gitleaks diffs | |
| # commits, and a merge commit has no diff, so a range of only merge commits has a | |
| # non-zero rev-list count and 0 commits scanned. Reporting the first as the second | |
| # is how a scan "passes" over nothing. | |
| scanned=$(grep -oE '[0-9]+ commits? scanned' "$log" | head -n1 | grep -oE '^[0-9]+' || true) | |
| if [ "$rc" = "2" ]; then | |
| { | |
| echo "### secret-scan: FAILED - secret(s) found" | |
| echo "${scanned:-?} commit(s) scanned. Values are redacted; rule, file and line only:" | |
| echo | |
| jq -r 'def s: gsub("[\r\n%]"; ""); .[] | "- `\(.RuleID|s)` at `\(.File|s):\(.StartLine)` in \(.Commit[0:8]|s)"' "$report" | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| jq -r 'def s: gsub("[\r\n%]"; ""); .[] | "::error file=\(.File|s),line=\(.StartLine),title=gitleaks \(.RuleID|s)::possible secret (redacted) in commit \(.Commit[0:8]|s)"' "$report" | |
| echo "FAILED: gitleaks reported finding(s); see the summary for rule, file and line" | |
| exit 1 | |
| fi | |
| if [ "$rc" != "0" ]; then | |
| echo "FAILED: gitleaks exited ${rc}, which is a scanner error and not a finding" | |
| exit 1 | |
| fi | |
| if [ -z "$scanned" ] || [ "$scanned" = "0" ]; then | |
| echo "::warning title=secret-scan NOT_CHECKED::gitleaks scanned ${scanned:-an unreported number of} commits in range (${range[*]}); nothing was verified" | |
| { | |
| echo "### secret-scan: NOT_CHECKED" | |
| echo "gitleaks reported ${scanned:-no} commits scanned for \`${range[*]}\` (${in_range} in range). No findings, but nothing was verified either." | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| exit 0 | |
| fi | |
| { | |
| echo "### secret-scan: VERIFIED" | |
| echo "${scanned} commit(s) scanned (\`${range[*]}\`), 0 findings." | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| echo "VERIFIED: ${scanned} commit(s) scanned, 0 findings" |