fix(#1440): Support NPM OIDC tokens by not exporting default NODE_AUTH_TOKEN#1477
fix(#1440): Support NPM OIDC tokens by not exporting default NODE_AUTH_TOKEN#1477Satishchoudhary94 wants to merge 1 commit into
Conversation
…ODE_AUTH_TOKEN This change addresses issue actions#1440 where NPM OIDC authentication was broken because the action was exporting a fake NODE_AUTH_TOKEN value by default. NPM OIDC requires NODE_AUTH_TOKEN to either be unset or empty for proper authentication. The fix only exports NODE_AUTH_TOKEN if it was explicitly set by the user, allowing OIDC to work while maintaining backward compatibility for users who explicitly provide tokens. BREAKING CHANGE: Users who rely on the fake default token should now explicitly provide NODE_AUTH_TOKEN in their workflows or use OIDC authentication. Fixes actions#1440 Related: actions#1440
|
Lost an entire day debugging trusted publishing today when it was this secret token the entire time. The world will be a better place if this PR gets merged! |
|
@jrjohnson Thanks for confirming this helps! Appreciate the feedback 🙌 |
|
Hi @Satishchoudhary94, thank you for your contribution! @jrjohnson, @TheJefe, as discussed in the comments on issue #1440, we were able to successfully publish to npm using OIDC with the existing setup-node code. Could you please check and confirm if you are also able to do so on your end? @Satishchoudhary94 , could you kindly let us know whether these changes are still needed and share any specific use cases that required these file modifications? We truly appreciate your effort and look forward to hearing from you. Thanks! |
|
Hi everyone, Gentle reminder on this. Looking forward to your update when you have a moment. |
|
Hi @gowridurgad, thanks a lot for taking the time to check this. I went through this again carefully from my side. From what i’ve observed, this issue seems to depend on the environment. In cases where a default At the same time, I completely understand why it may be working fine in your setup if the variable isn’t being injected or is already unset, the issue won’t show up. So this change is mainly to make the behavior safer and more predictable: -->Avoid exporting a placeholder token by default This also aligns with feedback from users who had to manually unset If it helps, I’m happy to share a minimal repro workflow where this difference is visible. Totally open to suggestions or improvements here as well. Thanks again for the review!. |
|
Hi @Satishchoudhary94 , thanks for the reply. As per npm’s Trusted Publishing (OIDC) docs, the npm CLI should automatically detect an OIDC-capable environment and prefer OIDC for authentication, only falling back to token-based auth if needed. In our testing, OIDC publishing still succeeds even when a (dummy) NODE_AUTH_TOKEN is present. Could you please share the minimal repro repo when you get a chance? That will help us reproduce the behavior on our end and better understand what differs across environments. |
|
Hi @Satishchoudhary94 , quick reminder on this: could you please share the minimal repro repository when you have a moment? |
|
Hi @gowridurgad, Thanks for taking a closer look! i've created a minimal reproduction repository to demonstrate the behavior: Repository: https://github.com/Satishchoudhary94/setup-node-oidc-test Observations
From this setup, it looks like when a placeholder Even if OIDC works in some setups with a dummy token, this change aims to make the behavior more predictable and aligned with npm’s OIDC expectations:
Happy to adjust this further if there’s a better approach here. |
|
Hi @Satishchoudhary94, thanks for the detailed response. A few points from our side after reviewing it: The workflow run you shared is currently returning a 404 error, so we’re unable to access the run logs and validate the exact execution behavior from that link. We also reviewed your workflow setup and logs, and it appears there is no explicit npm publish step present in the workflow where the behavior is being demonstrated. Most of the available information seems to come from log statements rather than a complete publish execution flow. Additionally, we noticed that NODE_AUTH_TOKEN is being set in the environment, but based on npm’s OIDC design, it should not be required for OIDC-based authentication flows. Could you please try validating this again by strictly following the official npm Trusted Publishing (OIDC) From our investigation so far, OIDC continues to work correctly even when a dummy token is present, and we have not observed it impacting or blocking the OIDC authentication flow. Please refer to this comment for details: #1440 (comment). So at this point, other than scenarios involving environment cleanup, we have not been able to identify a concrete use case where the presence of a dummy token actually changes OIDC behavior. It would be helpful if you could further validate this on your side and share any specific workflow or scenario where OIDC is getting affected due to the dummy token. |
|
It's been a while but I think you may need to go back to Node versions before 24 to get this to fail easily @gowridurgad. What I can't remember is if that was because of the NPM version shipped or if it was node itself. That may help you reproduce on your end. |
|
Hi @gowridurgad, Thanks for the detailed feedback! I've addressed all three issues in the reproduction repo: Reproduction repo: https://github.com/Satishchoudhary94/setup-node-oidc-test Changes just pushed (commit 33d84df):
On the "OIDC works with dummy token" finding:The key distinction is between two publishing scenarios:
When npm 11.5.1+ checks If the internal test used a real cc @jrjohnson does this match the scenario? |
|
@gowridurgad let me clarify the full scenario step by step. Current behavior (problem)Right now, NODE_AUTH_TOKEN=XXXXX-XXXXX-XXXXX-XXXXXeven when the user has not provided any token. What happens because of this?
So even when a user is trying to use Trusted Publishing (OIDC), it silently fails. What npm docs expectAccording to npm's official documentation: # Install (token used only here)
- run: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_READ_TOKEN }}
# Publish (OIDC - no token)
- run: npm publishSource: https://docs.npmjs.com/trusted-publishers#handling-private-dependencies What this PR changesThis PR updates the behavior to:
Expected behavior after this fixCase 1: Token-based publish
Case 2: OIDC / Trusted Publishing
|
|
@gowridurgad Please review once you're available. |
|
Hi @Satishchoudhary94, We noticed that no packages were actually published to npm for the version shown here: https://www.npmjs.com/package/@satishchoudhary94/setup-node-oidc-test/v/1.0.0. From the workflow logs, it appears that npm publish --dry-run is being used. In npm, --dry-run is intended as a verification step before a real release. It simulates the publish process so you can review what would be included in the package (such as files and metadata), but it does not upload anything to the npm registry or create a real release. This is also documented in the official npm CLI documentation for npm publish, where --dry-run is described as reporting what would happen without performing the actual publish. We also want to clarify the OIDC behavior based on the logs and documentation. The Trusted Publishing documentation states that The npm CLI automatically detects OIDC environments and uses them for authentication before falling back to traditional tokens. From the evidence in the attached screenshots and logs, we observe the following behavior in npm: In the first case, where both an OIDC-enabled environment (GitHub Actions) and NODE_AUTH_TOKEN are present, the package is still published using OIDC, and attestations/provenance are generated. The logs also clearly show:
In the second case (token-only scenario, without an OIDC environment), the package is published using token-based authentication and no provenance/attestation is generated.
This indicates that the OIDC flow is actively triggered and completed successfully when the environment supports it, even if NODE_AUTH_TOKEN is present. Based on this evidence, it appears that when OIDC is available (and provenance is enabled), npm proceeds with the OIDC-based authentication flow rather than relying solely on NODE_AUTH_TOKEN. Based on the above, the primary impact of this PR would be limited to environment cleanliness (i.e., avoiding setting a default/dummy token). The presence of a dummy NODE_AUTH_TOKEN does not appear to prevent or break the OIDC flow in this scenario. If you still have any questions or see a different behavior in other scenarios, please let us know—we’re happy to take a closer look. |
|
Hi @Satishchoudhary94, just a gentle reminder to take a look at the previous comment when you get a chance. Please let us know if there are any updates at your convenience. |
|
Hi @Satishchoudhary94, just a gentle reminder on this. Please let us know if there are any updates from your end. |
actions/setup-node v6.0.2 is the first release with npm OIDC support (actions/setup-node#1477). v4/v5 write an .npmrc that points `_authToken` at $NODE_AUTH_TOKEN unconditionally, which short-circuits npm CLI's OIDC code path and 401s at publish even when the trusted publisher is configured correctly.
…sh workflow (#147) * npm: bump weave-router to 0.1.1 + add tag-publish workflow - bump version to 0.1.1 (statusline self-refresh + uninstall delegation) - add .github/workflows/publish_npm.yml: tag `weave-router-v*` triggers `npm publish --provenance --access public`, asserts tag matches package.json version first * npm: rename to @workweave/router, switch to OIDC trusted publishing Rename the unscoped weave-router package to @workweave/router (org-scoped) so the package is owned by the workweave org from day one — no npm-support ticket needed, no squat risk on the unscoped name. - install/npm/package.json: name → @workweave/router, version reset to 0.1.0 (fresh scoped package; the unscoped [email protected] will be deprecated with a pointer to the new name) - Swap `npx weave-router` → `npx @workweave/router` in install.sh, uninstall.sh, install/README.md, install/npm/README.md, and bin.js comment - Keep the binary name as `weave-router` (package.json bin field) so the CLI on PATH after `npm install -g` is unchanged - publish_npm.yml: tag prefix `weave-router-v*` → `router-v*` (npm scope slashes break git refs; flat prefix is cleaner), drop NODE_AUTH_TOKEN env in favor of npm OIDC trusted publishing (no long-lived secret in repo) * npm: fix package metadata (homepage, license, bundle LICENSE) - homepage: weave.ai → workweave.ai (correct marketing domain) - license: Apache-2.0 → "SEE LICENSE IN LICENSE" (the repo is ELv2, which is not on the SPDX list; the npm-recommended pattern for non-SPDX licenses is to point at the bundled LICENSE file) - copy-installer.js: also copy ../../LICENSE into the npm package root so npm surfaces the license on the package page and consumers receive it with `npm install` - .gitignore: add LICENSE alongside the other prepack-generated files - bump to 0.1.1 (0.1.0 just shipped with the wrong metadata) * ci: pin actions to SHAs and bump Node to 24 for npm OIDC - pin actions/checkout + actions/setup-node to commit SHAs since this workflow has id-token: write and publishes to npm; floating tags here let an upstream-action compromise ship a malicious package - bump node-version 20 → 24 because npm OIDC trusted publishing requires npm ≥ 11.5 (Node 20 ships with npm 10 and would 401) * ci: reject publish tags not reachable from main Without this, anyone with tag-push capability could publish from a side branch and bypass branch-protection / PR-review on main. The new step fetches origin/main and asserts the tagged commit is an ancestor before the publish step runs. * ci: fetch-depth 0 so the merge-base ancestry check has history Default shallow clone (depth 1) only has the tagged commit, so `git merge-base --is-ancestor $SHA origin/main` can't walk the graph and the reachability check would reject even legitimate main-reachable tags. * ci: bump setup-node v4 → v6 for npm OIDC support actions/setup-node v6.0.2 is the first release with npm OIDC support (actions/setup-node#1477). v4/v5 write an .npmrc that points `_authToken` at $NODE_AUTH_TOKEN unconditionally, which short-circuits npm CLI's OIDC code path and 401s at publish even when the trusted publisher is configured correctly.




Problem
The action was exporting a fake NODE_AUTH_TOKEN value (
XXXXX-XXXXX-XXXXX-XXXXX) by default,which broke NPM OIDC authentication. OIDC requires NODE_AUTH_TOKEN to be either unset or empty.
Solution
Only export NODE_AUTH_TOKEN if it was explicitly provided by the user.
Changes
configAuthentication()in authutil.ts to check if NODE_AUTH_TOKEN exists before exportingTesting