Skip to content
Draft
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
43 changes: 43 additions & 0 deletions .github/workflows/privacy-guard-history-audit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Optional, non-required weekly full-history audit. Use this only in a
# repo that has a committed .privacy-baseline for accepted historical
# exposure. Copy to .github/workflows/privacy-guard-history-audit.yml.
# Do not add "Privacy Guard history audit" as a required status check.
# The required Privacy Guard job still covers new commits; this job
# reports remaining historical findings until a rewrite is authorised.
#
# This file contains no personal data and no account-specific addresses.

name: Privacy Guard history audit

on:
schedule:
- cron: "17 4 * * 1"
workflow_dispatch:

permissions:
contents: read

jobs:
privacy-guard-history-audit:
name: Privacy Guard history audit
runs-on: ubuntu-latest
env:
GITLEAKS_VERSION: "8.30.1"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install gitleaks
run: |
set -euo pipefail
base="https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}"
archive="gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz"
curl -sSfL -o "$RUNNER_TEMP/$archive" "$base/$archive"
curl -sSfL -o "$RUNNER_TEMP/checksums.txt" "$base/gitleaks_${GITLEAKS_VERSION}_checksums.txt"
(cd "$RUNNER_TEMP" && grep " ${archive}\$" checksums.txt | sha256sum -c -)
tar -xzf "$RUNNER_TEMP/$archive" -C "$RUNNER_TEMP" gitleaks
echo "$RUNNER_TEMP" >> "$GITHUB_PATH"
- name: Scan history for secrets
run: gitleaks detect --source . --log-opts=--all --redact --no-banner --exit-code 1
- name: Check commit emails and trailers over full history
run: bash scripts/check-commit-emails.sh --all
75 changes: 14 additions & 61 deletions .github/workflows/privacy-guard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
# .privacy-allowlist
# And optionally:
# .githooks/pre-push (see pre-push in this directory)
# .privacy-baseline (see privacy-baseline.example)
# privacy-guard-history-audit.yml (weekly full-history audit;
# do not make it a required check)
#
# Then add "Privacy Guard" as a required status check on the default branch.
# Do not print secret or personal values in logs. This file contains no
Expand All @@ -21,25 +24,17 @@ name: Privacy Guard
on:
push:
pull_request:
# Deviation from the vllnt/skills template: pre-existing history fails
# the full-history email scan, and the template has no SHA baseline.
# The required job scopes push scans to the pushed range; this
# scheduled/manual job reports a full-history audit and is not required.
schedule:
- cron: "17 4 * * 1"
workflow_dispatch:

permissions:
contents: read

