Invalid auth configuration found error when an update is found in a private npm artifacts feed

See original GitHub issue

Following the update to 1.20 our pipeline encounters the following error when an update is found,

npm ERR! code ERR_INVALID_AUTH npm ERR! Invalid auth configuration found: _auth must be renamed to //pkgs.dev.azure.com/our-org/_packaging/our-feed/npm/registry/:_auth in project config npm ERR! Please run npm config fix to repair your configuration.`

We previously had dockerImageTag set to 0.18 and this was working up until recently when the image per ecosystem update kicked in forcing us to update to 1.20 so I can’t be sure whether we would have encountered the same error with 0.19.

Issue Analytics

  • State:open
  • Created 2 months ago
  • Reactions:3
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
rickardgranbergcommented, Aug 8, 2023

We’re also seeing this problem after switching to 1.20+. In our configuration, we’re using Azure Artifacts as the only registry, with upstream feeds to npmjs et.al. Our .npmrc looks like:

registry=https://pkgs.dev.azure.com/<org>/<project>/_packaging/<registry>/npm/registry/

always-auth=true

This also means that every package in package-lock.json will have the above registry as the resolved URL. From what I can deduce by looking at the npmrc_builder.rb file in dependabot-core, this means that this registry will be classified as a global registry, see: https://github.com/dependabot/dependabot-core/blob/f9754d41004cb5a507b3cd4920fbf48551f9aced/npm_and_yarn/lib/dependabot/npm_and_yarn/file_updater/npmrc_builder.rb#L84

This in turn leads to this part of the code https://github.com/dependabot/dependabot-core/blob/f9754d41004cb5a507b3cd4920fbf48551f9aced/npm_and_yarn/lib/dependabot/npm_and_yarn/file_updater/npmrc_builder.rb#L165 creating the following .npmrc :

registry=https://pkgs.dev.azure.com/<org>/<project>/_packaging/<registry>/npm/registry/
_authToken=<token>
always-auth=true

This is a problem, because since NPM v8, all auth-related values need to be scoped, see: https://docs.npmjs.com/cli/v9/configuring-npm/npmrc?v=true#auth-related-configuration

A correct .npmrc needs to look like:

registry=https://pkgs.dev.azure.com/<org>/<project>/_packaging/<registry>/npm/registry/
//pkgs.dev.azure.com/<org>/<project>/_packaging/<registry>/npm/registry/:_authToken=<token>
always-auth=true

My conclusion is that the problem lies in dependabot-core in that it no longer creates a compatible .npmrc for NPM > v8

I’ve created an issue there, let’s see what the response is: https://github.com/dependabot/dependabot-core/issues/7759

0reactions
pawelrakoczycommented, Aug 21, 2023

I finally managed to get this working for me. In my case it helped to edit the .npmrc file in the project repo: non-working .npmrc:

@removed:registry=https://node.bit.cloud
registry=https://pkgs.dev.azure.com/Org_removed/Project_removed/_packaging/project_removed/npm/registry/
always-auth=true

working .npmrc:

@removed:registry=https://node.bit.cloud
@npm-devops:registry=https://pkgs.dev.azure.com/Org_removed/Project_removed/_packaging/project_removed/npm/registry/
registry=https://pkgs.dev.azure.com/Org_removed/Project_removed/_packaging/project_removed/npm/registry/
always-auth=true

npm-devops needs to be the same as the name of your registry in dependabot.yml:

version: 2
registries:
  npm-devops:
    type: npm-registry
    url: 'pkgs.dev.azure.com/Org_removed/Project_removed/_packaging/project_removed/npm/registry/'
    token: 'PAT:${{FEEDACCESSTOKEN}}'
updates:
  - package-ecosystem: "npm" 
    directory: "/"
    registries:
      - npm-devops
    target-branch: "develop"
    schedule:
      interval: "daily"

of course you need to replace the ‘removed’ parts with your stuff Hope that this would work for you as well!

thanks @mburumaxwell for your sample files, they helped me with narrowing down what might be the issue!

Read more comments on GitHub >

github_iconTop Results From Across the Web

E401 - Unable to authenticate, your authentication token ...
I tested with Azure Packages private NPM server and now want to revert back to using the standard NPM registry but when I...
Read more >
Fixing - E401 NPM Errors - Weekend Projects
Working with private NPM registries can encounter error codes such as E401 NPM error. We go over a few ways to fix this!...
Read more >
[BUG] NPM v7 private registry authentication 401 (v6 works)
A complete log of this run can be found in: npm ERR! ... Unable to authenticate, your authentication token seems to be invalid....
Read more >
How to connect and authenticate to NPM feeds on Azure ...
In order to update and download packages to a feed, you must access that Artifact page, click on Connect to feed and navigate...
Read more >
Set up your client's npmrc - Azure Artifacts
Select Artifacts, and then select Connect to feed. Select npm from the left navigation pane. If this is the first time using Azure...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found