Skip to content

ci: publish crates via crates.io trusted publishing once a release is signed - #2816

Merged
thiras merged 2 commits into
mainfrom
ci/crates-io-trusted-publishing
Nov 1, 2026
Merged

thiras merged 2 commits into
mainfrom
ci/crates-io-trusted-publishing

Conversation

@thiras

@thiras thiras commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

What

The crates.io upload moves from the local scripts/publish-crates.sh (personal API token) to a new workflow, .github/workflows/publish-crates.yml, using crates.io trusted publishing. Signing stays local. sign-release.sh takes the release out of draft, then dispatches the workflow on main with the tag as input, using the maintainer's gh login. The workflow, KEYS and every helper script come from that main commit. The tag is checked out at src/ and only packaged. The release environment allows main only, so no tag's or branch's copy of the workflow can get the token. No crates.io token is stored anywhere: the job trades its GitHub OIDC token for a 30-minute crates.io token, which the auth action revokes when the job ends.

A release is now cargo release + scripts/sign-release.sh; the crates.io upload follows automatically.

  • prepare (contents: read, no OIDC):
    • verifies the tag against KEYS on origin/main;
    • runs the new check-release-signed.sh: the release is out of draft; SHA256SUMS.asc is a good signature by a key in KEYS that has neither expired nor been revoked; the manifest names this version's archives; SHA256SUMS.minisig and every archive's .minisig are attached;
    • runs the binstall guard at the tag;
    • runs the new crates_to_publish.py, which excludes crates crates.io already serves at the version and refuses a crate that does not exist on crates.io yet;
    • runs the dashboard build and the cargo publish --dry-run verify build.
  • publish (release environment, id-token: write):
    • runs no build script, proc macro or package install: any step in this job could request an OIDC token;
    • takes the dashboard build from prepare and runs cargo publish --workspace --no-verify;
    • re-running uploads only what is missing, so a run that fails partway finishes on re-run.
  • The devops bump PR moves to the end of sign-release.sh. publish-crates.sh and its tests are deleted.
  • Recovery is to re-run all jobs, or gh workflow run publish-crates.yml --ref main -f tag=vX.Y.Z.
  • Pre-releases are uploaded too, as before; RELEASING.md says so.

Reviewer notes

Read .github/workflows/publish-crates.yml first. It is short, and its header covers the trust model. Then read check-release-signed.sh and crates_to_publish.py.

  • Stronger than the old script.
    • SHA256SUMS.asc is now verified, not only checked for presence. The check reads gpg's status lines, because a plain gpg --verify exits 0 for an expired or revoked key.
    • A 200 from crates.io counts only if its JSON describes the crate and version asked about.
  • Signature trust. The checks are enforced by code on main, not by the tag. The second commit addresses the review's tag-controlled-workflow finding. The remaining trust root is main (Protect Main; org admins bypass it), the same one KEYS already has.
  • Manual setup before the next release (RELEASING.md § Trusted publishing):
    1. The release environment: deployments from branch main only (no v* tag pattern), with no reviewers.
    2. On each of the 14 crates, add a trusted publisher: decdn/decdn, publish-crates.yml, environment release. An individual owner does this.
    3. Once the first CI upload succeeds, turn on Require trusted publishing on each crate.
  • Follow-ups in other repos. decdn/devops (scripts/open-decdn-bump.sh, AGENTS.md, the node role README) and internal/Launch/release-checklist.md still say publish-crates.sh opens the bump.
  • Untested until then. The OIDC exchange first runs at the next release. A failed exchange fails before any upload.
  • Post-merge smoke check. gh workflow run publish-crates.yml --ref main -f tag=v0.3.0 should pass prepare and skip publish, since every crate is already at 0.3.0. Locally, main's helpers pass against a v0.3.0 worktree.

Verification

  • pre-commit run on the changed files (passes; the crypto-bigint cargo-deny advisory predates this branch and is warn-only)
  • uvx --with pyyaml pytest .github/scripts/tests scripts/tests: 617 passed
    • New tests cover the signature gate (expired, revoked and outside-KEYS keys, a tampered manifest, another release's or an rc's manifest), the upload plan (crates.io statuses, bodies, retries) and the devops bump guards.
    • I checked the key and guard tests with one-at-a-time mutations.
  • .github/scripts/check-workflow-hardening.sh, .github/scripts/check-toolchain-pin.sh, actionlint, shellcheck
  • check-release-signed.sh v0.3.0 against the real release and the real KEYS: passes
  • crates_to_publish.py --version 0.3.0 against crates.io: all 14 already published, nothing pending
  • PR title uses an allowed type with a lowercase subject
  • No Rust, contract or public API changes, so clippy, nextest and forge are not affected.

🤖 Generated with Claude Code

