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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MfBCVNDv3y5gm2djeZSAk4
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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 <path-to-Cargo.lock>" >&2; exit 1; }
|
||||
@@ -18,7 +20,7 @@ lock="$1"
|
||||
}
|
||||
|
||||
# source = "git+<url>[?query]#<sha>"
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user