Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/actions/setup-gitleaks/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Installs the pinned gitleaks release and adds it to the PATH. This file is
# the only pin of the gitleaks version, so a change to it makes the Gitleaks
# step of repository-checks.yml scan the full history.
name: Set up gitleaks
description: Install the pinned gitleaks release after a SHA-256 check.

runs:
using: composite
steps:
- name: Set up gitleaks
shell: bash
env:
GITLEAKS_VERSION: 8.30.1
# SHA-256 of gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz. Update it with GITLEAKS_VERSION.
GITLEAKS_SHA256: 551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb
# The callers run on pull_request, push, schedule, and workflow_dispatch,
# and the PATH entry is a fixed runner directory, so the write is safe.
run: | # zizmor: ignore[github-env]
archive="gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz"
curl --fail --silent --show-error --location --output "$RUNNER_TEMP/$archive" \
"https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/$archive"
echo "$GITLEAKS_SHA256 $RUNNER_TEMP/$archive" | sha256sum --check --strict
mkdir -p "$RUNNER_TEMP/bin"
tar -xzf "$RUNNER_TEMP/$archive" -C "$RUNNER_TEMP/bin" gitleaks
echo "$RUNNER_TEMP/bin" >>"$GITHUB_PATH"
50 changes: 50 additions & 0 deletions .github/workflows/gitleaks-history.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Scans the full Git history for secrets once a week, on demand, and when a
# pull request or a push to main changes .gitleaks.toml or the gitleaks pin
# in .github/actions/setup-gitleaks/action.yml. The Gitleaks step of
# repository-checks.yml scans a commit range in most runs, so this scan checks
# each commit that HEAD reaches with the pinned rules.
name: gitleaks-history

on:
schedule:
# Each Monday at 06:17 UTC.
- cron: "17 6 * * 1"
workflow_dispatch:
pull_request:
branches:
- main
paths:
- .gitleaks.toml
- .github/actions/setup-gitleaks/action.yml
push:
branches:
- main
paths:
- .gitleaks.toml
- .github/actions/setup-gitleaks/action.yml

permissions:
contents: read

jobs:
gitleaks-history:
name: gitleaks-history
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
steps:
# gitleaks scans every commit that HEAD reaches, so the job needs the full history.
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false

- uses: ./.github/actions/setup-gitleaks

# gitleaks reads .gitleaks.toml when the file exists, and its default
# rules when not. The repository is public, so --redact keeps each
# secret out of the log.
- name: Gitleaks
run: gitleaks git --no-banner --redact --verbose --log-opts=HEAD .
44 changes: 29 additions & 15 deletions .github/workflows/repository-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,18 @@ jobs:
fetch-depth: 0
persist-credentials: false

# Each tool is a release binary, pinned by its version and SHA-256.
- name: Install Gitleaks and actionlint
- uses: ./.github/actions/setup-gitleaks

# actionlint is a release binary, pinned by its version and SHA-256.
- name: Install actionlint
env:
GITLEAKS_VERSION: 8.30.1
GITLEAKS_SHA256: 551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb
ACTIONLINT_VERSION: 1.7.12
ACTIONLINT_SHA256: 8aca8db96f1b94770f1b0d72b6dddcb1ebb8123cb3712530b08cc387b349a3d8
run: |
bin="$RUNNER_TEMP/bin"
mkdir -p "$bin"
cd "$RUNNER_TEMP"

gitleaks_archive="gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz"
curl -fsSLO "https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/${gitleaks_archive}"
echo "${GITLEAKS_SHA256} ${gitleaks_archive}" | sha256sum --check
tar -xzf "$gitleaks_archive" -C "$bin" gitleaks

actionlint_archive="actionlint_${ACTIONLINT_VERSION}_linux_amd64.tar.gz"
curl -fsSLO "https://github.com/rhysd/actionlint/releases/download/v${ACTIONLINT_VERSION}/${actionlint_archive}"
echo "${ACTIONLINT_SHA256} ${actionlint_archive}" | sha256sum --check
Expand All @@ -50,21 +45,40 @@ jobs:
echo "$bin" >> "$GITHUB_PATH"

# A pull request scans its own commits (base..head), and a push to main
# scans the pushed commits (before..after). When the base commit is not
# in the clone (a zero SHA for a new branch, or a force push), the scan
# reads the full history that the head reaches.
# scans the pushed commits (before..after). Earlier runs scanned the
# older commits, and the weekly workflow gitleaks-history scans the full
# history. The step scans the full history that HEAD reaches when the
# base commit is not in the clone (a zero SHA for a new branch, or a
# force push), or when the range changes .gitleaks.toml or
# .github/actions/setup-gitleaks/action.yml.
- name: Gitleaks
env:
EVENT_NAME: ${{ github.event_name }}
GITLEAKS_BASE: ${{ github.event.pull_request.base.sha || github.event.before }}
GITLEAKS_HEAD: ${{ github.event.pull_request.head.sha || github.event.after }}
run: |
log_opts="$GITLEAKS_BASE..$GITLEAKS_HEAD"
# A pull request counts only its own changes, from the merge base.
changes="$GITLEAKS_BASE..$GITLEAKS_HEAD"
if [ "$EVENT_NAME" = pull_request ]; then
changes="$GITLEAKS_BASE...$GITLEAKS_HEAD"
fi

log_opts=HEAD
if ! git cat-file -e "$GITLEAKS_BASE^{commit}" 2>/dev/null; then
log_opts="$GITLEAKS_HEAD"
echo "The clone does not hold the base commit: scan the full history."
else
changed="$(git diff --name-only "$changes" -- .gitleaks.toml .github/actions/setup-gitleaks/action.yml)"
if [ -n "$changed" ]; then
echo "$changes changes the gitleaks rules or version: scan the full history."
else
log_opts="$GITLEAKS_BASE..$GITLEAKS_HEAD"
fi
fi
echo "Gitleaks: --log-opts=$log_opts"

# The repository is public, so --redact keeps each secret out of the log.
# gitleaks reads .gitleaks.toml when the file exists, and its default
# rules when not. The repository is public, so --redact keeps each
# secret out of the log.
gitleaks git --no-banner --redact --verbose --log-opts="$log_opts" .

- name: Markdown lint
Expand Down