concurrency:
group: privacy-guard-${{ github.event_name }}-${{ github.head_ref || github.ref }}
group: privacy-guard-${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
privacy-guard:
name: Privacy Guard
if: github.event_name != 'schedule' && github.event_name != 'workflow_dispatch'
runs-on: ubuntu-latest
env:
GITLEAKS_VERSION: "8.30.1"
Expand Down Expand Up @@ -90,12 +85,18 @@ jobs:
REF_NAME: ${{ github.ref_name }}
run: |
set -euo pipefail
# Deviation from the vllnt/skills template: pre-existing history
# fails the full-history email scan, and the template has no SHA
# baseline. Pull requests: the commits this PR adds. Pushes with
# a known before SHA: the pushed range. Otherwise: full history.
# Validate a committed .privacy-baseline whenever it is present.
# Pull requests: the commits this PR adds. Push: baseline..HEAD
# when a baseline exists, otherwise full history on the default
# branch, or the pushed range on other refs.
baseline="$(bash scripts/check-commit-emails.sh --print-baseline)"
if [[ "$EVENT_NAME" == "pull_request" ]]; then
export PRIVACY_COMMIT_RANGE="${PR_BASE}..${PR_HEAD}"
elif [[ -n "${baseline}" ]]; then
echo "commit-metadata range: ${baseline:0:12}..HEAD"
export PRIVACY_COMMIT_RANGE="${baseline}..HEAD"
elif [[ "$EVENT_NAME" == "push" && "$REF_NAME" == "$DEFAULT_BRANCH" ]]; then
export PRIVACY_COMMIT_RANGE="--all"
elif [[ "$EVENT_NAME" == "push" && "${BEFORE:-}" != "" && "$BEFORE" != 0000000000000000000000000000000000000000 ]]; then
export PRIVACY_COMMIT_RANGE="${BEFORE}..HEAD"
else
Expand All @@ -117,51 +118,3 @@ jobs:
- name: Check package contents
run: bash scripts/check-package-contents.sh

privacy-guard-history-audit:
name: Privacy Guard history audit
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
env:
GITLEAKS_VERSION: "8.30.1"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install gitleaks
run: |
set -euo pipefail
base="https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}"
archive="gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz"
curl -sSfL -o "$RUNNER_TEMP/$archive" "$base/$archive"
curl -sSfL -o "$RUNNER_TEMP/checksums.txt" "$base/gitleaks_${GITLEAKS_VERSION}_checksums.txt"
(cd "$RUNNER_TEMP" && grep " ${archive}\$" checksums.txt | sha256sum -c -)
tar -xzf "$RUNNER_TEMP/$archive" -C "$RUNNER_TEMP" gitleaks
echo "$RUNNER_TEMP" >> "$GITHUB_PATH"
- name: Scan history for secrets
run: gitleaks detect --source . --log-opts=--all --redact --no-banner --exit-code 1
- name: Test denylist guard
run: bash scripts/test-privacy-denylist.sh
- name: Test commit-metadata email check
run: bash scripts/test-check-commit-emails.sh
- name: Check denylist
env:
PRIVACY_DENYLIST_EXTRA: ${{ secrets.PRIVACY_DENYLIST_EXTRA }}
run: |
set -euo pipefail
code=0
bash scripts/privacy-denylist.sh || code=$?
if [[ "$code" -eq 0 ]]; then
exit 0
fi
if [[ "$code" -eq 2 && -n "${PRIVACY_DENYLIST_EXTRA:-}" ]]; then
echo "::warning title=Privacy guard::PRIVACY_DENYLIST_EXTRA has invalid regex line(s) for git grep -E. Re-running with the tracked denylist only. Fix the Actions secret."
unset PRIVACY_DENYLIST_EXTRA
bash scripts/privacy-denylist.sh
exit $?
fi
exit "$code"
- name: Check commit emails and trailers (full history)
run: |
set -euo pipefail
export PRIVACY_COMMIT_RANGE="--all"
bash scripts/check-commit-emails.sh
8 changes: 8 additions & 0 deletions .privacy-baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Placeholder draft. decided is not an acceptance date.
# Do not merge until the exposure is accepted and recorded
# in the security-findings ledger.
#
# Required keys (no others):
sha: 8cd099d035f7e0673377844f5038f3861798dc88
reason: historical commit-metadata findings; no rewrite
decided: 1970-01-01
115 changes: 113 additions & 2 deletions scripts/check-commit-emails.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@
# Range (first match wins):
# $PRIVACY_COMMIT_RANGE a git revision range, or the token --all
# --range <rev> | --all command-line flags
# otherwise, if a baseline file is present, <baseline-sha>..HEAD
# otherwise --all
#
# Optional committed baseline file (default .privacy-baseline, override
# with $PRIVACY_BASELINE_FILE or --baseline-file). Allowed only for
# historical exposure the maintainer has accepted, recorded in the
# security-findings ledger. The file is validated whenever it is present.
# --print-baseline prints the resolved SHA and exits, or prints nothing
# and exits 0 when the file is absent.
#
# Allowed emails (override with $ALLOWED_EMAIL_PATTERN):
# *@users.noreply.github.com and noreply@github.com
#
Expand Down Expand Up @@ -41,11 +49,84 @@ HOSTNAME_PATTERN="${TS_NET}|${OVH_VPS}|${OVH_VPS_CA}|${HETZNER_DED}|${HETZNER_CL
IP_PATTERN="${CGNAT}|${RFC10}|${RFC192}|${RFC172}"

usage() {
echo "usage: $0 [--all] [--range <rev>]" >&2
echo "usage: $0 [--all] [--range <rev>] [--print-baseline] [--baseline-file <path>]" >&2
exit 2
}

# parse_baseline <path>
# Prints the resolved 40-character commit SHA on stdout.
# Exit 2 on a present but invalid file. Does not print reason text.
parse_baseline() {
local file="$1"
local line key value sha="" reason="" decided=""
local -A seen=()
while IFS= read -r line || [[ -n "$line" ]]; do
line="${line%$'\r'}"
[[ -z "${line// /}" ]] && continue
[[ "$line" == \#* ]] && continue
if [[ "$line" != *:* ]]; then
echo "error: .privacy-baseline has a malformed line" >&2
return 2
fi
key="${line%%:*}"
value="${line#*:}"
key="${key#"${key%%[![:space:]]*}"}"
key="${key%"${key##*[![:space:]]}"}"
value="${value#"${value%%[![:space:]]*}"}"
value="${value%"${value##*[![:space:]]}"}"
key="${key,,}"
if [[ -z "$key" ]]; then
echo "error: .privacy-baseline has a malformed line" >&2
return 2
fi
if [[ -n "${seen[$key]:-}" ]]; then
echo "error: .privacy-baseline has a duplicate key" >&2
return 2
fi
seen[$key]=1
case "$key" in
sha)
if [[ ! "$value" =~ ^[0-9a-fA-F]{7,40}$ ]]; then
echo "error: .privacy-baseline sha is not a git SHA" >&2
return 2
fi
sha="$value"
;;
reason)
if [[ -z "$value" ]]; then
echo "error: .privacy-baseline reason is empty" >&2
return 2
fi
reason="$value"
;;
decided)
if [[ ! "$value" =~ ^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$ ]]; then
echo "error: .privacy-baseline decided must be YYYY-MM-DD" >&2
return 2
fi
decided="$value"
;;
*)
echo "error: .privacy-baseline has an unknown key" >&2
return 2
;;
esac
done < "$file"
if [[ -z "$sha" || -z "$reason" || -z "$decided" ]]; then
echo "error: .privacy-baseline must set sha, reason, and decided" >&2
return 2
fi
local resolved
if ! resolved="$(git rev-parse --verify "${sha}^{commit}" 2>/dev/null)"; then
echo "error: .privacy-baseline sha does not resolve to a commit" >&2
return 2
fi
printf '%s\n' "$resolved"
}

RANGE="${PRIVACY_COMMIT_RANGE:-}"
BASELINE_FILE="${PRIVACY_BASELINE_FILE:-.privacy-baseline}"
PRINT_BASELINE=0
while [[ $# -gt 0 ]]; do
case "$1" in
--all) RANGE="--all"; shift ;;
Expand All @@ -54,11 +135,41 @@ while [[ $# -gt 0 ]]; do
RANGE="$2"
shift 2
;;
--print-baseline) PRINT_BASELINE=1; shift ;;
--baseline-file)
[[ $# -ge 2 ]] || usage
BASELINE_FILE="$2"
shift 2
;;
-h|--help) usage ;;
*) usage ;;
esac
done
[[ -n "$RANGE" ]] || RANGE="--all"

BASELINE_SHA=""
if [[ -f "$BASELINE_FILE" ]]; then
if ! BASELINE_SHA="$(parse_baseline "$BASELINE_FILE")"; then
exit 2
fi
elif [[ -e "$BASELINE_FILE" ]]; then
echo "error: .privacy-baseline exists but is not a regular file" >&2
exit 2
fi

if [[ "$PRINT_BASELINE" -eq 1 ]]; then
if [[ -n "$BASELINE_SHA" ]]; then
printf '%s\n' "$BASELINE_SHA"
fi
exit 0
fi

if [[ -z "$RANGE" ]]; then
if [[ -n "$BASELINE_SHA" ]]; then
RANGE="${BASELINE_SHA}..HEAD"
else
RANGE="--all"
fi
fi

# Validate the allowed-email pattern without printing it.
if ! printf 'a@users.noreply.github.com\n' | grep -qE "$ALLOWED_EMAIL_PATTERN"; then
Expand Down
Loading
Loading