WIP: Paused over-hardening fix wave (boot checkout verification, double-read package manifest)

This commit is contained in:
Gabriel Brown
2026-09-17 11:43:30 -04:00
parent 28e387868f
commit 442eec19fa
15 changed files with 2553 additions and 326 deletions
+146
View File
@@ -15,6 +15,16 @@ note() { findings+=("$1"); }
[[ -x "$boot" ]] || { printf 'boot contract: %s is not executable\n' "$boot" >&2; exit 1; }
# Git is the only package boot can install before the verified checkout exists.
# Both root-server and ordinary-user paths must exclude ambient third-party
# repositories while still allowing Fedora dependencies.
for git_install in \
'dnf install -y --repo=fedora --repo=updates --from-repo=fedora,updates git' \
'sudo dnf install -y --repo=fedora --repo=updates --from-repo=fedora,updates git'; do
grep -qF "$git_install" "$boot" \
|| note "boot omits reviewed Fedora source binding: $git_install"
done
work="$(mktemp -d)"
trap 'rm -rf "$work"' EXIT
@@ -103,6 +113,16 @@ case "\${1:-}" in
[[ "\$#" -eq 4 && "\$4" == 'HEAD^{commit}' ]] || exit 97
cat "$state/head-revision"
;;
ls-tree)
[[ "\$#" -eq 6 && "\$4" == -rz && "\$5" == --full-tree \
&& "\$6" == "$revision" ]] || exit 97
printf '100755 blob aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\tinstall\0'
;;
hash-object)
[[ "\$#" -eq 6 && "\$4" == --no-filters && "\$5" == -- \
&& "\$6" == install ]] || exit 97
printf '%s\n' aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
;;
*) exit 97 ;;
esac
;;
@@ -268,6 +288,132 @@ run_boot "$revision" "$boot_sha"
(( run_status != 0 )) || note 'existing HEAD mismatch returned success'
assert_no_install_or_rewrite 'existing HEAD mismatch'
# Git's porcelain status deliberately trusts index hints. The bootstrap cannot:
# these two flags can hide changed executable bytes while HEAD still names the
# reviewed commit. Exercise real Git so the contract cannot accidentally teach
# its adapter to expose state that Git itself hides.
real_git="$(command -v git)"
hidden_root="$work/hidden-index"
mkdir -p "$hidden_root/home"
"$real_git" init -q "$hidden_root/source"
"$real_git" -C "$hidden_root/source" config user.email contract@panama
"$real_git" -C "$hidden_root/source" config user.name contract
printf '#!/usr/bin/env bash\nexit 0\n' >"$hidden_root/source/install"
chmod +x "$hidden_root/source/install"
printf 'trusted target bytes\n' >"$hidden_root/source/target"
ln -s target "$hidden_root/source/trusted-link"
"$real_git" -C "$hidden_root/source" add install target trusted-link
"$real_git" -C "$hidden_root/source" commit -qm trusted
hidden_revision="$("$real_git" -C "$hidden_root/source" rev-parse HEAD)"
"$real_git" clone -q --bare "$hidden_root/source" "$hidden_root/origin.git"
# Exercise the exact boundary between checkout preparation and handoff. This
# test-only copy inserts a same-UID replacement after prepare returns; the
# production handoff must perform its complete comparison after that point.
post_prepare_checkout="$hidden_root/post-prepare-swap"
post_prepare_marker="$hidden_root/post-prepare-executed"
post_prepare_hook_marker="$hidden_root/post-prepare-hook-fired"
"$real_git" clone -q "$hidden_root/origin.git" "$post_prepare_checkout"
post_prepare_hook="$hidden_root/swap-install"
cat >"$post_prepare_hook" <<'HOOK'
#!/usr/bin/env bash
: >"$PANAMA_BOOT_POST_PREPARE_HOOK_MARKER"
printf '#!/usr/bin/env bash\nprintf "executed\\n" >%q\n' \
"$PANAMA_BOOT_POST_PREPARE_MARKER" >"$PANAMA_PATH/install"
chmod +x "$PANAMA_PATH/install"
HOOK
chmod +x "$post_prepare_hook"
hooked_boot="$hidden_root/boot-post-prepare-hook"
awk '
{
print
if ($0 == "prepare_panama_checkout \"$PANAMA_PATH\"") {
prepare_count++
if (prepare_count == 1) print "\"$PANAMA_BOOT_POST_PREPARE_FIXTURE\""
}
}
' "$boot" >"$hooked_boot"
hooked_boot_sha="$(sha256sum "$hooked_boot" | cut -d' ' -f1)"
post_prepare_status=0
HOME="$hidden_root/home" PANAMA_PATH="$post_prepare_checkout" \
PANAMA_BOOT_REVISION="$hidden_revision" PANAMA_BOOT_SHA256="$hooked_boot_sha" \
PANAMA_BOOT_POST_PREPARE_FIXTURE="$post_prepare_hook" \
PANAMA_BOOT_POST_PREPARE_MARKER="$post_prepare_marker" \
PANAMA_BOOT_POST_PREPARE_HOOK_MARKER="$post_prepare_hook_marker" \
bash "$hooked_boot" </dev/null >"$hidden_root/post-prepare.out" 2>&1 \
|| post_prepare_status=$?
[[ -e "$post_prepare_hook_marker" ]] \
|| note 'post-prepare replacement hook did not exercise the boundary'
(( post_prepare_status != 0 )) \
|| note 'post-prepare worktree replacement returned success'
[[ ! -e "$post_prepare_marker" ]] \
|| note 'post-prepare worktree replacement executed unreviewed install bytes'
# A valid tracked symlink must compare its link text with Git's 120000 blob;
# hashing the pathname would follow it and hash the target file instead.
symlink_checkout="$hidden_root/tracked-symlink"
"$real_git" clone -q "$hidden_root/origin.git" "$symlink_checkout"
symlink_status=0
HOME="$hidden_root/home" PANAMA_PATH="$symlink_checkout" \
PANAMA_BOOT_REVISION="$hidden_revision" PANAMA_BOOT_SHA256="$boot_sha" \
bash "$boot" </dev/null >"$hidden_root/tracked-symlink.out" 2>&1 \
|| symlink_status=$?
(( symlink_status == 0 )) \
|| note 'a checkout with a valid tracked symlink was rejected'
for hidden_flag in assume-unchanged skip-worktree; do
hidden_checkout="$hidden_root/$hidden_flag"
hidden_marker="$hidden_root/$hidden_flag-executed"
"$real_git" clone -q "$hidden_root/origin.git" "$hidden_checkout"
printf '#!/usr/bin/env bash\nprintf "executed\\n" >%q\n' "$hidden_marker" \
>"$hidden_checkout/install"
chmod +x "$hidden_checkout/install"
"$real_git" -C "$hidden_checkout" update-index "--$hidden_flag" install
[[ -z "$("$real_git" -C "$hidden_checkout" status --porcelain)" ]] \
|| note "$hidden_flag fixture was not hidden from porcelain status"
hidden_status=0
HOME="$hidden_root/home" PANAMA_PATH="$hidden_checkout" \
PANAMA_BOOT_REVISION="$hidden_revision" PANAMA_BOOT_SHA256="$boot_sha" \
bash "$boot" </dev/null >"$hidden_root/$hidden_flag.out" 2>&1 \
|| hidden_status=$?
(( hidden_status != 0 )) \
|| note "$hidden_flag modified checkout returned success"
[[ ! -e "$hidden_marker" ]] \
|| note "$hidden_flag modified checkout executed unreviewed install bytes"
done
# The same hidden-index state must not conceal a mode change or a different
# symlink target; both are part of the reviewed Git tree, not metadata hints.
for hidden_flag in assume-unchanged skip-worktree; do
for hidden_change in mode symlink-target; do
hidden_checkout="$hidden_root/$hidden_flag-$hidden_change"
"$real_git" clone -q "$hidden_root/origin.git" "$hidden_checkout"
case "$hidden_change" in
mode)
chmod -x "$hidden_checkout/install"
hidden_path=install
;;
symlink-target)
rm -- "$hidden_checkout/trusted-link"
ln -s untrusted-target "$hidden_checkout/trusted-link"
hidden_path=trusted-link
;;
esac
"$real_git" -C "$hidden_checkout" update-index "--$hidden_flag" "$hidden_path"
[[ -z "$("$real_git" -C "$hidden_checkout" status --porcelain)" ]] \
|| note "$hidden_flag $hidden_change fixture was not hidden from porcelain status"
hidden_status=0
HOME="$hidden_root/home" PANAMA_PATH="$hidden_checkout" \
PANAMA_BOOT_REVISION="$hidden_revision" PANAMA_BOOT_SHA256="$boot_sha" \
bash "$boot" </dev/null >"$hidden_root/$hidden_flag-$hidden_change.out" 2>&1 \
|| hidden_status=$?
(( hidden_status != 0 )) \
|| note "$hidden_flag concealed a tracked $hidden_change change"
done
done
if (( ${#findings[@]} > 0 )); then
printf 'boot contract: %d finding(s)\n' "${#findings[@]}" >&2
printf ' - %s\n' "${findings[@]}" >&2