Skip to content

Comments

Fix - npm publish trusted publishers#67

Merged
alexpmule merged 2 commits intomainfrom
fix/npm-publish-trusted-publishers
Jan 6, 2026
Merged

Fix - npm publish trusted publishers#67
alexpmule merged 2 commits intomainfrom
fix/npm-publish-trusted-publishers

Conversation

@alexpmule
Copy link
Contributor

@alexpmule alexpmule commented Jan 6, 2026

🔐 Enable NPM Trusted Publishers (OIDC) for Secure Package Publishing

Problem

The package publishing workflow was failing with authentication errors:

npm notice Access token expired or revoked
npm error 404 Not Found - PUT https://registry.npmjs.org/@api-components%2fapi-navigation

Solution

Implements NPM Trusted Publishers using OpenID Connect (OIDC) authentication, which provides a more secure and maintainable approach than static tokens.

Changes Made

1. Added OIDC Permissions

permissions:
  contents: write
  id-token: write  # Required for NPM Trusted Publishers

This allows GitHub Actions to generate temporary, scoped tokens verified by NPM.

2. Updated Actions to v4

  • actions/checkout@v4 (from v2)
  • actions/setup-node@v4 (from v2)

These versions provide better support for provenance generation and OIDC workflows.

3. Added Provenance Flag

npm publish --provenance --access public

Generates a cryptographic signature that proves the package was published from this repository.

Benefits

Enhanced Security: Uses short-lived OIDC tokens instead of static secrets
No Token Expiration: Tokens are generated automatically per workflow run
Supply Chain Security: Provenance statements provide verifiable authenticity
Reduced Maintenance: No need to rotate or manage NPM tokens
Audit Trail: Cryptographically signed publish events

Testing Checklist

  • Workflow runs successfully on merge to main
  • Package publishes to npmjs.com with provenance
  • Verify provenance badge appears on package page
  • Confirm GitHub release is created with correct version

References & Documentation

NPM Trusted Publishers

GitHub Actions

Related Issues

How It Works

sequenceDiagram
    participant GHA as GitHub Actions
    participant NPM as NPM Registry
    
    GHA->>GHA: Generate OIDC token
    GHA->>NPM: Publish with provenance
    NPM->>NPM: Verify token signature
    NPM->>NPM: Check trusted publisher config
    NPM->>NPM: Validate repository match
    NPM-->>GHA: ✅ Publish successful
    NPM->>NPM: Store provenance statement
Loading

Post-Merge Verification

After merging, verify the provenance on the package page:

  1. Visit: https://www.npmjs.com/package/@api-components/api-navigation
  2. Look for the "Provenance" badge
  3. Click to view the attestation details
  4. Confirm it links back to this repository

Note: This workflow will still work with the NPM_TOKEN as a fallback if OIDC authentication is not available, but the primary authentication method is now via Trusted Publishers.

cc: @jarrodek - Thanks for setting up the Trusted Publishers configuration! 🎉

- Add OIDC permissions (id-token: write) for trusted publishing
- Update actions to v4 for better provenance support
- Add --provenance flag to npm publish command
- Leverages NPM Trusted Publishers config set up by @jarrodek

This removes the need for static NPM tokens and provides cryptographic
verification of package authenticity.
@alexpmule alexpmule merged commit 61a9f0e into main Jan 6, 2026
3 checks passed
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