GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [BUG] npm config removes _auth from .npmrc · Issue #2300 · npm/cli

[BUG] npm config removes _auth from .npmrc #2300

New issue
Copy link
New issue
Copy link
Closed
Closed
[BUG] npm config removes _auth from .npmrc#2300
Copy link
Assignees
isaacs
Labels
Bugthing that needs fixingRelease 7.xwork is associated with a specific npm 7 release

Description

@bradbeck
bradbeck
opened on Dec 8, 2020
Issue body actions

Current Behavior:

npm config set <anykey> <anyvalue> will result in _auth=... being removed from .npmrc

Expected Behavior:

npm config set foo bar should not result in _auth=... being removed from .npmrc

Steps To Reproduce:

  1. echo '_auth="xxx"' >> ~/.npmrc
  2. cat ~/.npmrc to see _auth="xxx" is there
  3. npm config set foo bar
  4. cat ~/.npmrc to see _auth="xxx" is gone

Environment:

Docker image node:15.3.0
Node: 15.3.0
npm: 7.0.14

Reacted by Joe Tom, Abhilash Ghosh, Elouan Keryell-Even and Drazen Bjelovuk

Activity

  1. bradbeck
    added
    Bugthing that needs fixing
    Needs Triageneeds review for next steps
    Release 7.xwork is associated with a specific npm 7 release
    on Dec 8, 2020
  2. ljharb commented on Dec 8, 2020

    @ljharb
    ljharb
    on Dec 8, 2020
    Contributor
    More actions

    Does it still happen with v7.0.15?

  3. bradbeck commented on Dec 8, 2020

    @bradbeck
    bradbeck
    on Dec 8, 2020
    Author
    More actions

    Not sure, I haven't found a way to update npm in the node docker image.

  4. ljharb commented on Dec 8, 2020

    @ljharb
    ljharb
    on Dec 8, 2020
    Contributor
    More actions

    npm install -g npm@7?

  5. bradbeck commented on Dec 8, 2020

    @bradbeck
    bradbeck
    on Dec 8, 2020
    Author
    More actions

    The node docker image fails to update npm that way. Some permissions issue.

    I have confirmed that it still happens for [email protected] on MacOS.

    Reacted by Jordan Harband
  6. isaacs commented on Dec 10, 2020

    @isaacs
    isaacs
    on Dec 10, 2020
    Contributor
    More actions

    This is happening because xxx is not a valid _auth field.

    In order for credentials to be saved, a username, email address, and password must all be set, and it is re-saved to the config file scoped only to the proper registry.

    This works as expected, for example:

    $ echo $'_auth=dXNlcjpwYXNz\[email protected]' > foo.npmrc; node . config set foo=bar --userconfig=foo.npmrc ; cat foo.npmrc
    foo=bar
    //registry.npmjs.org/:username=user
    //registry.npmjs.org/:_password="cGFzcw=="
    //registry.npmjs.org/:[email protected]
    //registry.npmjs.org/:always-auth=false
    
  7. isaacs commented on Dec 11, 2020

    @isaacs
    isaacs
    on Dec 11, 2020
    Contributor
    More actions

    Note that _auth must be a base64-encoded username:password pair. It's then saved with the username and password as shown.

  8. bradbeck commented on Dec 11, 2020

    @bradbeck
    bradbeck
    on Dec 11, 2020
    Author
    More actions

    @isaacs This appears to be a change in behavior relative to versions prior to npm v7. Is the methodology you describe backward compatible? If so, how far back?

  9. bradbeck commented on Dec 11, 2020

    @bradbeck
    bradbeck
    on Dec 11, 2020
    Author
    More actions

    @isaacs The methodology you describe does not seem to work for ~/.npmrc and npm config set foo=bar. _auth still gets removed but it not replaced with username and password as you describe.

    Reacted by Elouan Keryell-Even and Drazen Bjelovuk
  10. bradbeck commented on Dec 11, 2020

    @bradbeck
    bradbeck
    on Dec 11, 2020
    Author
    More actions

    In versions prior to npm v7 we used to be able to use the following to configure authentication:

    $ npm config set registry http://npm.example.com/
    $ npm config set always-auth true
    $ npm config set email [email protected]
    $ npm config set _auth YWRtaW46YWRtaW4=
    

    With npm v7+ it does not appear to be possible to use npm config set ... to set email or _auth. A sequence like the following is required to get authentication working:

    $ npm config set registry http://npm.example.com/
    $ echo '[email protected]\n_auth="YWRtaW46YWRtaW4="' >> ~/.npmrc
    $ npm config set always-auth true
    

    or

    $ npm config set registry http://npm.example.com/
    $ npm config set //npm.example.com/:always-auth true
    $ npm config set //npm.example.com/:email [email protected]
    $ npm config set //npm.example.com/:username admin
    $ npm config set //npm.example.com/:_password YWRtaW4=
    
    Reacted by Drazen Bjelovuk
  11. isaacs commented on Dec 15, 2020

    @isaacs
    isaacs
    on Dec 15, 2020
    Contributor
    More actions

    Aha, seems like the issue here is that npm config set email [email protected] is failing, that's the bug here. Email should be able to be set separate from credentials. This works in the meantime:

    npm config set registry http://npm.example.com/
    npm config set always-auth true
    echo "[email protected]" >> ~/.npmrc
    npm config set _auth YWRtaW46YWRtaW4=
  12. isaacs
    closed this as completedin 9bf2ef5on Dec 15, 2020
  13. isaacs
    reopened this on Dec 15, 2020
  14. isaacs commented on Dec 15, 2020

    @isaacs
    isaacs
    on Dec 15, 2020
    Contributor
    More actions

    Will be fixed on next npm release, with @npmcli/[email protected]

    Reacted by Joe Tom
  15. isaacs
    self-assigned this
    on Dec 15, 2020
  16. isaacs
    added
    Release-Next
    and removed
    Needs Triageneeds review for next steps
    on Dec 15, 2020
  17. isaacs
    added 3 commits that reference this issue on Dec 16, 2020

    Support multiple set/get/deletes in npm config

    4faf5f3

    Support multiple set/get/deletes in npm config

    8ccbdf2

    Support multiple set/get/deletes in npm config

    8fd006a
  18. isaacs commented on Dec 16, 2020

    @isaacs
    isaacs
    on Dec 16, 2020
    Contributor
    More actions

    So, just to clarify:

    • npm config set _auth=xxx will fail if email is not set.
    • npm config set [email protected] will work, even if _auth is not set.
    • npm config set [email protected] _auth=xxx will always work (ie, adding two configs in one command).
    • in all cases, the authentication settings will still be scoped to a given registry, so it's important to either set that registry config first, or include it in the command cli config, like npm config --registry=https://npm.internal/ set [email protected] _auth=xxx
    Reacted by Brad Beck and Drazen Bjelovuk
  19. isaacs
    added 2 commits that reference this issue on Dec 18, 2020

    Support multiple set/get/deletes in npm config

    a9b8bf2

    @npmcli/[email protected]

    4fc2f3e
  20. isaacs
    closed this as completedon Dec 18, 2020
  21. belun commented on Oct 18, 2022

    @belun
    belun
    on Oct 18, 2022
    More actions

    still happening in npm8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @isaacs
    isaacs

Labels

Bugthing that needs fixingRelease 7.xwork is associated with a specific npm 7 release

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.