-
Notifications
You must be signed in to change notification settings - Fork 0
feat(monorepo-release): opt-in npm OIDC Trusted Publishing #79
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
base: main
Are you sure you want to change the base?
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 | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -61,13 +61,18 @@ on: | |||||||||||||||||||
| required: false | ||||||||||||||||||||
| default: false | ||||||||||||||||||||
| description: "Opt in to Blacksmith Linux runners (blacksmith-4vcpu-ubuntu-2404). Requires the Blacksmith GitHub App installed on the caller org. Defaults to ubuntu-latest." | ||||||||||||||||||||
| use-oidc: | ||||||||||||||||||||
| type: boolean | ||||||||||||||||||||
| required: false | ||||||||||||||||||||
| default: false | ||||||||||||||||||||
| description: "Opt in to npm OIDC Trusted Publishing. When true, the publish job inherits the caller's GITHUB_TOKEN so it can use 'id-token: write' (the caller must grant it) and a trusted publisher must be configured on npmjs.com for every package being released. Falls back to NPM_TOKEN if OIDC is unavailable. When false (default), publishing uses NPM_TOKEN and the job keeps least-privilege 'contents: read'." | ||||||||||||||||||||
| secrets: | ||||||||||||||||||||
| OPENAI_API_KEY: | ||||||||||||||||||||
| required: true | ||||||||||||||||||||
| description: "OpenAI API key for version and notes" | ||||||||||||||||||||
| NPM_TOKEN: | ||||||||||||||||||||
| required: true | ||||||||||||||||||||
| description: "NPM token for publishing" | ||||||||||||||||||||
| required: false | ||||||||||||||||||||
| description: "NPM token (required for npm publish when not using OIDC Trusted Publishing, or as a fallback when OIDC isn't configured for some packages)" | ||||||||||||||||||||
|
Comment on lines
73
to
+75
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. Restore an early guard for the non-OIDC publish path. Making 🤖 Prompt for AI Agents |
||||||||||||||||||||
| APP_ID: | ||||||||||||||||||||
| required: false | ||||||||||||||||||||
| description: "GitHub App ID for pushing to protected branches and triggering downstream workflows" | ||||||||||||||||||||
|
|
@@ -175,8 +180,12 @@ jobs: | |||||||||||||||||||
| app-id: ${{ secrets.APP_ID }} | ||||||||||||||||||||
| app-private-key: ${{ secrets.APP_PRIVATE_KEY }} | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Default publish path (use-oidc: false). Keeps least-privilege | ||||||||||||||||||||
| # `contents: read` exactly as before and publishes via NPM_TOKEN. Existing | ||||||||||||||||||||
| # callers are unaffected — no permission changes required on their side. | ||||||||||||||||||||
| npm-publish: | ||||||||||||||||||||
| needs: [check-labels, detect-changes, bump-versions] | ||||||||||||||||||||
| if: inputs.use-oidc != true | ||||||||||||||||||||
| runs-on: ${{ inputs.use-blacksmith && 'blacksmith-4vcpu-ubuntu-2404' || 'ubuntu-latest' }} | ||||||||||||||||||||
| permissions: | ||||||||||||||||||||
| contents: read | ||||||||||||||||||||
|
|
@@ -196,3 +205,30 @@ jobs: | |||||||||||||||||||
| root-build-command: ${{ inputs.root-build-command }} | ||||||||||||||||||||
| dry-run: ${{ inputs.dry-run }} | ||||||||||||||||||||
| npm-token: ${{ secrets.NPM_TOKEN }} | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # OIDC publish path (use-oidc: true). Opt-in only. It omits an explicit | ||||||||||||||||||||
| # `permissions:` block so it inherits the caller's GITHUB_TOKEN — meaning | ||||||||||||||||||||
| # `id-token: write` flows through when the caller grants it. Because it never | ||||||||||||||||||||
| # *requests* id-token, callers that haven't granted it can't be hard-failed; | ||||||||||||||||||||
| # the publish step just falls back to NPM_TOKEN. Default callers never reach | ||||||||||||||||||||
| # this job (the `if` below is false), so their permissions are untouched. | ||||||||||||||||||||
| npm-publish-oidc: | ||||||||||||||||||||
| needs: [check-labels, detect-changes, bump-versions] | ||||||||||||||||||||
| if: inputs.use-oidc == true | ||||||||||||||||||||
| runs-on: ${{ inputs.use-blacksmith && 'blacksmith-4vcpu-ubuntu-2404' || 'ubuntu-latest' }} | ||||||||||||||||||||
| steps: | ||||||||||||||||||||
| - uses: actions/checkout@v5 | ||||||||||||||||||||
| with: | ||||||||||||||||||||
| ref: ${{ github.ref_name }} | ||||||||||||||||||||
| fetch-depth: 0 | ||||||||||||||||||||
|
Comment on lines
+220
to
+223
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. Disable checkout credential persistence in the OIDC publish job ( The Suggested fix - uses: actions/checkout@v5
with:
ref: ${{ github.ref_name }}
fetch-depth: 0
+ persist-credentials: false📝 Committable suggestion
Suggested change
🧰 Tools🪛 zizmor (1.25.2)[warning] 220-223: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false (artipacked) [error] 220-220: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy) (unpinned-uses) 🤖 Prompt for AI Agents |
||||||||||||||||||||
|
|
||||||||||||||||||||
| - name: Publish NPM Packages | ||||||||||||||||||||
| uses: photon-hq/buildspace/.github/blocks/publish-npm-packages@main | ||||||||||||||||||||
| with: | ||||||||||||||||||||
| changed-packages: ${{ needs.detect-changes.outputs.changed }} | ||||||||||||||||||||
| bun-version: ${{ inputs.bun-version }} | ||||||||||||||||||||
| tag: ${{ (inputs.prerelease || fromJSON(needs.check-labels.outputs.labels).prerelease) && 'beta' || inputs.npm-tag }} | ||||||||||||||||||||
| build-command: ${{ inputs.build-command }} | ||||||||||||||||||||
| root-build-command: ${{ inputs.root-build-command }} | ||||||||||||||||||||
| dry-run: ${{ inputs.dry-run }} | ||||||||||||||||||||
| npm-token: ${{ secrets.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.
🧩 Analysis chain
🏁 Script executed:
Repository: photon-hq/buildspace
Length of output: 157
🌐 Web query:
npm trusted publishing minimum node version 22.14.0 npm 11.5.1💡 Result:
To utilize npm trusted publishing, you must use npm CLI version 11.5.1 or later and Node.js version 22.14.0 or higher [1][2][3][4]. These minimum version requirements ensure compatibility with the OIDC-based authentication mechanism used to establish trust relationships between your package and CI/CD providers [1][3]. If your environment is running an older version of Node.js or npm, you can satisfy the requirement by manually updating npm within your CI/CD workflow before performing the publish operation, for example by running: npm install -g npm@latest [2][4][5] Alternatively, you can ensure your CI/CD runner is using an environment that includes these versions by default (e.g., Node.js 24+) [6][5].
Citations:
🏁 Script executed:
Repository: photon-hq/buildspace
Length of output: 7272
🏁 Script executed:
Repository: photon-hq/buildspace
Length of output: 3145
🌐 Web query:
Node.js 24 bundled npm version (npm CLI version) trusted publishing npm 11.5.1💡 Result:
Node.js 24 was released on May 6, 2025 [1][2], and shipped with npm 11.0.0 [3][2]. Node.js versions are bundled with specific minor versions of npm that evolve over the lifecycle of the release line through subsequent updates [4]. Regarding trusted publishing: - Trusted publishing is a security feature that allows developers to publish packages from CI/CD environments using OpenID Connect (OIDC) rather than long-lived authentication tokens [5]. - The official npm documentation explicitly states that trusted publishing requires npm CLI version 11.5.1 or later [5][6]. - Because Node.js 24 receives regular updates, the bundled npm version has been incremented beyond 11.5.1 in later releases [4]. For example, Node.js 24.14.0 included npm 11.9.0 [4], and Node.js 24.15.0 included npm 11.12.1 [4]. Therefore, users running a recent version of Node.js 24 will satisfy the npm version requirement for trusted publishing by default [5][7]. If you are using an earlier release of Node.js 24 that includes an npm version older than 11.5.1, you can update npm globally or within your CI/CD environment using the command:
npm install -g npm@latest[8][7]. Users can also use thenpm trustcommand, which was introduced to manage these relationships directly from the CLI [8][9].Citations:
Fix OIDC publish default Node runtime to meet npm trusted publishing requirements
The OIDC path runs
npm publish ... --provenance, but the action defaultsinputs.node-versionto20. npm trusted publishing requires Node >= 22.14.0 and npm CLI >= 11.5.1, so callers enabling OIDC without overridingnode-versioncan hit the “OIDC failed → fallback” path (or hard-fail ifnpm-tokenwasn’t provided).Suggested fix
node-version: description: '[string] Node.js version' required: false - default: '20' + default: '24'🤖 Prompt for AI Agents