Skip to content

Also override global npm config to fix persistent E401#7375

Open
ilonatommy wants to merge 1 commit intomainfrom
fix-npm-stale-user-npmrc
Open

Also override global npm config to fix persistent E401#7375
ilonatommy wants to merge 1 commit intomainfrom
fix-npm-stale-user-npmrc

Conversation

@ilonatommy
Copy link
Member

@ilonatommy ilonatommy commented Mar 9, 2026

Problem

PR #7366 added \NPM_CONFIG_USERCONFIG\ to bypass stale user-level .npmrc\ credentials, but build 1325007 on PR #7361 still fails with E401 on agents 92 and 93.

The env var override was confirmed present in the merge commit, yet npm still sends stale auth tokens. This means the stale credentials are likely in the global .npmrc\ (<prefix>/etc/npmrc), not just the user-level one.

Fix

  • Add \NPM_CONFIG_GLOBALCONFIG\ alongside \NPM_CONFIG_USERCONFIG, both pointing to a non-existent file. This ensures npm only reads the project-level .npmrc\ (registry URL, no auth tokens).
  • Add
    pm config list\ diagnostics before the build so we can confirm the env vars take effect and see exactly which config sources npm is reading.

Why the previous fix was insufficient

npm reads config from four sources in order: project → user → global → built-in. PR #7366 only overrode the user config. If stale _authToken\ entries exist in the global config on these CI agents, they would still be sent.

Fixes #7365
Related: #7361, #7362, #7364, #7366

Microsoft Reviewers: Open in CodeFlow

The previous fix only overrode NPM_CONFIG_USERCONFIG, but stale auth
tokens may also exist in the global .npmrc on CI agents. Override both
NPM_CONFIG_USERCONFIG and NPM_CONFIG_GLOBALCONFIG to non-existent files
so npm only reads the project-level .npmrc (registry URL, no auth).

Also add npm config list diagnostics to confirm the env vars take effect
and help debug if E401 persists.

Fixes #7365

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ilonatommy ilonatommy requested a review from a team as a code owner March 9, 2026 07:42
Copilot AI review requested due to automatic review settings March 9, 2026 07:42
@github-actions github-actions bot added the area-ai-eval Microsoft.Extensions.AI.Evaluation and related label Mar 9, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens the Azure Pipelines “Build Azure DevOps plugin” step against npm E401 failures caused by stale credentials on hosted agents by neutralizing additional npm config sources and adding diagnostics to confirm which config files npm is using.

Changes:

  • Add NPM_CONFIG_GLOBALCONFIG alongside NPM_CONFIG_USERCONFIG to ignore global and user-level .npmrc files on CI agents.
  • Add npm config list diagnostics before the plugin build to aid troubleshooting.


- pwsh: |
Write-Host "--- npm config diagnostics ---"
npm config list
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

npm config list can print a large portion of npm’s effective configuration, which may include registry credentials from agent/user/global configs. Since this runs in CI logs, consider limiting diagnostics to only the specific config paths and a small set of non-sensitive keys (e.g., which config files are being used and what registry is selected), or otherwise ensuring any auth values are redacted before output.

Suggested change
npm config list
Write-Host ("npm userconfig: " + (npm config get userconfig))
Write-Host ("npm globalconfig:" + (npm config get globalconfig))
Write-Host ("npm registry: " + (npm config get registry))

Copilot uses AI. Check for mistakes.
Comment on lines +181 to +182
# so npm only reads the project-level .npmrc (which has the registry
# URL but no auth tokens).
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

The comment says overriding user/global config means npm will only read the project-level .npmrc (URL/no auth). In this script, npm runs in multiple directories, and not all of them appear to have a project .npmrc (e.g., the repo-level install). Consider adjusting the wording to reflect that this forces npm to ignore user/global configs and rely on project config when present (otherwise built-in defaults), to avoid confusion for future maintenance.

Suggested change
# so npm only reads the project-level .npmrc (which has the registry
# URL but no auth tokens).
# so npm ignores user/global .npmrc files and instead uses any
# project-level .npmrc present (with the registry URL but no auth
# tokens), or npm's built-in defaults if none exist.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-ai-eval Microsoft.Extensions.AI.Evaluation and related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

npmAuthenticate@0 insufficient to fix E401: stale user-level .npmrc overrides project-level credentials

3 participants