From ad8cf5756e166fa0ed7d747e46d66a5cff5d286c Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 11:27:46 -0600 Subject: [PATCH] fix: tighten the crates lock check, drop the key from child environments crates-lock-check.sh anchors on `[/:]daniel/gitdan-crates(.git)?/?` and matches case-insensitively, so a trailing-slash or differently-cased second commit is counted and a look-alike owner (notdaniel/) is not. crates-access.sh unsets DEPLOY_KEY once the key file is written, so git, ssh and timeout no longer inherit it. README says three actions, not two. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01MfBCVNDv3y5gm2djeZSAk4 --- README.md | 4 +++- scripts/crates-access-selftest.sh | 14 +++++++++++++- scripts/crates-access.sh | 2 ++ scripts/crates-lock-check.sh | 8 +++++--- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0a03245..870967a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,9 @@ Shared Gitea Actions composite actions for the gitdan forge. -Two actions. The first, done properly: **`cargo-cache`** — a persistent, +Three actions: `cargo-cache`, `cargo-cache-publish` and `gitdan-crates-access` +(read access to the private crates repo, [below](#gitdan-crates-access)). The +cache, done properly: **`cargo-cache`** — a persistent, per-branch Cargo build cache for self-hosted Gitea runners, where a pull request's cache is a near-free hardlink clone of an immutable snapshot its base branch published. diff --git a/scripts/crates-access-selftest.sh b/scripts/crates-access-selftest.sh index 594f338..cca6bac 100755 --- a/scripts/crates-access-selftest.sh +++ b/scripts/crates-access-selftest.sh @@ -61,6 +61,16 @@ ok "two commits fail, naming both" check "$scratch/two2.lock" >/dev/null 2>&1 && fail "two commits under different spellings passed" ok "two commits fail across URL spellings too" +{ entry core "$SRC?branch=main#$sha_a"; entry shared "git+https://gitdan.com/daniel/gitdan-crates/?branch=main#$sha_b"; } > "$scratch/slash.lock" +check "$scratch/slash.lock" >/dev/null 2>&1 && fail "a second commit spelled with a trailing slash passed" +{ entry core "$SRC?branch=main#$sha_a"; entry shared "git+https://gitdan.com/Daniel/GitDan-Crates.git#$sha_b"; } > "$scratch/case.lock" +check "$scratch/case.lock" >/dev/null 2>&1 && fail "a second commit spelled in another case passed" +ok "a trailing slash or a different case still counts as the repo" + +{ entry core "$SRC?branch=main#$sha_a"; entry shared "git+https://gitdan.com/notdaniel/gitdan-crates.git#$sha_b"; } > "$scratch/owner.lock" +check "$scratch/owner.lock" >/dev/null 2>&1 || fail "a look-alike owner counted as a second commit" +ok "a look-alike owner is not this source" + { entry other "git+ssh://git@gitdan.com:22022/daniel/gitdan-crates-extra.git#$sha_a" entry a "git+https://example.com/x/y#$sha_a"; entry b "git+https://example.com/x/y#$sha_b" entry serde "registry+https://github.com/rust-lang/crates.io-index"; } > "$scratch/none.lock" @@ -79,6 +89,7 @@ cat > "$stub/git" <<'STUB' #!/usr/bin/env bash printf '%s\n' "$@" > "$STUB_DIR/git.argv" printf '%s\n' "${GIT_SSH_COMMAND:-}" > "$STUB_DIR/git.ssh" +printf '%s' "${DEPLOY_KEY:-}" > "$STUB_DIR/git.key" [ -z "${STUB_GIT_ERR:-}" ] || echo "$STUB_GIT_ERR" >&2 exit "${STUB_GIT_RC:-0}" STUB @@ -122,7 +133,8 @@ grep -rqF "$secret_line" "$scratch/workspace" && fail "key material found in the for f in good.out good.env good.argv good.ssh; do grep -qF "$secret_line" "$scratch/$f" && fail "key material leaked into $f" done -ok "key is 0600 in a 0700 directory outside the workspace and in no output, env file or argv" +[ ! -s "$scratch/git.key" ] || fail "DEPLOY_KEY is still in the environment of git" +ok "key is 0600 in a 0700 directory outside the workspace and in no output, env file, argv or child environment" [ "$(tail -c1 "$keyfile" | od -An -c | tr -d ' ')" = '\n' ] || fail "key file does not end in a newline" if [ "$have_keygen" = 1 ]; then diff --git a/scripts/crates-access.sh b/scripts/crates-access.sh index 1fe09a8..1ef22a9 100755 --- a/scripts/crates-access.sh +++ b/scripts/crates-access.sh @@ -47,6 +47,8 @@ known_hosts="$dir/known_hosts" # builtin, so the key is not in any process's argv. ( umask 077; printf '%s\n' "${DEPLOY_KEY%$'\n'}" | tr -d '\r' > "$key" ) chmod 600 "$key" +# The children below (ssh-keygen, git, ssh, timeout) must not inherit the key. +unset DEPLOY_KEY cp "$known_hosts_src" "$known_hosts" chmod 600 "$known_hosts" diff --git a/scripts/crates-lock-check.sh b/scripts/crates-lock-check.sh index e430b1e..34aaae3 100755 --- a/scripts/crates-lock-check.sh +++ b/scripts/crates-lock-check.sh @@ -6,8 +6,10 @@ # # Several packages from the one source share a commit, so what counts is # distinct commits, not entries. The query string (`?branch=main`, `?rev=...`) -# is ignored, and so is the URL's spelling (scheme, port, `.git`): two copies -# of the repo are two copies whichever way they were named. No entry passes. +# is ignored, and so is the URL's spelling (scheme, port, `.git`, a trailing +# slash, case): two copies of the repo are two copies whichever way they were +# named. A look-alike owner or repo (`notdaniel/`, `gitdan-crates-extra`) is not +# this source. No entry passes. set -euo pipefail [ $# -eq 1 ] || { echo "::error::crates-lock-check: expected " >&2; exit 1; } @@ -18,7 +20,7 @@ lock="$1" } # source = "git+[?query]#" -shas=$(sed -nE 's#^source = "git\+[^"?\#]*daniel/gitdan-crates(\.git)?(\?[^"\#]*)?\#([^"]*)"$#\3#p' "$lock" | sort -u) +shas=$(sed -nE 's#^source = "git\+[^"?\#]*[/:]daniel/gitdan-crates(\.git)?/?(\?[^"\#]*)?\#([^"]*)"$#\3#Ip' "$lock" | sort -u) count=$(grep -c . <<<"$shas" || true) if [ "$count" -gt 1 ]; then -- 2.43.0