Skip to content

feat: sign pin commits and guard draft releases in the pin pr flow - #21

Closed
nullPointerEnjoyer wants to merge 1 commit into
mainfrom
fix/release-pipeline-hardening
Closed

nullPointerEnjoyer wants to merge 1 commit into
mainfrom
fix/release-pipeline-hardening

Conversation

@nullPointerEnjoyer

Copy link
Copy Markdown
Collaborator

Root-cause fixes for the two manual-firefight loops this release cycle hit on every tag:

1. Signed pin commits. The workflow-authored pin commit was unsigned, so the default-branch commit-signature ruleset blocked every pin PR (#13/#19 both needed a manual signed re-author). open-spm-pr.sh now SSH-signs the pin commit when BOT_SIGNING_KEY (SSH private key) is configured — key written 0600, used for exactly that commit, removed right after; without the secret the behavior is unchanged. release.yml passes the optional secret through.

Owner action to activate signing (one time): create an SSH keypair, register the public key as a signing key on the repository (or bot account), and add the private key as the BOT_SIGNING_KEY actions secret. Until then the existing manual rewrite continues to work.

2. Draft-release guard. The v0.1.1 tag move flipped the release to draft, and the failure surfaced later as an opaque pin-gate refusal. open-spm-pr.sh now verifies the release is published before opening the pin PR and fails closed with an actionable message (publish command included), before any mutation.

Tests: suite extended 164 → 168 assertions (draft refusal + message, unreadable state fail-closed, signed commit invocation with signing config, unsigned fallback unchanged). actionlint + shellcheck clean.

@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

🔍 OpenCodeReview found 8 issue(s) in this PR.

  • ✅ Successfully posted inline: 2 comment(s)
  • 📋 Routed to summary by policy: 6 comment(s)

test · low

📄 scripts/release/test-open-spm-pr.sh (L90-L90)

⚠️ GitHub could not post this as an inline comment: Routed to summary (severity low · category test)

The || echo false fallback silently treats a missing release_is_draft fixture as 'published', which can mask a test-setup bug: a future case that forgets to write the fixture will pass for the wrong reason. Fail loudly on a missing fixture instead of defaulting.

💡 Suggested Change

Before:

  draft="$(cat "${CASE_DIR}/release_is_draft" 2>/dev/null || echo false)"

After:

  if [ ! -f "${CASE_DIR}/release_is_draft" ]; then
    echo "gh stub: missing fixture ${CASE_DIR}/release_is_draft" >&2
    exit 1
  fi
  draft="$(cat "${CASE_DIR}/release_is_draft")"

maintainability · low

📄 scripts/release/open-spm-pr.sh (L240-L242)

⚠️ GitHub could not post this as an inline comment: Routed to summary (severity low · category maintainability)

The cleanup destroys any pre-existing repo-local gpg.format / user.signingkey configuration: the script unconditionally unsets both keys, even if the environment (e.g. a local release runner or a reusable-workflow caller) had already configured its own signing setup. Capture the prior values before overwriting and restore them (or only unset if they were absent), so the signing setup is self-cleaning without collateral damage.

💡 Suggested Change

Before:

  rm -f "${key_file}"
  git config --unset gpg.format || true
  git config --unset user.signingkey || true

After:

  rm -f "${key_file}"
  if [ -n "${prev_signingkey:-}" ]; then
    git config user.signingkey "${prev_signingkey}"
  else
    git config --unset user.signingkey || true
  fi
  # likewise restore gpg.format only if it was previously set

maintainability · low

📄 scripts/release/open-spm-pr.sh (L221-L223)

⚠️ GitHub could not post this as an inline comment: Routed to summary (severity low · category maintainability)

2>/dev/null discards gh's diagnostic stderr, so the fail-closed error ('cannot verify the release state') loses the actual reason (token scope, rate limit, network). Redirect gh's stderr to the log instead (e.g. 2>&2 or drop the redirect) while keeping only the exit status as the failure signal, so operators can act on the real cause.


bug · low

📄 scripts/release/open-spm-pr.sh (L224-L225)

⚠️ GitHub could not post this as an inline comment: Routed to summary (severity low · category bug)

The value comparison treats any output that is not exactly false as a draft, including null/empty output (e.g. release deleted between the earlier fetch and this call). The error message then claims the release 'is a draft' even when it does not exist, which is misleading — the fail-closed behavior is right, but the message should distinguish 'not found/unreadable' from 'is a draft' (e.g. also accept empty as an unverified-state error).


test · low

📄 scripts/release/test-open-spm-pr.sh (L1489-L1491)

⚠️ GitHub could not post this as an inline comment: Routed to summary (severity low · category test)

Cases 78 and 79 exercise the draft/unreadable paths but never run them with BOT_SIGNING_KEY set, so there is no coverage confirming the draft gate fires before any signing setup (i.e., no key file is written or git config signing mutation happens on the refused paths). A variant of case 78 with BOT_SIGNING_KEY="test-key-material" asserting the log contains no user.signingkey entry would pin that ordering.


maintainability · low

📄 scripts/release/open-spm-pr.sh (L234-L236)

⚠️ GitHub could not post this as an inline comment: Routed to summary (severity low · category maintainability)

The cleanup order writes the key to disk (mktemp + printf) before chmod 600. Between file creation and the permission change there is a brief window where the private key file has the default mktemp mode. Use install -m 600 /dev/stdin or set the umask before creating the file to eliminate the race.

Comment on lines +217 to +223
# The release must be published (not a draft) before pinning: SPM
# resolves the pinned checksum against the release's published assets,
# and the pin-order gate refuses draft releases later with a less
# actionable error. Fail closed when the release state cannot be read.
release_is_draft="$(gh release view "${TAG}" --repo "${GITHUB_REPOSITORY}" \
--json isDraft --jq '.isDraft' 2>/dev/null)" \
|| { echo "::error::cannot verify the release state for $(esc "${TAG}")"; exit 1; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maintainability · medium
The draft-release gate runs just before the commit, after git checkout -B and git add have already mutated the local checkout. The remote is untouched (no push/PR create happens before it), so the fail-closed intent holds, but the check reads only from the GitHub API and depends on no local state — hoisting it above the tag-ancestor/HEAD checks (near the other input validations at the top of the script) would make it a pure precondition, fail earlier, and make the assert_no_mutations guarantee in the test harness structurally obvious rather than incidental.

Suggestion:

Suggested change
# The release must be published (not a draft) before pinning: SPM
# resolves the pinned checksum against the release's published assets,
# and the pin-order gate refuses draft releases later with a less
# actionable error. Fail closed when the release state cannot be read.
release_is_draft="$(gh release view "${TAG}" --repo "${GITHUB_REPOSITORY}" \
--json isDraft --jq '.isDraft' 2>/dev/null)" \
|| { echo "::error::cannot verify the release state for $(esc "${TAG}")"; exit 1; }
# Hoist near the top of the script, before `git checkout -B`:
release_is_draft="$(gh release view "${TAG}" --repo "${GITHUB_REPOSITORY}" \
--json isDraft --jq '.isDraft' 2>/dev/null)" \
|| { echo "::error::cannot verify the release state for $(esc "${TAG}")"; exit 1; }

Comment on lines +234 to +242
key_file="$(mktemp)"
printf '%s\n' "${BOT_SIGNING_KEY}" > "${key_file}"
chmod 600 "${key_file}"
git config gpg.format ssh
git config user.signingkey "${key_file}"
git commit -S -m "chore: pin the SPM checksum to ${TAG}"
rm -f "${key_file}"
git config --unset gpg.format || true
git config --unset user.signingkey || true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security · high
With set -euo pipefail, if git commit -S fails (missing/invalid SSH key, signing failure), the script exits immediately without executing rm -f "${key_file}" or the git config --unset calls. The BOT_SIGNING_KEY private key material is then left on disk (world-readable-nameable mktemp path) and user.signingkey keeps pointing at it for any later steps in the same job. Move cleanup into an EXIT trap so it runs on every path, and drop the persisted repo config in favor of one-shot -c options so interrupted runs can't leave a dangling signingkey in the checkout.

Suggestion:

Suggested change
key_file="$(mktemp)"
printf '%s\n' "${BOT_SIGNING_KEY}" > "${key_file}"
chmod 600 "${key_file}"
git config gpg.format ssh
git config user.signingkey "${key_file}"
git commit -S -m "chore: pin the SPM checksum to ${TAG}"
rm -f "${key_file}"
git config --unset gpg.format || true
git config --unset user.signingkey || true
key_file="$(mktemp)"
printf '%s\n' "${BOT_SIGNING_KEY}" > "${key_file}"
chmod 600 "${key_file}"
trap 'rm -f "${key_file}"' EXIT
git -c gpg.format=ssh -c user.signingkey="${key_file}" \
commit -S -m "chore: pin the SPM checksum to ${TAG}"
rm -f "${key_file}"
trap - EXIT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants