Skip to content

Commit fca4977

Browse files
committed
fix(ci): reject hidden source state before native qualification
Normal git status can conceal a modified consumed helper or workflow behind assume-unchanged/skip-worktree flags. Refuse these flags and tracked, untracked or ignored changes in both exact repository roots. Require a completed native 0/1 receipt before accepting the unchanged canonical helper. Add actual Git fixture controls for both hidden flags in both checkouts and an ignored action.yml shadowing a tracked action.yaml. The new shell syntax passes bash -n; execution of the expanded suite is pending hosted CI with the official native binary and YAML parser. Do not transfer earlier runtime receipts to these source bytes. No native lock or refs are changed.
1 parent 2e1cdeb commit fca4977

3 files changed

Lines changed: 86 additions & 6 deletions

File tree

‎.githooks/validate-actions-lock.sh‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,25 @@
55
# boundary. No native YAML is generated, patched, or inferred here.
66
set -euo pipefail
77

8-
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
8+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
9+
assert_clean_checkout() {
10+
local checkout=$1 git_state
11+
# Git's normal status can hide modified consumed files behind these flags.
12+
# NUL records keep unusual filenames from changing the flag interpretation.
13+
git -C "$checkout" ls-files -v -z |
14+
while IFS= read -r -d '' entry; do
15+
case "${entry:0:1}" in
16+
[a-z]|S)
17+
echo "validate-actions-lock: unsafe index flags in $checkout; source bytes are unqualified" >&2
18+
exit 2
19+
;;
20+
esac
21+
done
22+
git_state="$(git -C "$checkout" status --porcelain --untracked-files=all --ignored=matching)" ||
23+
{ echo "validate-actions-lock: cannot inspect source state in $checkout" >&2; return 2; }
24+
[[ -z "$git_state" ]] ||
25+
{ echo "validate-actions-lock: tracked, untracked or ignored changes in $checkout; use an isolated clean checkout" >&2; return 2; }
26+
}
927
STANDARDS_REF=087f6bff5135ce3da6f287c83752256ce4a8efc1
1028
NATIVE_SHA256=79ec84c191667fd935a277e6fd3662cf5d3669cccc9e99998731d8f306f373b6
1129
: "${STANDARDS_ROOT:?checkout the pinned metadatastician/standards source; see docs/CI-CD.adoc}"
@@ -22,12 +40,12 @@ STANDARDS_ROOT="$(cd "$STANDARDS_ROOT" && pwd -P)"
2240
{ echo 'validate-actions-lock: Standards path must be its repository root' >&2; exit 2; }
2341
[[ "$(git -C "$STANDARDS_ROOT" rev-parse HEAD)" = "$STANDARDS_REF" ]] ||
2442
{ echo 'validate-actions-lock: wrong Standards source revision' >&2; exit 2; }
25-
[[ -z "$(git -C "$STANDARDS_ROOT" status --porcelain --untracked-files=all)" ]] ||
26-
{ echo 'validate-actions-lock: Standards checkout is not clean' >&2; exit 2; }
43+
assert_clean_checkout "$STANDARDS_ROOT"
2744

2845
cd "$ROOT"
29-
[[ -z "$(git status --porcelain --untracked-files=all)" ]] ||
30-
{ echo 'validate-actions-lock: commit the exact input tree before qualification' >&2; exit 2; }
46+
[[ "$(git rev-parse --show-toplevel)" = "$ROOT" ]] ||
47+
{ echo 'validate-actions-lock: consumer path must be its repository root' >&2; exit 2; }
48+
assert_clean_checkout "$ROOT"
3149
[[ -f .github/workflows/actions.lock ]] ||
3250
{ echo 'validate-actions-lock: missing native lock; use canonical recovery' >&2; exit 1; }
3351
snapshot="$(mktemp -d)"
@@ -63,4 +81,11 @@ jq -n \
6381

6482
GH_BIN="$ROOT/scripts/ci/actions-lock-transport.sh" \
6583
bash "$STANDARDS_ROOT/scripts/update-actions-lock.sh" --verify-local
84+
case "$(cat "$ACTIONS_LOCK_EVIDENCE_DIR/native.exit")" in
85+
0|1) ;;
86+
*)
87+
echo 'validate-actions-lock: helper returned without a completed native verifier result' >&2
88+
exit 1
89+
;;
90+
esac
6691
bash "$STANDARDS_ROOT/scripts/check-lock-sync.sh" .github/workflows

‎docs/CI-CD.adoc‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ official `gh-actions-lock v0.2.0` binary through the unchanged published
106106
`scripts/check-lock-sync.sh`. The latter checks reusable and local composite
107107
references in both directions. No consumer code emits native lock records.
108108
The gate checks the native executable digest, the exact clean Standards
109-
checkout, a clean consumer commit, and unchanged workflow/lock bytes.
109+
checkout, a clean consumer commit, and unchanged workflow/lock bytes. Both
110+
checkouts reject assume-unchanged/skip-worktree index flags and ignored inputs;
111+
Git status alone cannot bind hidden working bytes to the recorded commit.
110112

