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
40 changes: 39 additions & 1 deletion .github/workflows/privacy-guard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,45 @@ jobs:
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: bash scripts/privacy-denylist.sh
run: |
set -euo pipefail
# Tracked denylist must always run. If the optional CI secret has invalid
# git-grep regexes, warn and continue without it so PRs are not blocked
# while the secret is repaired (same failure mode as an empty secret).
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
env:
EVENT_NAME: ${{ github.event_name }}
PR_BASE: ${{ github.event.pull_request.base.sha }}
PR_HEAD: ${{ github.event.pull_request.head.sha }}
BEFORE: ${{ github.event.before }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
REF_NAME: ${{ github.ref_name }}
run: |
set -euo pipefail
if [[ "$EVENT_NAME" == "pull_request" ]]; then
export PRIVACY_COMMIT_RANGE="${PR_BASE}..${PR_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
export PRIVACY_COMMIT_RANGE="--all"
fi
bash scripts/check-commit-emails.sh
1 change: 1 addition & 0 deletions .privacy-allowlist
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:[0-9]+:[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+\.(test|invalid|example)$
:[0-9]+:[A-Za-z0-9._%+-]+@example\.(com|org|net)$
:[0-9]+:[A-Za-z0-9._%+-]+@users\.noreply\.github\.com$
:[0-9]+:noreply@github\.com$
:[0-9]+:git@github\.com$

# CI runner home directories
Expand Down
5 changes: 5 additions & 0 deletions .privacy-denylist
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
\b100\.(6[4-9]|[7-9][0-9]|1[01][0-9]|12[0-7])\.[0-9]{1,3}\.[0-9]{1,3}\b
\bfd7a:115c:a1e0:[0-9a-f:]+

# Provider-assigned VPS hostnames (not the vendor name itself)
[a-z0-9-]+\.vps\.ovh\.(net|ca)\b
[a-z0-9.-]+\.your-server\.de\b
[a-z0-9-]+\.hetzner\.cloud\b

# Private network addresses
\b10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\b
\b192\.168\.[0-9]{1,3}\.[0-9]{1,3}\b
Expand Down
187 changes: 187 additions & 0 deletions scripts/check-commit-emails.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
#!/usr/bin/env bash
#
# check-commit-emails.sh — fail when a commit in the scan range uses a
# disallowed author, committer, Co-authored-by, or Signed-off-by email,
# or when commit metadata contains a private hostname or internal IP.
#
# Matched values are never printed. Findings are reported as
# <short-sha> <field> <category>
# only. Public CI logs are public.
#
# Range (first match wins):
# $PRIVACY_COMMIT_RANGE a git revision range, or the token --all
# --range <rev> | --all command-line flags
# otherwise --all
#
# Allowed emails (override with $ALLOWED_EMAIL_PATTERN):
# *@users.noreply.github.com and noreply@github.com
#
# Exit codes: 0 clean, 1 finding, 2 misuse.

set -u

cd "$(git rev-parse --show-toplevel)" || exit 2

ALLOWED_EMAIL_PATTERN="${ALLOWED_EMAIL_PATTERN:-(@users\.noreply\.github\.com|^noreply@github\.com)$}"

# Hostname and address patterns, assembled from fragments so this file does
# not itself match a tree denylist. Keep them generic: no personal names.
TS_NET='[a-z0-9-]+\.ts''\.net\b'
OVH_VPS='[a-z0-9-]+\.vps\.ovh''\.net\b'
OVH_VPS_CA='[a-z0-9-]+\.vps\.ovh''\.ca\b'
HETZNER_DED='[a-z0-9.-]+\.your-server''\.de\b'
HETZNER_CLOUD='[a-z0-9-]+\.hetzner''\.cloud\b'
# Tailnet CGNAT (100.64/10) and RFC1918
CGNAT='\b100\.(6[4-9]|[7-9][0-9]|1[01][0-9]|12[0-7])\.[0-9]{1,3}\.[0-9]{1,3}\b'
RFC10='\b10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\b'
RFC192='\b192\.168\.[0-9]{1,3}\.[0-9]{1,3}\b'
RFC172='\b172\.(1[6-9]|2[0-9]|3[01])\.[0-9]{1,3}\.[0-9]{1,3}\b'

HOSTNAME_PATTERN="${TS_NET}|${OVH_VPS}|${OVH_VPS_CA}|${HETZNER_DED}|${HETZNER_CLOUD}"
IP_PATTERN="${CGNAT}|${RFC10}|${RFC192}|${RFC172}"

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

RANGE="${PRIVACY_COMMIT_RANGE:-}"
while [[ $# -gt 0 ]]; do
case "$1" in
--all) RANGE="--all"; shift ;;
--range)
[[ $# -ge 2 ]] || usage
RANGE="$2"
shift 2
;;
-h|--help) usage ;;
*) usage ;;
esac
done
[[ -n "$RANGE" ]] || RANGE="--all"

# Validate the allowed-email pattern without printing it.
if ! printf 'a@users.noreply.github.com\n' | grep -qE "$ALLOWED_EMAIL_PATTERN"; then
echo "error: ALLOWED_EMAIL_PATTERN does not accept a GitHub noreply address" >&2
exit 2
fi
if ! printf 'noreply@github.com\n' | grep -qE "$ALLOWED_EMAIL_PATTERN"; then
echo "error: ALLOWED_EMAIL_PATTERN does not accept noreply@github.com" >&2
exit 2
fi

# Resolve the commit list. An empty range (no new commits) is clean.
commits="$(mktemp)"
findings="$(mktemp)"
trap 'rm -f "$commits" "$findings"' EXIT

if [[ "$RANGE" == "--all" ]]; then
if ! git rev-list --all > "$commits" 2>/dev/null; then
echo "error: could not list commits for --all" >&2
exit 2
fi
else
if ! git rev-list "$RANGE" > "$commits" 2>/dev/null; then
echo "error: invalid commit range" >&2
exit 2
fi
fi

if [[ ! -s "$commits" ]]; then
echo "OK commit metadata: no commits in range"
exit 0
fi

# classify_email <addr> -> category (or empty if allowed)
classify_email() {
local addr="$1"
[[ -n "$addr" ]] || return 0
if printf '%s\n' "$addr" | grep -qE "$ALLOWED_EMAIL_PATTERN"; then
return 0
fi
if printf '%s\n' "$addr" | grep -qiE "$HOSTNAME_PATTERN"; then
echo "private-hostname"
return 0
fi
if printf '%s\n' "$addr" | grep -qiE "$IP_PATTERN"; then
echo "private-ip"
return 0
fi
echo "disallowed-email"
}

# classify_text <text> -> category (or empty)
classify_text() {
local text="$1"
[[ -n "$text" ]] || return 0
if printf '%s\n' "$text" | grep -qiE "$HOSTNAME_PATTERN"; then
echo "private-hostname"
return 0
fi
if printf '%s\n' "$text" | grep -qiE "$IP_PATTERN"; then
echo "private-ip"
return 0
fi
}

# extract_trailer_email <line> — Co-authored-by / Signed-off-by "Name <email>"
extract_trailer_email() {
local line="$1" addr
addr="$(printf '%s\n' "$line" | sed -n 's/.*<\([^>]*\)>.*/\1/p')"
printf '%s\n' "$addr"
}

while IFS= read -r sha || [[ -n "$sha" ]]; do
[[ -n "$sha" ]] || continue
short="$(git rev-parse --short "$sha")"
author="$(git log -1 --format='%ae' "$sha")"
committer="$(git log -1 --format='%ce' "$sha")"
subject="$(git log -1 --format='%s' "$sha")"
body="$(git log -1 --format='%b' "$sha")"

catg="$(classify_email "$author")"
[[ -n "$catg" ]] && printf '%s\tauthor\t%s\n' "$short" "$catg" >> "$findings"
catg="$(classify_email "$committer")"
[[ -n "$catg" ]] && printf '%s\tcommitter\t%s\n' "$short" "$catg" >> "$findings"

# Trailers only (unfolded). Do not treat the whole body as trailers.
trailers="$(git log -1 --format='%(trailers:only,unfold)' "$sha")"
while IFS= read -r tline || [[ -n "$tline" ]]; do
[[ -n "$tline" ]] || continue
key="$(printf '%s\n' "$tline" | sed -n 's/^\([^:]*\):.*/\1/p' | tr '[:upper:]' '[:lower:]')"
case "$key" in
co-authored-by|signed-off-by)
addr="$(extract_trailer_email "$tline")"
catg="$(classify_email "$addr")"
field="Co-authored-by"
[[ "$key" == "signed-off-by" ]] && field="Signed-off-by"
[[ -n "$catg" ]] && printf '%s\t%s\t%s\n' "$short" "$field" "$catg" >> "$findings"
;;
esac
done <<< "$trailers"

# Subject and body (including non-trailer text) for hostnames and internal IPs.
# Email addresses in the message body that are not trailers are not classified
# here; author/committer/trailer checks cover the metadata leak path.
catg="$(classify_text "$subject")"
[[ -n "$catg" ]] && printf '%s\tmessage\t%s\n' "$short" "$catg" >> "$findings"
# Skip re-reporting the same category already found in the subject.
body_catg="$(classify_text "$body")"
if [[ -n "$body_catg" && "$body_catg" != "$catg" ]]; then
printf '%s\tmessage\t%s\n' "$short" "$body_catg" >> "$findings"
elif [[ -n "$body_catg" && -z "$catg" ]]; then
printf '%s\tmessage\t%s\n' "$short" "$body_catg" >> "$findings"
fi
done < "$commits"

if [[ -s "$findings" ]]; then
count="$(wc -l < "$findings" | tr -d ' ')"
echo "FAIL commit metadata: $count finding(s); values withheld"
# field may contain a hyphen; columns are tab-separated
sort -u "$findings" | awk -F '\t' '{printf " %s %s %s\n", $1, $2, $3}'
exit 1
fi

n="$(wc -l < "$commits" | tr -d ' ')"
echo "OK commit metadata: $n commit(s) in range, no findings"
exit 0
Loading
Loading