Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yarn npm login is not compatible with verdaccio #1044

Closed
jeffrson opened this issue Mar 7, 2020 · 26 comments · Fixed by #5983
Closed

yarn npm login is not compatible with verdaccio #1044

jeffrson opened this issue Mar 7, 2020 · 26 comments · Fixed by #5983
Labels
bug Something isn't working good first issue Good for newcomers upholded Real issues without formal reproduction

Comments

@jeffrson
Copy link

jeffrson commented Mar 7, 2020

Describe the bug

I have a private npm registry implemented by verdaccio which requires login for any access. When a certain user does not yet exist in the registry yarn npm login succeeds. However, as soon as this user tries to relogin with the same command there's a http error 409 (conflict).

I had reported this against verdaccio (verdaccio/verdaccio#1737), since yarn2 login works fine for registry.yarnpkg.com. However, this was before I realized that new users may be created without problems.

To Reproduce

I'm sorry that I don't see like I could provide the repro with Sherlock :-(

1 You would have to install verdaccio, globally or locally, with yarn or npm and run it like this
[yarn run] verdaccio -c conf.yml with this conf.yml:

storage: ./storage

auth:
  htpasswd:
    file: ./htpasswd

security:
  api:
    jwt:
      sign:
        expiresIn: 30d
        notBefore: 0
  web:
    sign:
      expiresIn: 7d

uplinks:
  npmjs:
    url: https://registry.npmjs.org/

packages:
  '@*/*':
    access: $authenticated
    publish: $authenticated
    proxy: npmjs

  '**':
    access: $authenticated
    publish: $authenticated
    proxy: npmjs

logs:
  - {type: file, path: verdaccio.log, level: trace}

2 Furthermore I save this as .yarnrc.yml (you'd have to correct yarnPath, obviously)

yarnPath: "...\\.yarn\\releases\\yarn-berry.js"

unsafeHttpWhitelist:
  - "localhost"

npmRegistryServer: "http://localhost:4873"

3 Execute yarn npm login two times - the first will succeed, the second fail with a message like this:

➤ YN0001: HTTPError: Response code 409 (Conflict)
at EventEmitter. (...\releases\yarn-berry.js:24:327728)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
➤ YN0000: Failed with errors in 4.09s

Environment if relevant (please complete the following information):

  • OS: [e.g. OSX, Linux, Windows, ...] windows 10
  • Node version [e.g. 8.15.0, 10.15.1, ...] 12.16.1
  • Yarn version [e.g. 2.0.0-rc1, ...] 2.0.0rc29
const cp = require('child_process')
const fs = require('fs')


const verdaccioConf=`
storage: ./storage

auth:
  htpasswd:
    file: ./htpasswd

uplinks:
  npmjs:
    url: https://registry.npmjs.org/

packages:
  '@*/*':
    access: $authenticated
    publish: $authenticated
    proxy: npmjs

  '**':
    access: $authenticated
    publish: $authenticated
    proxy: npmjs

logs:
  - {type: stdout, format: pretty, level: http}
`
fs.writeFileSync('config.yaml', verdaccioConf)


const htpasswd = `
test:$6FrCaT/v0dwE:autocreated 2020-06-09T16:43:43.706Z
`
fs.writeFileSync('htpasswd', htpasswd)


const  yarnrc = `
unsafeHttpWhitelist:
  - "localhost"

npmRegistryServer: "http://localhost:4873"
`
fs.writeFileSync('.yarnrc.yml', yarnrc)


await packageJsonAndInstall({
  dependencies: {
    'verdaccio': '4.5.1'
  }
})

cp.spawn('./node_modules/.bin/verdaccio')

await new Promise(resolve => setTimeout(resolve, 5000)) // a bit of a delay

const output = await yarn('yarn', 'npm', 'login') // test, test
expect(output).not.toContain('Response code 409 (Conflict)')
@jeffrson jeffrson added the bug Something isn't working label Mar 7, 2020
@ringods
Copy link

ringods commented Apr 3, 2020

I was able to reproduce this easily with Yarn 2.0.0-rc.31.
I ran verdaccio via the default Docker image:

$ docker run -it --rm --name verdaccio -p 4873:4873 verdaccio/verdaccio

Then first create a user via:

$ npm adduser --registry http://localhost:4873

Then configure the local registry in your .yarnrc.yml file:

npmScopes:
  testscope:
    npmPublishRegistry: "http://localhost:4873"
    npmRegistryServer: "http://localhost:4873"
    npmAlwaysAuth: true
unsafeHttpWhitelist:
  - "localhost"

followed by:

$ yarn npm login -s testscope

If you use the same credentials from adduser, the yarn login will fail and you will see the following error message from the Verdaccio process:

http <-- 409, user: null(172.17.0.1), req: 'PUT /-/user/org.couchdb.user:ringods', error: username is already registered

@yarnbot

This comment has been minimized.

@yarnbot yarnbot added the stale Issues that didn't get attention label Jun 9, 2020
@jeffrson
Copy link
Author

jeffrson commented Jun 9, 2020

Tried a repro - still I don't know how to simulate input to "yarn npm login". Maybe someone could enlighten me...

I'm not sure if this will help to fix the bug, though.

@yarnbot yarnbot added the broken-repro The reproduction in this issue is broken label Jun 9, 2020
@yarnbot

This comment has been minimized.

@yarnbot

This comment has been minimized.

@jeffrson
Copy link
Author

jeffrson commented Jun 9, 2020

Also it does not seem to allow to start verdaccio...

@jeffrson
Copy link
Author

BTW, if I copy the auth-token received by "npm login" into .yarnrc.yml the registry can be accessed without probs.

@therealalexmois
Copy link

BTW, if I copy the auth-token received by "npm login" into .yarnrc.yml the registry can be accessed without probs.

Hi! It didn't help me. I add new user into Verdaccio, then copy authToken into .yarnrn.yml and I keep getting http error with code 409.

@bgotink
Copy link
Sponsor Member

bgotink commented Jul 23, 2020

The verdaccio logs shows that npm has some extra logic when a 409 is returned:

# yarn npm login -s testscope
 http <-- 409, user: null(172.17.0.1), req: 'PUT /-/user/org.couchdb.user:bram', error: username is already registered

# npm login --registry http://localhost:4873
 http <-- 404, user: null(172.17.0.1), req: 'POST /-/v1/login', bytes: 24/150
 http <-- 409, user: null(172.17.0.1), req: 'PUT /-/user/org.couchdb.user:bram', error: username is already registered
 http <-- 200, user: null(172.17.0.1), req: 'GET /-/user/org.couchdb.user:bram?write=true', bytes: 0/51
 http <-- 201, user: bram(172.17.0.1), req: 'PUT /-/user/org.couchdb.user:bram/-rev/undefined', bytes: 166/85

The logic in question can be found here: https://github.com/npm/npm-profile/blob/6b643238ff7e1e6ec5544b0771142a8d0c537925/index.js#L162

@bgotink bgotink added upholded Real issues without formal reproduction and removed broken-repro The reproduction in this issue is broken labels Jul 23, 2020
@yarnbot yarnbot added the broken-repro The reproduction in this issue is broken label Jul 23, 2020
@yarnbot

This comment has been minimized.

@bgotink
Copy link
Sponsor Member

bgotink commented Jul 23, 2020

I've removed the repro tag from the OP. Even though it's probably possible to get it running in sherlock, it would be hard to do and it's easy enough to reproduce manually.

@bgotink bgotink added good first issue Good for newcomers and removed broken-repro The reproduction in this issue is broken stale Issues that didn't get attention labels Jul 23, 2020
@juanpicado
Copy link
Contributor

I'll give it a try 🤞

@dmoosocool
Copy link

dmoosocool commented Oct 21, 2020

any news here?

npmAlwaysAuth: true
npmAuthToken: xxxxMyToken

npmRegistryServer: "http://localhost:4873"

npmScopes:
  myscope:
    npmAlwaysAuth: true
    npmAuthToken: xxxxMyToken
    npmPublishRegistry: "http://localhost:4873"
    npmRegistryServer: "http://localhost:4873"

unsafeHttpWhitelist:
  - localhost
yarn npm login
➤ YN0000: Logging in to http://localhost:4873

✔ Username: · dmoosocool
✔ Password: · *************

➤ YN0001: HTTPError: Response code 409 (Conflict)
    at se.<anonymous> (/.yarn/releases/yarn-sources.cjs:23:10082)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
➤ YN0000: Failed with errors in 11s 413ms
yarn npm whoami
➤ YN0000: undefined
➤ YN0000: Done in 0s 49ms
yarn npm publish
➤ YN0041: Invalid authentication (as an unknown user)
➤ YN0000: Failed with errors in 0s 150ms

@XavierChevalier
Copy link

I have exactly the same problem as @dmoosocool, any news?

@XavierChevalier
Copy link

XavierChevalier commented Jan 25, 2021

I designed a temporary fix.

I created a file named .yarn/publish.sh in which I change the version of Yarn on the fly in the .yarnrc.yml. This allows to publish with the 1.22.10 version and to switch back to the "Berry" version of Yarn.

# This is a temporary fix allowing to publish the package.
# Indeed, there is a bug under Yarn Berry that prevents deployment on Verdaccio.
# @see https://github.com/yarnpkg/berry/issues/1044
# @see https://github.com/verdaccio/verdaccio/issues/1737
sed -i "s/yarnPath: .*/yarnPath: \.yarn\/releases\/yarn-1.22.10.cjs/" .yarnrc.yml
yarn publish
sed -i "s/yarnPath: .*/yarnPath: \.yarn\/releases\/yarn-berry.cjs/" .yarnrc.yml

When you want to publish, do not run yarn npm publish, but rather ./.yarn/publish.sh.

@thefrana
Copy link

Any progress on this?

@juanpicado juanpicado removed their assignment Jun 1, 2021
@juanpicado
Copy link
Contributor

I'm removing myself assigning here more details verdaccio/verdaccio#1737 (comment) and here the PR I did open #1848 anyone feel free to keep contributing.

@IhToN
Copy link

IhToN commented Nov 3, 2021

After playing with Wireshark, a non-https request and Yarn Berry I was able to replicate the same behavior on Postman.

It looks like yarn npm login is not adding the Authorization header but just the user and password in the body request. For whatever reason, that's making verdaccio not use the authorization process but the adduser process.

As extra info, it doesn't launch the authorization nor the adduser process from all the plugins as I'm using verdaccio-azure-ad-login and this one does not display any of the debug messages it displays when using npm login.

@korniychuk
Copy link

korniychuk commented Feb 7, 2022

Temporary workaround:

  1. Login with NPM
  2. Copy-paste generated token from ~/.npmrc to ~/.yarnrc.yml.
❯ cat ~/.npmrc
//npm.my-project.pro/:_authToken="GAOEuaeouaoEUo+u3=="

❯ cat ~/.yarnrc.yml
npmRegistries:
  "https://npm.my-project.pro":
    npmAuthToken: GAOEuaeouaoEUo+u3==

Then yarn npm publish for verdaccio works fine.

@Jim-Bar
Copy link

Jim-Bar commented Feb 11, 2022

Same issue with yarn 3.1.1 here and Verdaccio 3.2.0, but I can confirm that the workaround of @korniychuk works.

@v4dkou
Copy link

v4dkou commented Jun 19, 2022

Same issue with yarn 3.2.1 and Verdaccio 4.6.2.

@jeffrson
Copy link
Author

jeffrson commented Nov 20, 2022

Unfortunately, this still is an issue with current Verdaccio 5.17 and yarn 3.3.0 as well as 4.0.0rc30.

Comparing Wireshark logs for npm and yarn with the same prerequisites (no token in .npmrc or .yarnrc.yml) it can be seen, that npm receives "409 conflict (user exists)" just as yarn does. However, while yarn stops at that moment, npm continues in a kind of "login flow", finally creating a token and logging in successfully. This is the relevant source of npm:
https://github.com/npm/npm-profile/blob/main/lib/index.js#L181

OTOH, if there is a token in .npmrc and .yarnrc.yml, npm sends the token with the request while yarn doesn't. Such, there's no "409" for npm, but for yarn it remains.

Essentially, this is what @juanpicado tries to address in the PR - any chance this will be fixed for 4.0?

@Daolot
Copy link

Daolot commented Apr 13, 2023

Same issue

@usrrname
Copy link

usrrname commented Jun 4, 2023

Feel like I'm late to the party but discovering this issue in 2023. 😆

@nnmax
Copy link

nnmax commented Aug 15, 2023

Same issue with yarn 3.6.1 and Verdaccio 5.26.1.

demurgos added a commit to demurgos/berry that referenced this issue Nov 19, 2023
This commit fixes `yarn npm login` when the remote registry is Verdaccio.

When a user already exists, the registry replies with `409 Conflict`. The official npm client then retrieves the latest user state and inserts a revision, using HTTP basic authentication. This step was missing, and this commits adds it.

The change was tested to work with a private Verdaccio registry. It should now be as reliable as the official npm client.

- Closes yarnpkg#1044
- Closes verdaccio/verdaccio#1737
demurgos added a commit to demurgos/berry that referenced this issue Nov 19, 2023
This commit fixes `yarn npm login` when the remote registry is Verdaccio.

When a user already exists, the registry replies with `409 Conflict`. The official npm client then retrieves the latest user state and inserts a revision, using HTTP basic authentication. This step was missing, and this commits adds it.

The change was tested to work with a private Verdaccio registry. It should now be as reliable as the official npm client.

- Closes yarnpkg#1044
- Closes verdaccio/verdaccio#1737
@demurgos
Copy link
Contributor

demurgos commented Nov 19, 2023

I was able to fix the issue locally; it works with my private Verdaccio instance. I sent a Yarn PR: #5983

demurgos added a commit to demurgos/berry that referenced this issue Nov 19, 2023
This commit fixes `yarn npm login` when the remote registry is Verdaccio.

When a user already exists, the registry replies with `409 Conflict`. The official npm client then retrieves the latest user state and inserts a revision, using HTTP basic authentication. This step was missing, and this commits adds it.

The change was tested to work with a private Verdaccio registry. It should now be as reliable as the official npm client.

- Closes yarnpkg#1044
- Closes verdaccio/verdaccio#1737
demurgos added a commit to demurgos/berry that referenced this issue Nov 19, 2023
This commit fixes `yarn npm login` when the remote registry is Verdaccio.

When a user already exists, the registry replies with `409 Conflict`. The official npm client then retrieves the latest user state and inserts a revision, using HTTP basic authentication. This step was missing, and this commits adds it.

The change was tested to work with a private Verdaccio registry. It should now be as reliable as the official npm client.

- Closes yarnpkg#1044
- Closes verdaccio/verdaccio#1737
demurgos added a commit to demurgos/berry that referenced this issue Nov 19, 2023
This commit fixes `yarn npm login` when the remote registry is Verdaccio.

When a user already exists, the registry replies with `409 Conflict`. The official npm client then retrieves the latest user state and inserts a revision, using HTTP basic authentication. This step was missing, and this commits adds it.

The change was tested to work with a private Verdaccio registry. It should now be as reliable as the official npm client.

- Closes yarnpkg#1044
- Closes yarnpkg#1848
- Closes verdaccio/verdaccio#1737
demurgos added a commit to demurgos/berry that referenced this issue Nov 19, 2023
This commit fixes `yarn npm login` when the remote registry is Verdaccio.

When a user already exists, the registry replies with `409 Conflict`. The official npm client then retrieves the latest user state and inserts a revision, using HTTP basic authentication. This step was missing, and this commits adds it.

The change was tested to work with a private Verdaccio registry. It should now be as reliable as the official npm client.

- Closes yarnpkg#1044
- Closes yarnpkg#1848
- Closes verdaccio/verdaccio#1737
demurgos added a commit to demurgos/berry that referenced this issue Nov 19, 2023
This commit fixes `yarn npm login` when the remote registry is Verdaccio.

When a user already exists, the registry replies with `409 Conflict`. The official npm client then retrieves the latest user state and inserts a revision, using HTTP basic authentication. This step was missing, and this commits adds it.

The change was tested to work with a private Verdaccio registry. It should now be as reliable as the official npm client.

- Closes yarnpkg#1044
- Closes yarnpkg#1848
- Closes verdaccio/verdaccio#1737
demurgos added a commit to demurgos/berry that referenced this issue Nov 19, 2023
This commit fixes `yarn npm login` when the remote registry is Verdaccio.

When a user already exists, the registry replies with `409 Conflict`. The official npm client then retrieves the latest user state and inserts a revision, using HTTP basic authentication. This step was missing, and this commits adds it.

The change was tested to work with a private Verdaccio registry. It should now be as reliable as the official npm client.

- Closes yarnpkg#1044
- Closes yarnpkg#1848
- Closes verdaccio/verdaccio#1737
arcanis pushed a commit that referenced this issue Nov 28, 2023
**What's the problem this PR addresses?**

This commit fixes `yarn npm login` when the remote registry is
Verdaccio.

- Closes #1044
- Closes #1848
- Closes verdaccio/verdaccio#1737

...

**How did you fix it?**

When a user already exists, the registry replies with `409 Conflict`.
The official npm client then retrieves the latest user state and inserts
a revision, using HTTP basic authentication. This step was missing, and
this commits adds it.

The change was tested to work with a private Verdaccio registry. It
should now be as reliable as the official npm client.

...

**Checklist**
<!--- Don't worry if you miss something, chores are automatically
tested. -->
<!--- This checklist exists to help you remember doing the chores when
you submit a PR. -->
<!--- Put an `x` in all the boxes that apply. -->
- [x] I have read the [Contributing
Guide](https://yarnpkg.com/advanced/contributing).

<!-- See
https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released
for more details. -->
<!-- Check with `yarn version check` and fix with `yarn version check
-i` -->
- [x] I have set the packages that need to be released for my changes to
be effective.

<!-- The "Testing chores" workflow validates that your PR follows our
guidelines. -->
<!-- If it doesn't pass, click on it to see details as to what your PR
might be missing. -->
- [x] I will check that all automated PR checks pass before the PR gets
reviewed.
merceyz pushed a commit that referenced this issue Jan 30, 2024
**What's the problem this PR addresses?**

This commit fixes `yarn npm login` when the remote registry is
Verdaccio.

- Closes #1044
- Closes #1848
- Closes verdaccio/verdaccio#1737

...

**How did you fix it?**

When a user already exists, the registry replies with `409 Conflict`.
The official npm client then retrieves the latest user state and inserts
a revision, using HTTP basic authentication. This step was missing, and
this commits adds it.

The change was tested to work with a private Verdaccio registry. It
should now be as reliable as the official npm client.

...

**Checklist**
<!--- Don't worry if you miss something, chores are automatically
tested. -->
<!--- This checklist exists to help you remember doing the chores when
you submit a PR. -->
<!--- Put an `x` in all the boxes that apply. -->
- [x] I have read the [Contributing
Guide](https://yarnpkg.com/advanced/contributing).

<!-- See
https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released
for more details. -->
<!-- Check with `yarn version check` and fix with `yarn version check
-i` -->
- [x] I have set the packages that need to be released for my changes to
be effective.

<!-- The "Testing chores" workflow validates that your PR follows our
guidelines. -->
<!-- If it doesn't pass, click on it to see details as to what your PR
might be missing. -->
- [x] I will check that all automated PR checks pass before the PR gets
reviewed.

(cherry picked from commit db6210f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers upholded Real issues without formal reproduction
Projects
None yet