Skip to content

Promote npm trusted publisher #201

Open

Description

@sxzz

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:

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:

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:

  1. Connect your GitHub repository to your existing npm package at https://www.npmjs.com/package/<your-package>/access
  2. Upgrade npm to the latest version (11.5.1+) if you're using npm or pnpm.
  3. Safely remove npm tokens
  4. [optional] Disallow tokens and trusted publishing will still work
Image

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: true

I 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.

Read more

Activity

  1. posva commented on Aug 15, 2025

    @posva

    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?

  2. sxzz commented on Aug 15, 2025

    @sxzz
    Author

    @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?

  3. JounQin commented on Aug 15, 2025

    @JounQin

    I haven't migrated due to changesets/changesets#1152 (comment)


    Update: set env NPM_TOKEN: '' is the workaround

  4. outslept commented on Aug 15, 2025

    @outslept

    @sxzz You should be able to use (will get you 11.5.2 currently)

     - name: Update npm
       run: npm install -g npm@latest

    So there shouldn't be a need to tie to pnpm

  5. posva commented on Aug 15, 2025

    @posva

    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

  6. sxzz commented on Aug 15, 2025

    @sxzz
    Author

    @outslept Not tied to any specific package manager; pnpm is used here merely as an example.

  7. sxzz commented on Aug 15, 2025

    @sxzz
    Author

    @posva Both Yarn and pnpm actually use npm for publishing packages, so the versions of Yarn or pnpm are essentially irrelevant.

  8. SuperchupuDev commented on Aug 15, 2025

    @SuperchupuDev

    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

  9. SuperchupuDev commented on Aug 15, 2025

    @SuperchupuDev

    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

    Image
  10. wesleytodd commented on Aug 15, 2025

    @wesleytodd

    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 provenance is 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

  11. sxzz commented on Aug 15, 2025

    @sxzz
    Author

    @SuperchupuDev Thanks for your tips! Updated migration guidance.

  12. wojtekmaj commented on Aug 15, 2025

    @wojtekmaj

    @posva Both Yarn and pnpm actually use npm for publishing packages, so the versions of Yarn or pnpm are essentially irrelevant.

    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.

  13. sxzz commented on Aug 15, 2025

    @sxzz
    Author

    @wojtekmaj Oh, that's not correct—it's only applicable to pnpm.

  14. added a commit that references this issue on Aug 19, 2025
  15. added a commit that references this issue on Aug 20, 2025
  16. 9 remaining items

  17. igalklebanov commented on Sep 19, 2025

    @igalklebanov

    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.
    pnpm updated with min release age 1d.

  18. sxzz commented on Sep 22, 2025

    @sxzz
    Author

    For many package maintainers, I’ve created a userscript that automatically fills in repository information of trusted publisher (using the required repository field from package.json) and enables 2FA by default. You can install it using Tampermonkey or Violentmonkey. Thanks to @antfu's idea.

  19. antfu commented on Sep 23, 2025

    @antfu

    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.

  20. danielroe commented on Sep 23, 2025

    @danielroe

    great news: https://github.blog/security/supply-chain-security/our-plan-for-a-more-secure-npm-supply-chain

    To support these changes and further improve the security of the npm ecosystem, we will:

    • Deprecate legacy classic tokens.
    • Deprecate time-based one-time password (TOTP) 2FA, migrating users to FIDO-based 2FA.
    • Limit granular tokens with publishing permissions to a shorter expiration.
    • Set publishing access to disallow tokens by default, encouraging usage of trusted publishers or 2FA enforced local publishing.
    • Remove the option to bypass 2FA for local package publishing.
    • Expand eligible providers for trusted publishing.
  21. sonofmagic commented on Sep 25, 2025

    @sonofmagic

    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.我在 的脚本公司做了 https://github.com/antfu/open-packages-on-npm,您可以在其中一次打开所有 monorepo 包的设置页面。

    In that regards, Slidev and UnoCSS are all on Trusted Publisher from now.在这方面,Slidev 和 UnoCSS 从现在开始都在 Trusted Publisher 上。

    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.

    Image

    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?

  22. sxzz commented on Sep 25, 2025

    @sxzz
    Author

    We need to publish the new package using the npm token first (local or CI), and then enable the trusted publisher after publishing.

  23. ghiscoding commented on Sep 25, 2025

    @ghiscoding

    We need to publish the new package using the npm token first (local or CI), and then enable the trusted publisher after publishing.

    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

  24. ghiscoding commented on Sep 27, 2025

    @ghiscoding

    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

  25. ghiscoding commented on Feb 11, 2026

    @ghiscoding

    hey guys, probably worth to know that there's an npm CLI PR to add a new npm trust command 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.

    A new command / set of registry api endpoints that allows a user to add, remove and check the Trusted configurations between npm's registry and Trusted Publishers.

    This command will allow maintainers to have a mechanism for managing their configurations outside of the npm website.

    A lot of maintainers have mentioned how they'd like to be able to set Trusted Publishing "in bulk" and this solution allows maintainers to setup a simple bash script to loop over and set these configurations for many packages / repositories quickly.

    See PR for mode usage demos: npm/cli#8899

  26. sxzz commented on Feb 11, 2026

    @sxzz
    Author

    Oh, thank goodness!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions