X Tutup
Skip to content

feat: migrate to npm trusted publishing with OIDC#474

Merged
azu merged 7 commits intomasterfrom
oidc
Sep 8, 2025
Merged

feat: migrate to npm trusted publishing with OIDC#474
azu merged 7 commits intomasterfrom
oidc

Conversation

@azu
Copy link
Member

@azu azu commented Sep 8, 2025

Summary

This PR migrates the npm publishing process from traditional token-based authentication to OpenID Connect (OIDC) trusted publishing. This enhancement provides automatic package provenance, improved security through short-lived tokens, and verifiable build attestations for all published packages.

Key Changes

  • OIDC Authentication: Replaced long-lived NPM_TOKEN with GitHub's OIDC provider for secure, temporary authentication
  • Package Provenance: Enabled automatic provenance generation for all npm packages, providing cryptographic proof of build origin
  • Provenance Monitoring: Added automated workflow to track provenance status across all packages and provide visibility through PR comments

Motivation

Traditional npm tokens pose several security risks:

  • Long-lived credentials that can be compromised
  • No automatic link between published packages and their source code
  • Limited auditability of package origins

OIDC trusted publishing addresses these concerns by:

  • Using short-lived tokens that expire after each workflow run
  • Establishing cryptographic proof linking packages to their GitHub source
  • Enabling npm users to verify package authenticity through provenance attestations

Changes in Detail

1. Release Workflow Migration (.github/workflows/release.yml)

  • Added id-token: write permission to enable OIDC token generation
  • Added NPM_CONFIG_PROVENANCE: true environment variable for automatic provenance
  • Removed NPM_TOKEN and NODE_AUTH_TOKEN from secrets
  • Updated publish step to use OIDC authentication implicitly
  • Enhanced documentation with OIDC configuration details
  • Fixed template injection vulnerabilities identified by zizmor

2. Provenance Status Monitoring (.github/workflows/check-provenance.yml)

New workflow that:

  • Checks provenance status for all published packages
  • Runs on PRs that modify package configurations
  • Provides automated PR comments with provenance status
  • Sets commit status checks for visibility
  • Handles both published and unpublished packages gracefully

Security Benefits

  1. No Long-Lived Secrets: Eliminates the need for storing NPM_TOKEN in GitHub secrets
  2. Verifiable Builds: Users can verify packages were built and published from this repository
  3. Supply Chain Security: Provides transparency about package origins and build environment
  4. Automatic Rotation: Tokens are automatically rotated with each workflow run
  5. Template Injection Protection: Fixed potential security vulnerabilities in GitHub Actions scripts

Breaking Changes

None. This change is transparent to package consumers and maintains backward compatibility.

Test Plan

Manual Verification Required

  1. Release Process Validation

    • Trigger a test release on a feature branch
    • Verify OIDC authentication succeeds without npm token
    • Confirm packages are published with provenance badges on npm
  2. Provenance Check Workflow

    • Create a test PR modifying package.json
    • Verify the provenance check workflow runs and comments on the PR
    • Confirm the comment correctly identifies packages with/without provenance
  3. npm Registry Verification

    • After publishing, visit npm package pages
    • Verify the "Provenance" badge appears next to package versions
    • Click provenance link to confirm it shows correct GitHub repository and workflow
  4. Error Scenarios

    • Test workflow behavior if npm registry is unavailable
    • Verify graceful handling of unpublished packages
    • Confirm workflow continues if provenance check fails for individual packages

Migration Notes

  • The repository must be configured for OIDC publishing on npm (one-time setup per package)
  • Existing NPM_TOKEN secret can be removed after successful migration
  • First release with OIDC will establish the trusted publisher relationship

References

@github-actions

This comment was marked as outdated.

- Replace NPM_TOKEN with OIDC authentication
- Add id-token permission for GitHub Actions
- Enable npm provenance for published packages
- Add workflow to check package provenance status
- Fix template injection vulnerabilities
@github-actions
Copy link
Contributor

github-actions bot commented Sep 8, 2025

📦 NPM Package Status

Published Packages Missing OIDC Configuration

Configure OIDC for these packages:

Setup Instructions:

  1. Click each package link above
  2. Click "Add trusted publisher"
  3. Configure with:
    • Repository: honkit/honkit
    • Workflow: .github/workflows/release.yml
    • Environment: (leave empty)

@azu azu self-assigned this Sep 8, 2025
@azu azu added the Type: CI Changes to CI configuration files and scripts label Sep 8, 2025
azu and others added 6 commits September 8, 2025 20:54
Resolved conflicts:
- package.json: Updated lint-staged to v16, removed lerna dependency
- pnpm-lock.yaml: Regenerated after package.json changes
- lerna.json: Removed (following oidc branch approach)

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

Co-Authored-By: Claude <noreply@anthropic.com>
…g install

The prepublish script was running during pnpm install and cleaning the lib directory,
causing "Cannot find module '../lib/bin.js'" error in CI.

Changed to prepublishOnly so it only runs during actual npm publish.

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

Co-Authored-By: Claude <noreply@anthropic.com>
The single quotes in pnpm filter commands were not working on Windows PowerShell,
causing "No projects matched the filters" error in CI.

Changed to escaped double quotes for cross-platform compatibility.

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

Co-Authored-By: Claude <noreply@anthropic.com>
Removed commit-version script as it's no longer needed with the new CI workflow.

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

Co-Authored-By: Claude <noreply@anthropic.com>
@azu azu marked this pull request as ready for review September 8, 2025 12:48
@azu azu merged commit 811beca into master Sep 8, 2025
21 checks passed
@azu azu deleted the oidc branch September 8, 2025 12:55
@azu azu mentioned this pull request Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: CI Changes to CI configuration files and scripts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

X Tutup