Skip to content

Conversation

@daniel-samson
Copy link
Owner

@daniel-samson daniel-samson commented Dec 8, 2025

Summary

Enable npm trusted publishing with OpenID Connect (OIDC) by adding the required permissions to the GitHub Actions publish workflow.

What is npm Trusted Publishing?

npm trusted publishing allows packages to be published directly from CI/CD workflows without storing long-lived authentication tokens. Instead:

  1. GitHub Actions generates a short-lived, cryptographically-signed OIDC token
  2. The token is specific to this workflow execution only
  3. The npm CLI automatically detects and uses the token for authentication
  4. The token cannot be extracted, reused, or leaked

Changes Made

publish.yml Updates

Added job-level permissions to the publish job:

permissions:
  id-token: write    # Allow OIDC token generation
  contents: read     # Allow reading repository contents

Added comment explaining automatic OIDC handling by npm CLI.

Security Benefits

Eliminates token exposure risk - No long-lived tokens stored in secrets
Automatic provenance - npm CLI v11.5.1+ automatically generates package provenance attestations
Unique per-publish - Each publish uses a different, short-lived token
No manual rotation - Tokens are automatically managed by GitHub Actions
Cannot be reused - Tokens are cryptographically bound to specific workflows

How It Works

  1. User has already configured a trusted publisher on npmjs.com
  2. When the publish workflow runs, GitHub Actions generates an OIDC token
  3. The npm CLI detects the token and automatically uses it (no env vars needed)
  4. Package is published with provenance attestation
  5. Token is automatically revoked after use

Prerequisites Verified

✅ npm CLI v11.5.1 or later (already in use via node 22.x)
✅ GitHub-hosted runners (using ubuntu-latest)
✅ Trusted publisher configured on npmjs.com (user confirmed)
✅ Standard node_modules/.bin/npm available in workflow

Testing

This change only adds permissions - the actual OIDC token handling is automatic in npm CLI v11.5.1+. The workflow will continue to work with the fallback NPM_AUTH_TOKEN for older npm versions, while newer npm versions will prioritize the OIDC token.

References

🤖 Generated with Claude Code


Note

Add id-token: write and contents: read permissions to the publish job in .github/workflows/publish.yml to enable npm trusted publishing via OIDC.

  • CI/CD:
    • Publish workflow (.github/workflows/publish.yml): Add job-level permissions id-token: write and contents: read to enable npm trusted publishing via OIDC.

Written by Cursor Bugbot for commit db5674a. This will update automatically on new commits. Configure here.

Enable npm trusted publishing with OpenID Connect (OIDC) by adding the
required permissions to the publish workflow.

**What is npm Trusted Publishing?**
npm trusted publishing allows secure publishing of packages directly from
CI/CD workflows without storing long-lived npm authentication tokens. Instead,
GitHub Actions generates short-lived, cryptographically-signed OIDC tokens
that are specific to each workflow execution and cannot be reused.

**Changes Made:**
- Add `id-token: write` permission to enable OIDC token generation
- Add `contents: read` permission for workflow to read repository contents
- Add comment explaining automatic OIDC handling by npm CLI v11.5.1+

**Security Benefits:**
- ✅ Eliminates long-lived token exposure risk
- ✅ Automatic package provenance attestation
- ✅ Each publish uses unique, short-lived tokens
- ✅ No manual token rotation needed
- ✅ Tokens cannot be extracted or reused

**Prerequisites:**
- npm CLI v11.5.1 or later (already in use)
- Trusted publisher configured on npmjs.com (user has already set this up)
- GitHub-hosted runners only (currently using ubuntu-latest ✓)

**How It Works:**
When the workflow runs, the npm CLI automatically detects the OIDC token
generated by GitHub Actions and uses it for authentication. No additional
environment variables or token storage needed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@daniel-samson daniel-samson merged commit dec9daa into main Dec 8, 2025
4 checks passed
@daniel-samson daniel-samson deleted the ci/add-npm-trusted-publishing branch December 8, 2025 18:28
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is being reviewed by Cursor Bugbot

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

if: github.event_name == 'push' && ( github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' )
permissions:
id-token: write
contents: read
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Insufficient permissions break GitHub release creation

The permissions block sets contents: read, but the merge-release action needs contents: write to create GitHub releases and tags. When job-level permissions are explicitly defined, GitHub Actions only grants those specific permissions—all defaults are revoked. Before this change, the workflow used default permissions which include write access. This change will cause release creation to fail with a permission denied error.

Fix in Cursor Fix in Web

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants