Configure NPM publishing with OIDC trusted publishers#28
Conversation
Co-authored-by: empeje <11813607+empeje@users.noreply.github.com>
Co-authored-by: empeje <11813607+empeje@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR migrates the NPM publishing workflow from token-based authentication to OIDC (OpenID Connect) authentication using NPM's Trusted Publishers feature. This improves security by eliminating the need for long-lived NPM tokens stored as GitHub secrets.
Changes:
- Added OIDC permissions (
id-token: writeandcontents: read) to the publish job - Switched publish command to use
npm publish --provenance --access publicwith provenance attestations - Removed
NODE_AUTH_TOKENenvironment variable dependency
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| run: yarn publish --access public --non-interactive | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| run: npm publish --provenance --access public |
There was a problem hiding this comment.
The workflow is using npm to publish, but the project consistently uses yarn everywhere else (install, build, cache configuration). While npm and yarn are interoperable, this inconsistency could be confusing and may cause unexpected behavior. Consider changing this to yarn publish --provenance --access public to maintain consistency with the rest of the workflow and project configuration.
| run: npm publish --provenance --access public | |
| run: yarn publish --provenance --access public |
There was a problem hiding this comment.
The OIDC permissions and npm publish --provenance change is directionally correct, but switching from yarn publish to npm publish risks release failures if versioning isn’t explicitly handled for the release.created trigger. The workflow also pins Node 16 (EOL), which is a compatibility and supply-chain risk for CI/CD publishing. Finally, the workflow now mixes Yarn for build with npm for publish; that can be OK, but it should be made intentional or standardized to avoid subtle publish-time differences.
Additional notes (3)
- Compatibility |
.github/workflows/test-and-publish.yml:55-58
Switching fromyarn publishtonpm publishcan break releases if the package version isn’t bumped before publishing.yarn publishcommonly handled versioning prompts/behavior, whilenpm publishwill fail withYou cannot publish over the previously published versionsunless your release process already updatespackage.jsonversion.
Given this workflow triggers on release.created, it’s worth making the version source explicit (tag-driven) or ensuring the version is already set in the repo at that ref.
- Compatibility |
.github/workflows/test-and-publish.yml:41-43
You’re still using Node.js16, which is EOL. Even if it currently works, provenance/SLSA-related tooling and ecosystem packages are increasingly assuming newer runtimes, and this can become a surprise breakage for releases.
Upgrading the workflow runtime reduces supply-chain risk and avoids sudden deprecations in GitHub-hosted runners/actions.
- Maintainability |
.github/workflows/test-and-publish.yml:43-43
Thepublishjob usesnpm publishbut dependency installation/build uses Yarn. That’s fine, but it increases the chance of publishing with the wrong lock/tooling expectations (e.g., ifprepare/prepublishOnlyscripts rely on Yarn assumptions). Also,npm publishwill use.npmrc/npm config;setup-nodesets up auth/registry config, but Yarn-specific config won’t apply.
If you keep mixed tooling, it’s worth making it intentional and stable.
Summary of changes
Workflow updates for NPM Trusted Publishing (OIDC)
-
Added job-level
permissionsto thepublishjob:contents: readid-token: write
-
Switched the publish step from Yarn + long-lived token auth:
yarn publish ...withNODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
to npm CLI with provenance:
npm publish --provenance --access public
-
Removed dependency on the
NPM_TOKENGitHub secret for publishing.
Migrates NPM publishing from long-lived
NPM_TOKENsecrets to GitHub Actions OIDC authentication with provenance attestations.Changes
id-token: writeandcontents: readto publish job for OIDC token generationnpm publish --provenance --access public(fromyarn publishwith token auth)NODE_AUTH_TOKENsecret dependency.github/PUBLISHING.mdwith trusted publisher configuration steps for npmjs.comSetup Required
Repository maintainer must configure trusted publisher at npmjs.com:
kulkultechtinyurl-clienttest-and-publish.ymlAfter configuration, releases will publish automatically with cryptographic build provenance.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
docs.npmjs.com/home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.