Commit fbd17d9
Alain Picard
Adjusted based on OpenRouter extensive rework.
Their comments:
Latest commit:
Upgrade npm to support OIDC Trusted Publishing (OpenRouterTeam#231)
npm v10.8.2 (bundled with Node 20.x) predates Trusted Publishing support.
npm CLI v11.5.1+ is required for OIDC authentication with --provenance flag.
Evidence: CI publish failed with ENEEDAUTH despite id-token: write and
correct workflow setup. npm fell back to token auth and found none.
Add explicit npm upgrade step before publish to ensure OIDC works.
Previous:
Migrate npm OIDC (OpenRouterTeam#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 61b26bb commit fbd17d9
3 files changed
+108
-24
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
6 | 11 | | |
7 | | - | |
| 12 | + | |
| 13 | + | |
8 | 14 | | |
| 15 | + | |
9 | 16 | | |
10 | | - | |
11 | | - | |
| 17 | + | |
12 | 18 | | |
| 19 | + | |
13 | 20 | | |
14 | | - | |
15 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
16 | 24 | | |
17 | 25 | | |
18 | 26 | | |
19 | 27 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
25 | 41 | | |
26 | | - | |
27 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
28 | 63 | | |
29 | | - | |
| 64 | + | |
30 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
31 | 73 | | |
32 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
5 | 11 | | |
6 | 12 | | |
7 | 13 | | |
| |||
20 | 26 | | |
21 | 27 | | |
22 | 28 | | |
23 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
24 | 33 | | |
25 | 34 | | |
26 | 35 | | |
27 | 36 | | |
28 | 37 | | |
29 | 38 | | |
30 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
31 | 46 | | |
32 | 47 | | |
33 | 48 | | |
34 | 49 | | |
35 | 50 | | |
36 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
37 | 54 | | |
38 | 55 | | |
39 | | - | |
| 56 | + | |
40 | 57 | | |
41 | 58 | | |
42 | 59 | | |
| |||
56 | 73 | | |
57 | 74 | | |
58 | 75 | | |
59 | | - | |
| 76 | + | |
| 77 | + | |
60 | 78 | | |
61 | 79 | | |
62 | 80 | | |
| |||
0 commit comments