From c106793f79f155626e7fba7602b22a769b0af4ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Tue, 17 Nov 2026 12:20:49 +0000 Subject: [PATCH] fix(release): publish to npm with the job's OIDC token, not a stored token (#8070) * test(release): npm publishes with the job's OIDC token, no stored token named * fix(release): publish to npm with the job's OIDC token, not a stored token * test(release): catch a secret named by index or inherited, not only secrets.X --- .github/workflows/publish.yml | 5 +++-- docs/contributing/release-channels.mdx | 2 +- scripts/publish-workflow.test.mjs | 9 ++++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f17094e060..0dc0f2aff6 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -809,11 +809,12 @@ jobs: ' "$RUNNER_TEMP/assets-pages.json" > /dev/null # Runs outside the checkout so no project .npmrc applies, and with - # --ignore-scripts so no lifecycle script runs next to the npm token. + # --ignore-scripts so no lifecycle script runs next to the npm credentials. - name: Publish packages working-directory: ${{ runner.temp }} env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + # Empty, not setup-node's placeholder: npm authenticates with the job's OIDC token only. + NODE_AUTH_TOKEN: "" VERSION: ${{ steps.version.outputs.version }} DIST_TAG: ${{ steps.version.outputs.dist_tag }} run: | diff --git a/docs/contributing/release-channels.mdx b/docs/contributing/release-channels.mdx index 75f24c2a86..ab555edfc5 100644 --- a/docs/contributing/release-channels.mdx +++ b/docs/contributing/release-channels.mdx @@ -72,7 +72,7 @@ The publish workflow validates release channel boundaries before publishing: - Merged `release/vX.Y.Z` PRs publish stable releases only. - Every publish job verifies that its checkout matches the immutable event SHA. - Builds, lifecycle scripts and `npm pack` run in a job with a read-only token and no secrets. -- The job that holds the npm token runs no code from the release commit. It checks that every packed tarball is a package this workflow publishes, at exactly the release version, then uploads it with lifecycle scripts off. +- The job that publishes to npm runs no code from the release commit, and it holds no stored npm token: npm trusted publishing authenticates it with the job's OIDC token. It checks that every packed tarball is a package this workflow publishes, at exactly the release version, then uploads it with lifecycle scripts off. - A version already on npm is skipped only when its contents match the original run’s tarball, including on a retry. Different contents fail the publish. - The Lambda handler zip and arm64 video image are built by the run, and `@hyperframes/aws-lambda` pins those builds. Retries reuse the original immutable run bundle. If the version is already on npm, its verified package must pin those same bytes before any release mutation. A separate immutable run receipt binds the release ID and asset digests; foreign releases and mismatched assets fail instead of being adopted or overwritten. See [publish recovery](/contributing/changelog-process) for retention and recovery limits. diff --git a/scripts/publish-workflow.test.mjs b/scripts/publish-workflow.test.mjs index 82d7bca56b..ec88c6668d 100644 --- a/scripts/publish-workflow.test.mjs +++ b/scripts/publish-workflow.test.mjs @@ -471,6 +471,12 @@ test("release-commit code runs only in a job without secrets", () => { assert.deepEqual(publish.needs, ["release-source", "pack"]); }); +test("npm publishes with the job's OIDC token only: no stored npm token is named", () => { + assert.doesNotMatch(JSON.stringify(config), /\bsecrets\b(?!\.GITHUB_TOKEN\b)/); + assert.equal(publish.permissions["id-token"], "write"); + assert.equal(stepOf(publish, "Publish packages").env.NODE_AUTH_TOKEN, ""); +}); + test("the publish job runs no code from the release commit", () => { for (const step of publish.steps) { assert.doesNotMatch(step.uses ?? "", /setup-bun|^\.\//, `${step.uses} in the publish job`); @@ -482,10 +488,7 @@ test("the publish job runs no code from the release commit", () => { assert.match(line, /--ignore-scripts/, step.name); } } - const job = JSON.stringify(publish); - assert.equal(job.split("secrets.NPM_TOKEN").length - 1, 1); const publishPackages = stepOf(publish, "Publish packages"); - assert.equal(publishPackages.env.NODE_AUTH_TOKEN, "${{ secrets.NPM_TOKEN }}"); assert.equal(publishPackages["working-directory"], "${{ runner.temp }}"); });