Commit 563f4ab
authored
Migrate npm OIDC (#230)
* refactor: migrate to OIDC for npm package publishing
Replace token-based authentication with OpenID Connect (OIDC) for enhanced security:
- Remove NPM_TOKEN from changesets action environment
- Enable automatic provenance generation (NPM_CONFIG_PROVENANCE)
- Set NODE_AUTH_TOKEN to empty string to force OIDC authentication
- Keep diagnostic step for troubleshooting auth issues
This requires configuring npm Trusted Publisher on npmjs.com for the repository.
* refactor: restructure publish workflow to support OIDC properly
Split changesets/action into versioning-only step and separate publish step
to avoid .npmrc token mutation that would block OIDC. This ensures npm uses
Trusted Publisher authentication instead of legacy token-based auth.
Key changes:
- changesets/action now only runs version step (no publish input)
- Added OIDC preflight step to scrub any auth tokens from .npmrc before publishing
- Separated publish into dedicated step with pnpm changeset-publish
- Added post-mortem diagnostics for troubleshooting publish failures
The id-token: write permission remains enabled for OIDC token generation.
Registry setup and package.json publish script already include provenance.
* fix: harden OIDC workflow with publish gate and comprehensive preflight
Address three critical risks identified during code review:
1. Gate publish step to run only when no changesets exist
- Prevents wasteful runs and log noise when version PR is created
- Ensures publish only runs on merge commits (when hasChangesets == 'false')
- .github/workflows/publish.yaml:74
2. Harden preflight to scrub all .npmrc locations and auth forms
- Iterate over all potential locations: NPM_CONFIG_USERCONFIG, ~/.npmrc, .npmrc
- Remove both registry-scoped (_authToken, _auth=) and global (always-auth) forms
- Prevents stray .npmrc from blocking OIDC authentication
- .github/workflows/publish.yaml:45-52
3. Make whoami check robust with exit code instead of grep
- Check npm whoami exit code (0 = logged in, non-zero = not logged in)
- Avoids reliance on fragile message matching across npm versions
- Verify registry config (including @openrouter scope)
- .github/workflows/publish.yaml:62-71
4. Enhance post-mortem diagnostics
- Log registry configuration for both global and @openrouter scope
- Redact .npmrc contents to aid forensics without exposing secrets
- Check all three potential .npmrc locations
- .github/workflows/publish.yaml:92-101
With these changes, the workflow is hardened against OIDC authentication failures.
* refine: use extended regex patterns for comprehensive .npmrc token scrubbing
Improve sed patterns to handle edge cases in token removal:
- Registry-scoped tokens: Allow optional whitespace around = sign
sed -i -E '/\/\/registry\.npmjs\.org\/:(_authToken|_auth)\s*=/d'
- Global tokens: Match _authToken or _auth anywhere on a line with leading whitespace
sed -i -E '/^\s*(_authToken|_auth)\s*=/d'
- Global always-auth: Case-insensitive with optional spacing
sed -i -E '/^\s*[Aa]lways-[Aa]uth\s*=/d'
This closes the gap where npm could treat whitespace-padded or variant token
lines as a signal to use legacy token auth instead of OIDC. Extended regex (-E)
enables more flexible matching without sacrificing readability.
Addresses edge case identified during workflow review.1 parent cae7fb4 commit 563f4ab
1 file changed
+67
-37
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
33 | 41 | | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
52 | 54 | | |
53 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
54 | 69 | | |
55 | | - | |
56 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
57 | 88 | | |
58 | | - | |
59 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
60 | 92 | | |
61 | | - | |
62 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
63 | 103 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
| 104 | + | |
| 105 | + | |
0 commit comments