111113
Tree allowlist:: `scripts/ci/check-allowed-actions.sh` parses YAML, resolves
112114
aliases, and reads job/step `uses` values. Owner/repository spelling is

‎scripts/ci/test-ci-integrity.sh‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,59 @@ expect 2 'multiple JSON policies cannot be combined implicitly' bash "$checker"
111111
printf '%s\n' '{"github_owned_allowed":false,"patterns_allowed":["fixture/action@*\nevil/*"]}' > "$work/newline-policy.json"
112112
expect 2 'a newline cannot inject a second allowlist pattern' bash "$checker" "$work/newline-policy.json" "$work/workflows"
113113

114+
# Run the actual consumer entrypoint against disposable Git checkouts.
115+
# Hidden index flags must fail before any helper or native program executes.
116+
source_fixture="$work/source-fixture"
117+
authority_fixture="$work/standards-fixture"
118+
mkdir -p "$source_fixture/.githooks" "$source_fixture/scripts/ci" \
119+
"$source_fixture/.github/workflows" "$source_fixture/.github/actions/local"
120+
cp "$ROOT/.githooks/validate-actions-lock.sh" "$source_fixture/.githooks/"
121+
cp "$transport" "$source_fixture/scripts/ci/"
122+
printf 'mock-only lock sentinel\n' > "$source_fixture/.github/workflows/actions.lock"
123+
printf 'jobs: {gate: {runs-on: ubuntu-latest, steps: [{run: echo fixture}]}}\n' \
124+
> "$source_fixture/.github/workflows/test.yml"
125+
printf 'name: fixture\nruns: {using: composite, steps: []}\n' \
126+
> "$source_fixture/.github/actions/local/action.yaml"
127+
printf '.github/actions/local/action.yml\n' > "$source_fixture/.gitignore"
128+
git -C "$source_fixture" init --quiet
129+
git -C "$source_fixture" add --all
130+
git -C "$source_fixture" -c user.name=Fixture -c user.email=fixture@example.invalid \
131+
-c commit.gpgsign=false commit --quiet -m 'disposable source-qualification fixture'
132+
git clone --quiet --no-hardlinks "$STANDARDS_ROOT" "$authority_fixture"
133+
source_gate() {
134+
STANDARDS_ROOT="$authority_fixture" GH_ACTIONS_LOCK_BIN="$official_native" \
135+
ACTIONS_LOCK_EVIDENCE_DIR="$work/source-evidence" \
136+
bash "$source_fixture/.githooks/validate-actions-lock.sh"
137+
}
138+
for flag in --assume-unchanged --skip-worktree; do
139+
for fixture in "$authority_fixture" "$source_fixture"; do
140+
if [[ "$fixture" = "$authority_fixture" ]]; then
141+
path=scripts/update-actions-lock.sh
142+
else
143+
path=.github/workflows/test.yml
144+
fi
145+
git -C "$fixture" update-index "$flag" "$path"
146+
printf 'tampered consumed source\n' > "$fixture/$path"
147+
# This is the actual premise that fooled the previous source guard.
148+
[[ -z "$(git -C "$fixture" status --porcelain --untracked-files=all)" ]]
149+
expect 2 "hidden source flag $flag in $fixture is rejected" source_gate
150+
grep -F 'unsafe index flags' "$work/stderr" >/dev/null
151+
[[ ! -e "$work/source-evidence/native.exit" ]] ||
152+
{ echo 'an unqualified source reached native verification' >&2; exit 1; }
153+
git -C "$fixture" update-index --no-assume-unchanged "$path"
154+
git -C "$fixture" update-index --no-skip-worktree "$path"
155+
git -C "$fixture" checkout -- "$path"
156+
done
157+
done
158+
# A clean status must not hide action.yml shadowing a tracked action.yaml.
159+
printf 'name: ignored shadow\nruns: {using: composite, steps: []}\n' \
160+
> "$source_fixture/.github/actions/local/action.yml"
161+
[[ -z "$(git -C "$source_fixture" status --porcelain --untracked-files=all)" ]]
162+
expect 2 'ignored action input is not part of the qualified commit' source_gate
163+
grep -F 'tracked, untracked or ignored changes' "$work/stderr" >/dev/null
164+
[[ ! -e "$work/source-evidence/native.exit" ]] ||
165+
{ echo 'ignored source reached native verification' >&2; exit 1; }
166+
114167
cat > "$work/mock-native" <<'SH'
115168
#!/usr/bin/env bash
116169
set -eu

0 commit comments

Comments
 (0)