Skip to content

ci(npm): publish with npm trusted publishing (OIDC), no stored token - #2077

Merged
lilyshen0722 merged 2 commits into
mainfrom
fix/npm-trusted-publishing
Oct 6, 2026
Merged

lilyshen0722 merged 2 commits into
mainfrom
fix/npm-trusted-publishing

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

Moves Publish npm packages to npm trusted publishing (OIDC), so no publish token is stored anywhere.

Why now: the NPM_TOKEN granular token (secret updated 2026-08-29) stopped being accepted. The cli 0.1.82 publish failed with E404 Not Found - PUT https://registry.npmjs.org/@commonlyai%2fcli (run 36872618263). The last good publish was 2026-09-29 (run 36591777382). Three CLI fixes sit on main but not on npm: #2058 agent attribution, #2061 public codex attribution env, and #2067 the broker token kept out of claude's env.

What changes:

  • The token step is removed. Publish has no NODE_AUTH_TOKEN, and npm exchanges the job's OIDC id-token (id-token: write was already granted).
  • A step installs npm@^11.5.1, the minimum for trusted publishing; Node 22 ships npm 10.
  • The header comment is rewritten. The read-back script and its test update their pinned line refs: npm-publish.yml:143→142 (publish) and :69→75 (setup-node).

Verified: YAML parses. backend/__tests__/unit/scripts/npmPublishReadback.test.js passes, 22/22.

Order of operations: this merges first, which is harmless because publishing is already failing. Then each package (@commonlyai/cli, @commonlyai/mcp) gets a Trusted Publisher on npmjs.com: GitHub Actions, Team-Commonly/commonly, workflow npm-publish.yml. Then workflow_dispatch with package=all. After that, the NPM_TOKEN secret can be deleted.

Gate: Vera.

🤖 Generated with Claude Code

https://claude.ai/code/session_013geJsV4RJMujdvpf3JV2Cv

lilyshen0722 and others added 2 commits October 1, 2026 16:24
The NPM_TOKEN granular token (set 2026-08-29) stopped being accepted: cli 0.1.82
failed with E404 on PUT (run 36872618263), so three CLI security fixes are on main
but not on npm. Trusted publishing removes the token entirely. The job installs
npm >= 11.5.1 and keeps id-token: write; provenance is automatic.

Line references to npm-publish.yml in the read-back script and its test move
143 -> 142 (publish) and 69 -> 75 (setup-node).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013geJsV4RJMujdvpf3JV2Cv
… without a usable OIDC identity

Vera 76335: setup-node@v4 with registry-url writes _authToken=${NODE_AUTH_TOKEN} to the
runner npmrc; npm reads a present-but-empty token as configured auth, skips the OIDC
exchange and fails E404 (fixed only in setup-node v7). npmjs.org is npm's default, so
the registry-url line is removed. Vera 76338: a guard step names the failure when the
id-token is missing or any npmrc still carries _authToken. Line refs: publish 142->156,
setup-node 75->80.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013geJsV4RJMujdvpf3JV2Cv

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Vera — verification gate, head 857d38c3

CLEARED. The hold from my earlier verdict is lifted.

The fix is in, and it is the right layer

registry-url survives only as comment text (:75). I checked for a live key specifically (^ *registry-url:) rather than a bare substring, since a live one would be the whole defect returning — none.

The guard, exercised rather than read

I extracted the Refuse to publish without a usable OIDC identity step verbatim from this head and ran it under Actions' own shell flags (bash --noprofile --norc -eo pipefail), in a sandboxed HOME:

case result
clean runner, ACTIONS_ID_TOKEN_REQUEST_URL set exit 0
$HOME/.npmrc carries _authToken exit 1, names the file
./.npmrc carries _authToken exit 1, names the file
$NPM_CONFIG_USERCONFIG carries _authToken exit 1, names the file
ACTIONS_ID_TOKEN_REQUEST_URL unset exit 1, named

The last three are the original defect simulated — I wrote setup-node's exact line into an npmrc rather than running the action, since I cannot drive a runner from here. Stated as simulated, not observed.

The trailing true is load-bearing. On a clean runner the loop body's final AND-list is false; without the true that trips errexit and fails an otherwise-fine publish. So that line has a measured reason to exist, and removing it as noise would break releases silently.

Everything else at this head

  • Guard placement correct: :139, before Install (:148) and Publish (:152).
  • Both moved line references accurate: :80 is actions/setup-node@v4, :156 is npm publish --provenance --access public.
  • permissions: id-token: write retained; triggers remain push on main (path-filtered) plus workflow_dispatch, with no pull_request — a fork cannot reach the publish path.
  • npmPublishReadback.test.js 22/22, run at this head.
  • Delta from the head I held is exactly the registry-url removal, the comment, the guard step, and the three line-reference updates.

One residual, direction-safe

grep -q '_authToken' matches a token for any registry, so a runner carrying an unrelated ~/.npmrc fails the publish by name. Loud and wrong beats silent and wrong, so I would leave it — but it should not be a surprise when it happens.

Why the earlier hold needed measuring rather than citing

npm's own documented example also sets registry-url, and actions/setup-node#1551 was closed by a maintainer reporting a successful OIDC publish "even with the dummy token present". Both pointed away from the defect. What settled it was grepping the sentinel XXXXX-XXXXX-XXXXX-XXXXX in each published dist/setup/index.js, with a control string that correctly returned zero: present in v4 and v6, absent in v7. The fix (#1558) shipped only on the v7 line.

@lilyshen0722
lilyshen0722 added this pull request to the merge queue Oct 6, 2026
Merged via the queue into main with commit dab6baa Oct 6, 2026
18 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.

1 participant