diff --git a/.github/workflows/privacy-guard.yml b/.github/workflows/privacy-guard.yml index 727e2a1..0dc9e05 100644 --- a/.github/workflows/privacy-guard.yml +++ b/.github/workflows/privacy-guard.yml @@ -68,8 +68,16 @@ jobs: REF_NAME: ${{ github.ref_name }} run: | set -euo pipefail + # 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 diff --git a/CHANGELOG.md b/CHANGELOG.md index c59b27f..6c7ca58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Extend `Privacy Guard` with optional `.privacy-baseline` support, so the required commit-metadata check can scan `baseline..HEAD` on push when historical exposure has been accepted. Mirrors vllnt/skills. + - Accept the reviewed Skills `v0.2.0` update from `7483dd4dfd8502fd2db376c13e44fa0cbc464161` to `06365b10b42d1c56308b946187d51ccf1efa7d33` as `0.1.0-canary.9` through a separate protected PR, because the range changes sensitive paths. Adds the `init-project` workflow (replacing `build-project`), defaults packages to the newest stable release behind the 7-day age gate, defers fast-changing tool detail to official docs, and adds machine security and privacy workflows. The automatic sensitivity policy is unchanged. - Fix the `Privacy Guard` denylist check: validate patterns with the same `git grep -iE` engine that scans them, reject PCRE-only escapes, normalize CRLF and blank private lines, and report an invalid pattern by source and line only. Mirrors vllnt/skills. diff --git a/scripts/check-commit-emails.sh b/scripts/check-commit-emails.sh index e3897ac..8607b7d 100755 --- a/scripts/check-commit-emails.sh +++ b/scripts/check-commit-emails.sh @@ -11,8 +11,16 @@ # Range (first match wins): # $PRIVACY_COMMIT_RANGE a git revision range, or the token --all # --range | --all command-line flags +# otherwise, if a baseline file is present, ..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 # @@ -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 ]" >&2 + echo "usage: $0 [--all] [--range ] [--print-baseline] [--baseline-file ]" >&2 exit 2 } +# parse_baseline +# 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 ;; @@ -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 diff --git a/scripts/test-check-commit-emails.sh b/scripts/test-check-commit-emails.sh index 63469d1..50919ab 100755 --- a/scripts/test-check-commit-emails.sh +++ b/scripts/test-check-commit-emails.sh @@ -17,6 +17,7 @@ chmod +x "$REPO/scripts/check-commit-emails.sh" git -C "$REPO" init -q git -C "$REPO" config user.email "123+tester@users.noreply.github.com" git -C "$REPO" config user.name tester +git -C "$REPO" config commit.gpgsign false failures=0 LAST_OUTPUT="" @@ -50,9 +51,12 @@ run() { --all) args+=("$1"); shift ;; - --range) + --range|--baseline-file) args+=("$1" "$2"); shift 2 ;; + --print-baseline) + args+=("$1"); shift + ;; *=*) envvars+=("$1"); shift ;; @@ -173,6 +177,102 @@ run "invalid range exits 2" 2 --range "this-is-not-a-rev-xyz" run "full history with dirt fails" 1 --all expect "full history fail line" "FAIL commit metadata" +# --- SHA baseline --- + +write_baseline() { + local dest="${4:-$REPO/.privacy-baseline}" + printf '%s\n' \ + "# test fixture — not a production baseline" \ + "" \ + "sha: $1" \ + "reason: $2" \ + "decided: $3" \ + > "$dest" +} + +# 13. No baseline file: --print-baseline is silent and succeeds. +run "print-baseline without file is silent" 0 --print-baseline +if [[ -n "$LAST_OUTPUT" ]]; then + printf 'FAIL print-baseline without file: expected empty output\n%s\n' "$LAST_OUTPUT" >&2 + failures=$((failures + 1)) +fi + +# 14–16. A valid baseline excludes earlier dirt and is printed as a full SHA. +commit "dirt before baseline" GIT_AUTHOR_EMAIL="$DISALLOWED_ADDR" GIT_COMMITTER_EMAIL="$DISALLOWED_ADDR" +dirty_full="$(git -C "$REPO" rev-parse HEAD)" +commit "clean after baseline" +write_baseline "$dirty_full" "accepted historical test fixture" "2026-11-22" +run "print-baseline emits resolved sha" 0 --print-baseline +if [[ "$LAST_OUTPUT" != "$dirty_full" ]]; then + printf 'FAIL print-baseline emits resolved sha: expected the baseline sha only\n' >&2 + failures=$((failures + 1)) +fi +run "baseline excludes earlier dirt" 0 +expect "baseline auto-range ok" "OK" +run "explicit --all overrides baseline" 1 --all +expect "override still reports fail" "FAIL commit metadata" +refute "override withholds disallowed" "$DISALLOWED_ADDR" + +# 17. Dirt after the baseline is still detected. +commit "dirt after baseline" GIT_AUTHOR_EMAIL="$DISALLOWED_ADDR" GIT_COMMITTER_EMAIL="$DISALLOWED_ADDR" +run "dirt after baseline still fails" 1 +expect "post-baseline finding" "disallowed-email" +refute "post-baseline withheld" "$DISALLOWED_ADDR" + +# 18. Explicit --range still wins, and a present valid file is accepted. +root="$(git -C "$REPO" rev-list --max-parents=0 HEAD)" +run "explicit clean range wins over baseline" 0 --range "$root" +expect "explicit range ok" "OK" + +# 19. Invalid files fail even when a range flag is also given. +write_baseline "$dirty_full" "" "2026-11-22" +run "empty reason exits 2" 2 --print-baseline +expect "empty reason message" "reason is empty" + +write_baseline "$dirty_full" "accepted historical test fixture" "22-11-2026" +run "bad decided date exits 2" 2 --print-baseline +expect "bad decided message" "YYYY-MM-DD" + +printf '%s\n' "reason: accepted historical test fixture" "decided: 2026-11-22" > "$REPO/.privacy-baseline" +run "missing sha exits 2" 2 --print-baseline +expect "missing sha message" "must set sha, reason, and decided" + +write_baseline "not-a-sha" "accepted historical test fixture" "2026-11-22" +run "malformed sha exits 2" 2 --print-baseline +expect "malformed sha message" "not a git SHA" + +write_baseline "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "accepted historical test fixture" "2026-11-22" +run "unresolved sha exits 2" 2 --print-baseline +expect "unresolved sha message" "does not resolve to a commit" + +write_baseline "$dirty_full" "accepted historical test fixture" "2026-11-22" +printf '%s\n' "sha: $dirty_full" >> "$REPO/.privacy-baseline" +run "duplicate key exits 2" 2 --print-baseline +expect "duplicate key message" "duplicate key" + +printf '%s\n' "sha: $dirty_full" "reason: accepted historical test fixture" "decided: 2026-11-22" "owner: nobody" > "$REPO/.privacy-baseline" +run "unknown key exits 2" 2 --print-baseline +expect "unknown key message" "unknown key" + +# A present but invalid baseline must fail even with --all, so CI cannot +# skip validation by setting a range. +printf '%s\n' "sha: not-a-sha" "reason: accepted historical test fixture" "decided: 2026-11-22" > "$REPO/.privacy-baseline" +run "invalid baseline fails with --all" 2 --all +expect "invalid with --all message" "not a git SHA" + +# 20. --baseline-file can point at an alternate path. +rm -f "$REPO/.privacy-baseline" +write_baseline "$dirty_full" "accepted historical test fixture" "2026-11-22" "$REPO/.other-baseline" +run "alternate baseline file prints sha" 0 --print-baseline --baseline-file .other-baseline +if [[ "$LAST_OUTPUT" != "$dirty_full" ]]; then + printf 'FAIL alternate baseline file prints sha: expected the baseline sha only\n' >&2 + failures=$((failures + 1)) +fi +# Without --baseline-file, the default path is absent again, so this is --all +# over dirty history and must fail. +run "missing default baseline falls back to all" 1 +expect "fallback fail line" "FAIL commit metadata" + if [[ "$failures" -ne 0 ]]; then echo "FAILED $failures test(s)" >&2 exit 1