Repository navigation
Description
Motivation
npm Trusted Publishing is now generally available, allowing package owners to publish npm packages via CI without manually generating npm tokens. This method greatly reduces the risk of token leaks, which has been a recurring issue in the past. For more details, see:
- https://github.blog/changelog/2025-07-31-npm-trusted-publishing-with-oidc-is-generally-available/
- https://docs.npmjs.com/trusted-publishers/
Current Status
I've added a provenance tab to node-modules-inspector, where you can view the provenance status of all my packages: https://pkg.sxzz.dev/grid/provenance
Some packages have provenance enabled but are not yet using Trusted Publishing, including:
- Vue / Vite, /cc @yyx990803 @edison1105 @patak-dev @sapphi-red
- Nuxt, /cc @danielroe
- Vitest / UnoCSS / Shiki / VueUse / Slidev, /cc @antfu @sheremet-va @zyyv
- Vitest
- UnoCSS
- Shiki ci: use oidc for npm publish & codecov shikijs/shiki#1068
- VueUse
- Slidev
- Rolldown, /cc @hyf0
- Oxc by @Boshen
- tinyexec by @43081j
- tinyglobby by @SuperchupuDev
- publint by @bluwy
- eslint-plugin-import-x / unrs-resolver / synckit by @JounQin
- List of the most popular npm packages: https://github.com/sxzz/npm-top-provenance
Migration
Note
This proposal applies only to packages already published via CI. If your package does not yet use CI for publishing, you will need to set up CI workflows before migrating to Trusted Publishing.
Migrating is straightforward for packages already published via CI:
- Connect your GitHub repository to your existing npm package at
https://www.npmjs.com/package/<your-package>/access - Upgrade npm to the latest version (11.5.1+) if you're using npm or pnpm.
- Safely remove npm tokens
- [optional] Disallow tokens and trusted publishing will still work
For reference, see this example commit:
- name: Publish to NPM
- run: npm publish
+ run: npm i -g npm@latest && npm publish # or pnpm publish
- env:
- NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
- NPM_CONFIG_PROVENANCE: trueI also wrote a reusable workflow: https://github.com/sxzz/workflows/blob/main/examples/release.yml
Automation
Anthony created a tool that lets you open the settings pages for all your monorepo packages at once.
I’ve also developed a userscript that automatically fills in repository information on the trusted publisher form (using the required repository field from package.json) and enables 2FA by default. You can install it using Tampermonkey or Violentmonkey. Thanks to @antfu for the inspiration!
Tip
If you maintain a large monorepo, connecting all packages can be time-consuming, and the user experience is currently lacking. I tried to write a script to automate repository connections, but was blocked by Cloudflare verification. Hopefully, npm will offer this feature via API in the future.
Activity
posva commentedon Aug 15, 2025
Why is the npm i -g npm? Is it to get the latest version of npm? Isn’t this done at the image or action level?
sxzz commentedon Aug 15, 2025
@posva The built-in npm updates alongside Node.js. Currently, Node.js LTS is at v22.18, which comes with npm v10.9.3. However, Trusted Publisher requires npm version 11.5.1 or higher. Do you have any effective solutions for upgrading or managing npm version on CI?
JounQin commentedon Aug 15, 2025
I haven't migrated due to changesets/changesets#1152 (comment)
Update: set env
NPM_TOKEN: ''is the workaroundoutslept commentedon Aug 15, 2025
@sxzz You should be able to use (will get you 11.5.2 currently)
So there shouldn't be a need to tie to pnpm
posva commentedon Aug 15, 2025
I don’t have a better solution. I thought there would be a different way to upgrade. It looks funny because after it, it uses pnpm 🤪 some might think it’s a typo
I would like to use this method of publishing too. Mono repos need some extra configuration
sxzz commentedon Aug 15, 2025
@outslept Not tied to any specific package manager; pnpm is used here merely as an example.
sxzz commentedon Aug 15, 2025
@posva
Both Yarn andpnpm actually use npm for publishing packages, so the versions ofYarn orpnpm are essentially irrelevant.SuperchupuDev commentedon Aug 15, 2025
tinyglobby enabled trusted publishing as soon as it could for its next version SuperchupuDev/tinyglobby@b85c139
since ci installs node 24, the right npm version is automatically used and there's no need to manually install it
SuperchupuDev commentedon Aug 15, 2025
FYI after enabling trusted publishing, you can restrict publishing access to disallow all tokens and trusted publishing will still work, we talked about it in e18e (thread link) and @dominikg tested that it works
wesleytodd commentedon Aug 15, 2025
While provenance is not "bad" (other than being vendor leverage to signal security when it is actually just security theater), please include a call out that
provenanceis worthless without 2fa in your publishing workflows. Which is a feature github has no support for. As it stands, a maintainer with good hygiene and forced 2fa on a package is much more effective protection than a CI publish with provenance, especially if you can reproduce the build.see our discussion with a bit more nuance here: https://bsky.app/profile/notwes.bsky.social/post/3lwgx6llchc2o
sxzz commentedon Aug 15, 2025
@SuperchupuDev Thanks for your tips! Updated migration guidance.
wojtekmaj commentedon Aug 15, 2025
Are you sure about that? Yarn has recently added support for provenance in yarnpkg/berry#6750 and trusted publisher support is being tracked in yarnpkg/berry#6831.
sxzz commentedon Aug 15, 2025
@wojtekmaj Oh, that's not correct—it's only applicable to pnpm.
ci: use trusted publisher
ci: use trusted publishing
9 remaining items
igalklebanov commentedon Sep 19, 2025
I have setup trusted publishing in Kysely. kysely-org/kysely@002229f
Would love a review.
The environment requires a maintainer's review to start, with "prevent self-review" on.
2 maintainers, 2FA'd in NPM and GitHub. NPM publishing set to 2FA only.
All external contributions require workflow approval.
pnpmupdated with min release age 1d.sxzz commentedon Sep 22, 2025
For many package maintainers, I’ve created a userscript that automatically fills in repository information of trusted publisher (using the required
repositoryfield frompackage.json) and enables 2FA by default. You can install it using Tampermonkey or Violentmonkey. Thanks to @antfu's idea.antfu commentedon Sep 23, 2025
I made https://github.com/antfu/open-packages-on-npm in the company of @sxzz's script, where you can open the setting page of all your monorepo packages at once.
In that regards, Slidev and UnoCSS are all on Trusted Publisher from now.
danielroe commentedon Sep 23, 2025
great news: https://github.blog/security/supply-chain-security/our-plan-for-a-more-secure-npm-supply-chain
sonofmagic commentedon Sep 25, 2025
open-packages-on-npm is very useful, and I look forward to npm opening up APIs in the future to further optimize support for monorepos.
But I have a question:
if I add a new subpackage in a monorepo, and other packages depend on it, will this cause the release to fail?
Because at that point the npm token is no longer available, but the new subpackage hasn’t been set up with a Trusted Publisher yet?
sxzz commentedon Sep 25, 2025
We need to publish the new package using the npm token first (local or CI), and then enable the trusted publisher after publishing.
ghiscoding commentedon Sep 25, 2025
This is indeed important to note that the user must have publish the new package(s) at least once before OIDC becomes available. Side note, there's an issue open on NPM CLI to hopefully drop this requirement in the future, you guys could maybe upvote it to get more traction maybe, see npm/cli#8544
ghiscoding commentedon Sep 27, 2025
hey guys, happy to mention that OIDC Trusted Publishing is now supported in both Lerna and Lerna-Lite (I maintain the latter).
This should help with monorepos publishing, I've tried with my own monorepos and it's all working nicely 🚀
See details below
Lerna@9.0.0 (new major version)
with a working demo: https://github.com/JamesHenry/lerna-v9-oidc-publishing-example
Lerna-Lite@4.9.0
with a working demo: https://github.com/lerna-lite-test/oidc
Credit goes to James who brought it first in Lerna and I later reimplemented it in Lerna-Lite (which I maintain)
I also hope that they will eventually add 2FA (OTP) because I also do find it less secure if for example a user takes control of my GitHub Account, then such user could in theory change any code and then push a release!? I was using OTP with Provenance before, which was using long live token and I know that was bad, but still it was protected with an OTP.
I also find it super lengthy to configure OIDC for every monorepo package one-by-one, a global setting would be nice to have eventually. It's been asked in the original OIDC Discussion
chore(ci): switch to use OIDC (trusted publisher)
chore(ci): switch to use OIDC (trusted publisher)
chore(ci): switch to use OIDC (trusted publisher)
chore(ci): switch to use OIDC (trusted publisher)
chore(ci): switch to use OIDC (trusted publisher)
ghiscoding commentedon Feb 11, 2026
hey guys, probably worth to know that there's an npm CLI PR to add a new
npm trustcommand that just got merged. So I assume it will be available in the next week or so (it's scheduled for v11.10.0 I think). I find this one pretty exciting since it will finally provide a way to do trusted publishing bulk changes.See PR for mode usage demos: npm/cli#8899
sxzz commentedon Feb 11, 2026
Oh, thank goodness!