… signed

sign-release.sh takes the release out of draft with the maintainer's gh
login; the resulting `release: published` event starts publish-crates.yml,
which uploads the workspace through crates.io trusted publishing (OIDC). No
crates.io token is stored anywhere.

- prepare (contents: read): verifies the tag against KEYS on origin/main,
  check-release-signed.sh (a good SHA256SUMS.asc by a live key in KEYS, a
  manifest of this version, every .minisig attached), the binstall guard,
  crates_to_publish.py (excludes crates crates.io already serves, refuses a
  crate that does not exist yet), the dashboard build and the verify build.
- publish (crates-io environment, id-token: write): runs no build script,
  proc macro or package install; cargo publish --no-verify with the
  short-lived token. Re-running uploads only what is missing.

The devops bump PR moves to the end of sign-release.sh, and
scripts/publish-crates.sh and its tests are deleted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras thiras self-assigned this Nov 1, 2026
Copilot AI balanced review requested due to automatic review settings November 1, 2026 10:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The tag-controlled release workflow allows authorized tag creators to bypass the signing gate and request a crates.io token, while the documented smoke check fails because the target tag lacks required publishing helpers.

2 open issues
What changed in this PR

Moves crates.io publishing from a local token-based script to GitHub Actions trusted publishing after a maintainer signs and publishes the release. Signing remains local.

Changes:

  • Adds separate preparation and publishing jobs, signature checks, and retry-safe upload planning.
  • Moves the downstream devops bump into sign-release.sh and removes the local publishing script.
  • Updates release documentation, workflow permissions, and regression tests.
File Description
scripts/​tests/​test_sign_release_switches.py Tests signing-script skip switches.
scripts/​tests/​test_sign_release_publish.py Covers devops bump execution, guards, and failures.
scripts/​tests/​test_sign_release_key_selection.py Disables downstream cloning in signing fixtures.
scripts/​tests/​test_publish_crates_assets.py Removes tests for the deleted publisher.
scripts/​sign-release.sh Reports CI publishing and opens the devops bump.
scripts/​publish-crates.sh Removes the local token-based publisher.
RELEASING.md Documents trusted publishing, setup, and recovery.
release.toml Updates comments explaining deferred publishing.
.github/​workflows/​release.yml Updates publishing-related comments only.
.github/​workflows/​publish-crates.yml Adds signed-release preparation and trusted publishing.
.github/​scripts/​tests/​test_pnpm_wrapper.py Removes obsolete publisher references from the docstring.
.github/​scripts/​tests/​test_crates_to_publish.py Tests upload planning and registry responses.
.github/​scripts/​tests/​test_check_release_signed.py Tests signature and release-asset checks.
.github/​scripts/​pnpm.sh Updates the wrapper’s usage comment.
.github/​scripts/​crates_to_publish.py Plans missing uploads and confirms registry availability.
.github/​scripts/​check-release-signed.sh Verifies the manifest signature and required assets.
.github/​scripts/​check_workspace_manifests.py Updates the metadata-consumer comment.
.github/​scripts/​check_workflow_hardening.py Allows OIDC permission for the publishing job.

Review effort: Balanced

Comment thread .github/workflows/publish-crates.yml Resolved
Comment thread .github/workflows/publish-crates.yml Resolved
A `release` event runs the tag's copy of publish-crates.yml, and crates.io
matches the workflow by file name and environment, not by ref. With the
environment open to `v*` tags, anyone able to push a release tag could
carry a workflow that skips the checks and still get the token.

- publish-crates.yml is workflow_dispatch only. sign-release.sh dispatches
  it on main once the release is out of draft; a failed dispatch warns and
  prints the command, last.
- The `release` environment (renamed from `crates-io`) allows `main` only.
- The workflow, KEYS and every script and action come from the main commit
  the run started on; the tag is checked out at src/ and only packaged. The
  dashboard-build action takes a `root` input for this. It also lets a
  dispatch against an older tag, such as v0.3.0, run the current checks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

@github-code-quality

Copy link
Copy Markdown

Code coverage overview

Languages: Solidity

Solidity / code-coverage/forge

main ca1a965 ci/crates-io-trusted... c87ae74 +/-
92% 92% 0%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.

@thiras
thiras merged commit 236a892 into main Nov 1, 2026
34 checks passed
@thiras
thiras deleted the ci/crates-io-trusted-publishing branch November 1, 2026 10:46
thiras added a commit to decdn/devops that referenced this pull request Nov 1, 2026
…-bump.sh (#200)

decdn/decdn#2816 deleted publish-crates.sh; sign-release.sh now opens the
bump PR once the release is out of draft. The invocation is unchanged.

Closes #198

Co-authored-by: Claude Opus 5.5 <[email protected]>
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