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
5 changes: 5 additions & 0 deletions .github/post-pin-bump.paths
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-License-Identifier: MPL-2.0
# Paths scripts/post-pin-bump.sh may change, one per line. The Action pins applier
# stages exactly these (and nothing else) after running the hook.
scripts/lib/pinned-reusable-sources.json
scripts/lib/lock-closure-receipts.tsv
2 changes: 2 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ jobs:
run: printf 'PINNED_SOURCE_CACHE=%s/fleet-pinned-sources\n' "$RUNNER_TEMP" >> "$GITHUB_ENV"
- name: Test pinned-source failure modes
run: bash scripts/tests/pinned-reusable-sources-test.sh
- name: Test the post-pin-bump hook
run: bash scripts/tests/post-pin-bump-test.sh
- name: Authenticate pinned reusable sources
run: bash scripts/audit-pinned-reusable-sources.sh --fetch-sources
- name: Verify live scanner caller and negative controls
Expand Down
1 change: 0 additions & 1 deletion .machine_readable/departures.jsonl
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
{"added":"2026-11-22","blocked_on":"upstream serenity/poise/sqlx still depend; replace with jiff/time when they move","checks":[{"kind":"grep-present","path":"bots/gsbot/Cargo.lock","pattern":"^name = \"chrono\"$"}],"claim":"RUSTSEC-2026-0543: chrono 0.4.44 is unmaintained (all versions affected, no safe upgrade). bots/gsbot/Cargo.lock still resolves it, via gsbot itself and via serenity, poise and sqlx. The GSBot dependency audit runs with --warn unmaintained, so this is reported as a warning and does not fail the audit.","fix":"blocked","id":"gsbot-rustsec-2026-0543-chrono","repo":"hyperpolymath/gitbot-fleet","ruling":"bots/gsbot/deny.toml: no vulnerability advisories are ignored; the GSBot dependency audit in .github/workflows/rust.yml must pass"}
{"added":"2026-11-22","blocked_on":"upstream poise still depends on derivative; clears when poise removes it or replaces it with a maintained derive crate","checks":[{"kind":"grep-present","path":"bots/gsbot/Cargo.lock","pattern":"^name = \"derivative\"$"}],"claim":"RUSTSEC-2024-0388: derivative 2.2.0 is unmaintained (no safe upgrade). bots/gsbot/Cargo.lock still resolves it, via poise 0.6.2. The GSBot dependency audit runs with --warn unmaintained, so this is reported as a warning and does not fail the audit.","fix":"blocked","id":"gsbot-rustsec-2024-0388-derivative","repo":"hyperpolymath/gitbot-fleet","ruling":"bots/gsbot/deny.toml: no vulnerability advisories are ignored; the GSBot dependency audit in .github/workflows/rust.yml must pass"}
{"added":"2026-11-26","blocked_on":"gitbot-fleet #717 (scripts/post-pin-bump.sh) lands, after the standards applier hook contract (part A); merge order A, then #717. Clears when scripts/post-pin-bump.sh exists on main.","checks":[{"kind":"path-absent","path":"scripts/post-pin-bump.sh"}],"claim":"The applier writes only .github/workflows and .github/actions and skips first-party owners, so when it moves a pinned reusable-workflow commit, scripts/lib/pinned-reusable-sources.json and scripts/lib/lock-closure-receipts.tsv are not updated and Pinned source closure goes red on main (as with #699). The repo hook scripts/post-pin-bump.sh (#717) re-attests the pin-only case, but it is not on main, so the gap is open.","fix":"blocked","id":"applier-bump-closure-gap","repo":"hyperpolymath/gitbot-fleet","ruling":"Owner ruling \"single pin writer\" (2026-11-26): the standards Action pins applier is the only writer of third-party action pins and actions.lock; Dependabot github-actions is off (#716)."}
14 changes: 12 additions & 2 deletions scripts/audit-pinned-reusable-sources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
MANIFEST=""; LOCK=""; RECEIPTS=""; CACHE="${PINNED_SOURCE_CACHE:-${XDG_CACHE_HOME:-${HOME:-/tmp}/.cache}/fleet-pinned-sources}"
FETCH=0; JSON=0
FETCH=0; JSON=0; ROOTS_ONLY=0
while [[ "$#" -gt 0 ]]; do
case "$1" in
--manifest|--source-manifest) MANIFEST="${2:?manifest file required}"; shift ;;
Expand All @@ -17,7 +17,8 @@ while [[ "$#" -gt 0 ]]; do
--cache|--source-cache) CACHE="${2:?cache directory required}"; shift ;;
--fetch-sources) FETCH=1 ;;
--json) JSON=1 ;;
-h|--help) printf '%s\n' 'Usage: audit-pinned-reusable-sources.sh [--manifest FILE] [--repo-root DIR] [--lock FILE] [--receipts FILE] [--cache DIR] [--fetch-sources] [--json]'; exit 0 ;;
--roots-only) ROOTS_ONLY=1 ;;
-h|--help) printf '%s\n' 'Usage: audit-pinned-reusable-sources.sh [--manifest FILE] [--repo-root DIR] [--lock FILE] [--receipts FILE] [--cache DIR] [--fetch-sources] [--json] [--roots-only]'; exit 0 ;;
*) printf 'Unknown argument: %s\n' "$1" >&2; exit 64 ;;
esac
shift
Expand Down Expand Up @@ -179,6 +180,15 @@ for workflow in "$ROOT"/.github/workflows/*.yml "$ROOT"/.github/workflows/*.yaml
done
shopt -u nullglob
jq -s 'sort_by(.workflow,.job)' "$TMP/roots" > "$TMP/actual-roots.json"
if [[ "$ROOTS_ONLY" -eq 1 ]]; then
# Print the live remote-reusable roots (workflow, job, repository, path,
# commit) and stop: no source is fetched and nothing is compared. Used by
# scripts/post-pin-bump.sh to learn which pins a bump moved.
if [[ -s "$TMP/findings" ]] || [[ -s "$TMP/notrun" ]]; then
jq -r '"\(.rule)\t\(.subject)\t\(.detail)"' "$TMP/findings" "$TMP/notrun" >&2; exit 1
fi
cat "$TMP/actual-roots.json"; exit 0
fi
jq '[.sources[]|select(.role=="active")|. as $s|.callers[]|{workflow,job,repository:($s.repository|ascii_downcase),path:$s.path,commit:$s.commit}]|sort_by(.workflow,.job)' "$MANIFEST" > "$TMP/expected-roots.json"
if ! cmp -s "$TMP/actual-roots.json" "$TMP/expected-roots.json"; then
finding SOURCE-ACTIVE-MISSING "$MANIFEST" 'Active caller/job/path/commit bindings differ from the actual workflow roots (historical paths cannot satisfy active calls)'
Expand Down
211 changes: 211 additions & 0 deletions scripts/post-pin-bump.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: MPL-2.0
# SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell <jonathan.jewell@open.ac.uk>
#
# Post-pin-bump hook: the repo's half of the "single pin writer" contract.
#
# The Action pins applier (metadatastician/standards) moves third-party
# `uses:` SHAs and actions.lock. It cannot write scripts/lib/*, and it skips
# first-party owners, so a bump of a pinned reusable-workflow commit leaves the
# source closure files (the manifest and the receipts) describing the old
# commit and main goes red. This hook re-attests the PIN-ONLY case and refuses
# everything else:
#
# * a pin-only bump means the caller's reusable workflow now points at a new
# commit of the SAME repository and path, and the workflow file there is
# byte-identical (same blob, same content_sha256, same direct edges);
# * anything else (another blob, another repository or path, a commit shared
# with a source that did not move, edges that changed, unreadable input) is
# refused with a non-zero exit and NO file is changed. A human reviews it.
#
# New source is fetched as DATA over git by scripts/audit-pinned-reusable-sources.sh
# into its isolated bare cache and is never checked out or executed.
#
# Output: the paths the hook changed, NUL-separated, on stdout (nothing when no
# pin moved). Messages go to stderr. Exit 0 = nothing to do or re-attested,
# 1 = refused or self-audit failed (files restored), 64 = usage.
#
# Fetching new source is on when POST_PIN_BUMP=1 (set by the applier) or with
# --fetch-sources; otherwise the hook is offline and reads only the cache.
#
# Usage: post-pin-bump.sh [--repo-root DIR] [--cache DIR] [--fetch-sources]
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
CACHE="${PINNED_SOURCE_CACHE:-${XDG_CACHE_HOME:-${HOME:-/tmp}/.cache}/fleet-pinned-sources}"
# The Action pins applier runs this hook with no arguments and POST_PIN_BUMP=1 (the
# contract in metadatastician/standards), so that variable also turns fetching on.
FETCH=0
[[ "${POST_PIN_BUMP:-}" != 1 ]] || FETCH=1
while [[ "$#" -gt 0 ]]; do
case "$1" in
--repo-root) ROOT="${2:?repository root required}"; shift ;;
--cache) CACHE="${2:?cache directory required}"; shift ;;
--fetch-sources) FETCH=1 ;;
-h|--help) printf '%s\n' 'Usage: post-pin-bump.sh [--repo-root DIR] [--cache DIR] [--fetch-sources]'; exit 0 ;;
*) printf 'post-pin-bump: unknown argument: %s\n' "$1" >&2; exit 64 ;;
esac
shift
done
ROOT="$(cd "$ROOT" && pwd)"
for tool in git jq awk sha256sum cmp; do
command -v "$tool" >/dev/null || { printf 'post-pin-bump: missing prerequisite: %s\n' "$tool" >&2; exit 2; }
done

AUDIT="$SCRIPT_DIR/audit-pinned-reusable-sources.sh"
MANIFEST_REL='scripts/lib/pinned-reusable-sources.json'
RECEIPTS_REL='scripts/lib/lock-closure-receipts.tsv'
ALLOW="$ROOT/.github/post-pin-bump.paths"
MANIFEST="$ROOT/$MANIFEST_REL"
RECEIPTS="$ROOT/$RECEIPTS_REL"

TMP="$(mktemp -d "${TMPDIR:-/tmp}/post-pin-bump.XXXXXX")"
trap 'rm -rf "$TMP"' EXIT
refuse() { printf 'post-pin-bump: REFUSED: %s\n' "$*" >&2; exit 1; }

[[ -f "$ALLOW" ]] || refuse "missing allow-list $ALLOW"
[[ -f "$MANIFEST" && -f "$RECEIPTS" ]] || refuse 'closure manifest or receipts missing'
[[ -x "$AUDIT" || -f "$AUDIT" ]] || refuse 'audit script missing'

audit_args=(--repo-root "$ROOT" --cache "$CACHE")
[[ "$FETCH" -eq 0 ]] || audit_args+=(--fetch-sources)

# 1. The live remote-reusable roots, read by the audit's own parser. Anything
# the parser cannot read stops here.
bash "$AUDIT" --repo-root "$ROOT" --roots-only > "$TMP/roots.json" 2> "$TMP/roots.err" ||
refuse "workflow roots unreadable: $(tr '\n' ' ' < "$TMP/roots.err")"

# 2. Which active sources moved? One (index, old, new) per moved source.
jq -rn --slurpfile roots "$TMP/roots.json" --slurpfile m "$MANIFEST" '
$m[0].sources as $src | $roots[0] as $actual |
[ range(0; $src|length) as $i | $src[$i] | select(.role=="active") as $s |
($s.callers | map(. as $c | ($actual | map(select(.workflow==$c.workflow and .job==$c.job)))[0])) as $found |
if ($found|any(.==null)) then "ERR\t\($s.repository)@\($s.commit)\tcaller no longer present in the workflows"
elif ($found|any((.repository != ($s.repository|ascii_downcase)) or .path != $s.path)) then "ERR\t\($s.repository)@\($s.commit)\trepository or path of a caller changed (not pin-only)"
elif ($found|map(.commit)|unique|length) != 1 then "ERR\t\($s.repository)@\($s.commit)\tcallers disagree on the commit"
elif $found[0].commit != $s.commit then "BUMP\t\($i)\t\($s.commit)\t\($found[0].commit)"
else empty end ] | .[]' > "$TMP/plan.tsv"

if grep -q '^ERR' "$TMP/plan.tsv"; then refuse "$(grep '^ERR' "$TMP/plan.tsv" | tr '\t' ' ' | tr '\n' ';')"; fi
if [[ ! -s "$TMP/plan.tsv" ]]; then exit 0; fi

# 3. Rewrite into temporary copies, never into the tree.
cp "$MANIFEST" "$TMP/manifest.json"
cp "$RECEIPTS" "$TMP/receipts.tsv"
# Plan rows grouped by (repository, old commit): sources that share an old commit
# and ALL move together to the same new commit are one group and are rewritten
# once. A sharer that stays put, or members moving to different targets, is refused.
: > "$TMP/members.tsv"
while IFS=$'\t' read -r _ idx old new; do
[[ "$idx" =~ ^[0-9]+$ && "$old" =~ ^[0-9a-f]{40}$ && "$new" =~ ^[0-9a-f]{40}$ ]] || refuse 'malformed plan row'
jq -r --argjson i "$idx" --arg old "$old" --arg new "$new" \
'[(.sources[$i].repository|ascii_downcase), $old, $new, ($i|tostring)] | @tsv' "$TMP/manifest.json" >> "$TMP/members.tsv"
done < <(grep '^BUMP' "$TMP/plan.tsv")
# Chained or overlapping moves (A->B with B->C, or a swap) make the result depend on
# the order the rewrites run in; refuse them before any rewrite, whatever the order.
chained="$(awk -F'\t' '{ old[$1 FS $2] = 1; nw[$1 FS $3] = 1 } END { for (k in nw) if (k in old) { split(k, a, FS); print a[1] } }' "$TMP/members.tsv" | LC_ALL=C sort -u | tr '\n' ' ')"
[[ -z "$chained" ]] || refuse "chained or overlapping pin moves for ${chained% }; review by hand"
# A lock record still resolving to repo@old would lose its receipt rows when they move
# to the new commit (the full audit reports CLOSURE-NO-RECEIPT), so it must be bumped
# too: refuse rather than leave the lock pointing at a commit without receipts.
bash "$SCRIPT_DIR/audit-lock-closure.sh" --dump-lock-records --lock "$ROOT/.github/workflows/actions.lock" \
--workflows "$ROOT/.github/workflows" --repo-root "$ROOT" --receipts "$RECEIPTS" --baseline /dev/null > "$TMP/lockrecs.json" 2> "$TMP/lockrecs.err" ||
refuse "lock records unreadable: $(tr '\n' ' ' < "$TMP/lockrecs.err" | cut -c1-300)"
while IFS=$'\t' read -r repo old; do
if jq -e --arg k "$repo@$old" '[(keys[], (.[] | .uses[]?)) | ascii_downcase | select(. == $k)] | length > 0' "$TMP/lockrecs.json" >/dev/null; then
refuse "actions.lock still resolves $repo@$old; bump the lock record too, or review by hand"
fi
done < <(cut -f1,2 "$TMP/members.tsv" | LC_ALL=C sort -u)
while IFS=$'\t' read -r repo old; do
targets="$(awk -F'\t' -v r="$repo" -v o="$old" '$1==r && $2==o {print $3}' "$TMP/members.tsv" | LC_ALL=C sort -u)"
[[ "$(printf '%s\n' "$targets" | wc -l)" -eq 1 ]] ||
refuse "$repo@$old moves to conflicting commits ($(printf '%s' "$targets" | tr '\n' ' ')); review by hand"
new="$targets"
idxs="$(awk -F'\t' -v r="$repo" -v o="$old" '$1==r && $2==o {print $4}' "$TMP/members.tsv" | paste -sd, -)"
# Receipt rows and the comment cover every source of repo@old: a commit shared
# with a source outside this bump plan cannot be re-pointed by guessing.
shared="$(jq -r --arg r "$repo" --arg c "$old" --argjson ids "[$idxs]" \
'[.sources|to_entries[]|select((.key as $k | $ids|index($k)|not) and (.value.repository|ascii_downcase)==$r and .value.commit==$c)]|length' "$MANIFEST")"
[[ "$shared" -eq 0 ]] || refuse "$repo@$old is shared with $shared other source(s) that did not move; review by hand"
# Re-point each member's commit and its recognised provenance fields (source_url,
# local_file), by literal split/join. Any other mention of $old is refused below.
jq --argjson ids "[$idxs]" --arg old "$old" --arg new "$new" '
def swap: if type=="string" then split($old)|join($new) else . end;
reduce $ids[] as $i (.; .sources[$i] |= (.commit=$new | (if has("source_url") then .source_url|=swap else . end) | (if has("local_file") then .local_file|=swap else . end)))' \
"$TMP/manifest.json" > "$TMP/manifest.next"
mv "$TMP/manifest.next" "$TMP/manifest.json"
# Receipts: rows "repo<TAB>old<TAB>..." and "# Reviewed source: ...repo/...@old" lines,
# literal matching only (no regex on data).
awk -F'\t' -v OFS='\t' -v repo="${repo,,}" -v old="$old" -v new="$new" '
BEGIN { tag = "# Reviewed source: " }
substr($0, 1, length(tag)) == tag {
i = index(tolower($0), repo "/")
if (i > 0) { j = index($0, "@" old); if (j > 0 && j > i) $0 = substr($0, 1, j) new substr($0, j + 1 + length(old)) }
print; next
}
$0 !~ /^#/ && tolower($1) == repo && $2 == old { $2 = new }
Comment thread
hyperpolymath marked this conversation as resolved.
Resolved
{ print }' "$TMP/receipts.tsv" > "$TMP/receipts.next"
mv "$TMP/receipts.next" "$TMP/receipts.tsv"
if grep -qF "$old" "$TMP/receipts.tsv"; then
# The only tolerated mention is prose in the header comment block.
grep -F "$old" "$TMP/receipts.tsv" | grep -qv '^#' && refuse "receipts still name $old after the rewrite"
fi
# Any other mention of the old commit in the manifest, in a value or an object key (e.g. dependency keys), is
# something this hook did not review.
if jq -e --arg c "$old" '[.. | (strings, (objects | keys[])) | select(contains($c))] | length > 0' "$TMP/manifest.json" >/dev/null; then
refuse "manifest still names $old after the rewrite (dependency records); review by hand"
fi
done < <(cut -f1,2 "$TMP/members.tsv" | LC_ALL=C sort -u)

# 4. The audit is the authority: with the rewritten copies it must find, at the
# NEW commit, the same blob (a fetched blob mismatch is a FATAL finding) and
# the same direct edges, with every receipt consistent. Not-run is a refusal.
if ! bash "$AUDIT" "${audit_args[@]}" --manifest "$TMP/manifest.json" --receipts "$TMP/receipts.tsv" > "$TMP/audit.out" 2>&1; then
refuse "the new commit does not re-attest as pin-only: $(tr '\n' ' ' < "$TMP/audit.out" | cut -c1-600)"
fi

# 5. content_sha256, from the cached object the audit just verified by hash.
while IFS=$'\t' read -r _ idx _ new; do
want="$(jq -r --argjson i "$idx" '.sources[$i].content_sha256 // empty' "$TMP/manifest.json")"
[[ -n "$want" ]] || continue
repo="$(jq -r --argjson i "$idx" '.sources[$i].repository|ascii_downcase' "$TMP/manifest.json")"
blob="$(jq -r --argjson i "$idx" '.sources[$i].blob' "$TMP/manifest.json")"
got="$(env GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_NOSYSTEM=1 git --no-replace-objects --git-dir "$CACHE/$repo.git" cat-file blob "$blob" | sha256sum | cut -d' ' -f1)" ||
refuse "cannot read verified blob $blob of $repo@$new"
[[ "$got" = "$want" ]] || refuse "content_sha256 of $repo@$new differs from the manifest"
done < <(grep '^BUMP' "$TMP/plan.tsv")

# 6. Only the allow-listed paths may change.
: > "$TMP/changed"
cmp -s "$MANIFEST" "$TMP/manifest.json" || printf '%s\n' "$MANIFEST_REL" >> "$TMP/changed"
cmp -s "$RECEIPTS" "$TMP/receipts.tsv" || printf '%s\n' "$RECEIPTS_REL" >> "$TMP/changed"
while IFS= read -r p; do
grep -qxF -- "$p" "$ALLOW" || refuse "$p is not in .github/post-pin-bump.paths"
done < "$TMP/changed"

# 7. Install, self-audit the real tree. Any failure (a write that stops half way, or
# a failed self-audit) restores BOTH files, so the pair never describes different commits.
cp -p "$MANIFEST" "$TMP/manifest.orig"; cp -p "$RECEIPTS" "$TMP/receipts.orig"
restore() {
# Attempt BOTH restores independently: a failed first one must not skip the second.
local failed=0 keep
cat "$TMP/manifest.orig" > "$MANIFEST" || failed=1
cat "$TMP/receipts.orig" > "$RECEIPTS" || failed=1
[[ "$failed" -eq 1 ]] || return 0
# $TMP is deleted on exit, so keep the originals somewhere that survives it. If
# that copy fails too, disarm the deletion and leave them in $TMP itself.
if keep="$(mktemp -d "${TMPDIR:-/tmp}/post-pin-bump-backup.XXXXXX")" && cp -p "$TMP/manifest.orig" "$TMP/receipts.orig" "$keep/"; then
refuse "cannot restore the closure files after a failed install; originals kept in $keep (restore from there or from git)"
fi
trap - EXIT
refuse "cannot restore the closure files after a failed install; originals kept in $TMP (copy to a separate backup dir failed; restore from there or from git)"
}
if ! { cat "$TMP/manifest.json" > "$MANIFEST" && cat "$TMP/receipts.tsv" > "$RECEIPTS"; }; then
restore; refuse 'writing the closure files failed (files restored)'
fi
if ! bash "$AUDIT" "${audit_args[@]}" > "$TMP/final.out" 2>&1; then
restore
refuse "self-audit failed after the rewrite (files restored): $(tr '\n' ' ' < "$TMP/final.out" | cut -c1-600)"
fi
while IFS= read -r p; do printf '%s\0' "$p"; done < "$TMP/changed"
Loading
Loading