Skip to content

Commit 670825a

Browse files
Add documentation for publishing to npm with Trusted Publisher (OIDC) (#1536)
1 parent 48b55a0 commit 670825a

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ If the runner is not able to access github.com, any Nodejs versions requested du
249249
- [Publishing to npmjs and GPR with npm](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-npm)
250250
- [Publishing to npmjs and GPR with yarn](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-yarn)
251251
- [Using private packages](docs/advanced-usage.md#use-private-packages)
252+
- [Publishing to npm with Trusted Publisher (OIDC)](docs/advanced-usage.md#publishing-to-npm-with-trusted-publisher-oidc)
252253
- [Using private mirror](docs/advanced-usage.md#use-private-mirror)
253254

254255
## Recommended permissions

docs/advanced-usage.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,45 @@ To access private GitHub Packages within the same organization, go to "Manage Ac
475475

476476
Please refer to the [Ensuring workflow access to your package - Configuring a package's access control and visibility](https://docs.github.com/en/packages/learn-github-packages/configuring-a-packages-access-control-and-visibility#ensuring-workflow-access-to-your-package) for more details.
477477

478+
## Publishing to npm with Trusted Publisher (OIDC)
479+
480+
npm supports Trusted Publishers, enabling packages to be published from GitHub Actions using OpenID Connect (OIDC) instead of long-lived npm tokens. This improves security by replacing static credentials with short-lived tokens, reducing the risk of credential leakage and simplifying authentication in CI/CD workflows.
481+
482+
### Requirements
483+
484+
Trusted publishing requires a compatible npm version:
485+
486+
* **npm ≥ 11.5.1 (required)**
487+
* **Node.js 24 or newer (recommended)** — includes a compatible npm version by default
488+
489+
> If npm is below 11.5.1, publishing will fail even if OIDC permissions are correctly configured.
490+
491+
You must also configure a **Trusted Publisher** in npm for your package/scope that matches your GitHub repository and workflow (and optional environment, if used).
492+
493+
### Example workflow
494+
495+
```yaml
496+
permissions:
497+
contents: read
498+
id-token: write # Required for OIDC
499+
500+
steps:
501+
- uses: actions/checkout@v6
502+
503+
- uses: actions/setup-node@v6
504+
with:
505+
node-version: '24'
506+
registry-url: 'https://registry.npmjs.org'
507+
508+
- run: npm ci
509+
- run: npm run build --if-present
510+
- run: npm publish
511+
```
512+
513+
> **Note**: If the Trusted Publisher configuration (GitHub owner/repo/workflow file, and optional environment) does not match the workflow run identity exactly, publishing may fail with **E404 Not Found** even if the package exists on npm.
514+
515+
For more details, see the [npm Trusted Publishers documentation](https://docs.npmjs.com/trusted-publishers) and the [GitHub Actions OpenID Connect (OIDC) overview](https://docs.github.com/en/actions/concepts/security/openid-connect).
516+
478517
## Use private mirror
479518

480519
It is possible to use a private mirror hosting Node.js binaries. This mirror must be a full mirror of the official Node.js distribution.

0 commit comments

Comments
 (0)