Repository navigation
ci: publish to npm with trusted publishing #47615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,6 +93,7 @@ jobs: | |
| if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.use-npm == 'true' }} | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
| defaults: | ||
| run: | ||
| working-directory: packages/bun-release | ||
|
|
@@ -103,6 +104,10 @@ jobs: | |
| persist-credentials: false | ||
| # To workaround issue | ||
| ref: main | ||
| - name: Setup Node.js | ||
| uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 | ||
| with: | ||
| node-version: latest | ||
| - name: Setup Bun | ||
| uses: ./.github/actions/setup-bun | ||
| with: | ||
|
|
@@ -113,7 +118,7 @@ jobs: | |
| run: bun upload-npm -- "$BUN_VERSION" publish | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 If any of the 17 packages the npm job publishes lacks an npm-side trusted publisher bound to release.yml, the release now stops with some platform packages published and no root bun package. Each Why this was flaggedA release or the daily canary run triggers the npm job at .github/workflows/release.yml:117-120, which runs Verification: |
||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| NPM_CONFIG_PROVENANCE: "false" | ||
| npm-types: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| name: Release types to NPM | ||
| runs-on: ubuntu-latest | ||
|
|
@@ -122,6 +127,7 @@ jobs: | |
| if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.use-types == 'true' }} | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
| defaults: | ||
| run: | ||
| working-directory: packages/bun-types | ||
|
|
@@ -160,11 +166,9 @@ jobs: | |
| - name: Release | ||
| if: ${{ env.BUN_VERSION == 'canary' || env.BUN_LATEST == 'true' }} | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| NPM_CONFIG_USERCONFIG: ${{ runner.temp }}/.npmrc | ||
| NPM_TAG: ${{ env.BUN_VERSION == 'canary' && 'canary' || 'latest' }} | ||
| NPM_CONFIG_PROVENANCE: "false" | ||
| run: | | ||
| echo '//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}' > "$NPM_CONFIG_USERCONFIG" | ||
| VERSION=$(node -p 'require("./package.json").version') | ||
| if [ "$(npm view bun-types@"$VERSION" version 2>/dev/null)" = "$VERSION" ]; then | ||
| echo "bun-types@$VERSION already published, skipping" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1 @@ | ||
| @oven:registry=https://registry.npmjs.org/ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 (optional) Transition hazard: a release published from a tag cut before this merges ships no Why this was flaggedTrigger: a Verification: For |
||
| //registry.npmjs.org/:_authToken=${NPM_TOKEN} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 (optional) Anyone running
npm audit signaturesor reading the provenance of a taggedbunrelease will see a signed attestation naming the release-tag commit, while install.js was actually built from whatevermainis at run time. Trusted publishing (enabled by release.yml:96) auto-generates provenance from the OIDC token'ssha, but the checkout at release.yml:106 pinsref: main. The base published with a token and no attestation, so no false claim existed. Fix: build the publish payload from the same commit the attestation names, i.e. dropref: main(or publish with--provenance=falseuntil the workaround it references is resolved). [also at: .github/workflows/release.yml:118 - Anyone verifying provenance forbunor@ oven/bun-*will get a signed attestation naming a source commit the package was not built from.]Why this was flagged
When a release event fires for tag bun-vX and
mainhas moved past that tag (the normal case), the npm job checks outmain(release.yml:106, comment 'To workaround issue' with no issue link) and buildsnpm/bun/install.jsfrom packages/bun-release/scripts/npm-postinstall.ts at main (packages/bun-release/scripts/upload-npm.ts:68). The OIDC token minted underid-token: write(release.yml:96) carries the run'ssha= the tag commit, and npm's trusted-publishing path for a public repo attaches a provenance statement for that commit. On the base there was no attestation at all:NPM_TOKENpublishes carry no provenance, so a wrong source commit is new with this diff. Consumers verifying provenance (npm audit signatures, Sigstore/Rekor lookups) get a cryptographically valid statement that the package came from a commit it was not built from. Remedy: check out the triggering ref for the npm job, or disable provenance until the ref: main workaround is removed.Verification: nit — triggered on every
release: publishedrun oncemainhas any commit past the tagged commit. Thenpmjob's checkout keepsref: main(release.yml:105-106), so the job builds from main's tree. The diff addsid-token: write(release.yml:96), sonpm publishauto-generates a SLSA provenance attestation whose source digest is GITHUB_SHA. The base never passed--provenance, so no attestation existed before.