rust-lang / cargo

The Rust package manager

Home Page:https://doc.rust-lang.org/cargo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cargo can't find git credentials for private repo anymore

Boscop opened this issue · comments

I was using private repos in my Cargo.toml before without problems.
My git installation is GitHub Desktop for windows.
But now I get this error when doing cargo build on a project that uses a private repo:

  failed to authenticate when downloading repository
attempted to find username/password via git's `credential.helper` support, but failed

Caused by:
  [7/-1] Config value 'credential.helper' was not found

Even though ssh-agent.exe is running, and when I git clone the repo manually on the cmd line, it doesn't ask me for credentials, so the underlying mechanism is working.

(It's been several months since I last tried to build this project but I didn't change anything in it from when it last compiled successfully, only updated rust/cargo (and GitHub updated itself).)

cargo 0.16.0-nightly (3568be9 2016-11-26)

This may be due to some change in libssh2, but I'm not entirely sure how to debug unfortunately.

I have gotten something similar to this today.
If I'm right, the steps to reproduce are relatively simple:

  • Use Windows (I used Windows 10)
  • Set git credentials
  • Clone a repo or pull from one, which will succeed
  • change git credentials
  • clone/pull again. This time it will fail.

The core issue as far as I can see it is that there is no (easy?) way to change the credentials and have them automatically propagate to wherever they need to go (including Cargo in this case).

This may be related to https://github.com/alexcrichton/git2-rs/issues/202, fixed in alexcrichton/ssh2-rs@0e979f8, pulled into Cargo in #4008 and going into rust-lang/rust in rust-lang/rust#41830. It may work trying the next nightly with rust-lang/rust#41830?

I'm still running into this, but I haven't changed my GitHub credentials.
Now I can't depend on ANY of my private repos. It will give the above error with cargo, even though I can git clone manually in the same cmd line.
What can I try to get this working?

@Boscop are you on Windows?

Yes, Windows 8.1 with GitHub Desktop. I added the paths to git.exe and github.exe to PATH and cloning the private github repos works on the cmd line. It used to work with cargo too but not anymore.

@Boscop right now Cargo works when cloning private repositories through using the ssh-agent protocol, do you know if that's configured with GitHub Desktop?

I think so, ssh-agent.exe is running in the background.

It may be that libgit2 isn't finding it to communicate with it? Unfortunately I don't know many details of how the ssh-agent is supposed to work on Windows or how libssh2/libgit2 implement it...

Who implemented the communication between cargo and git/ssh agent?
Or who can we ask to find the cause of this?
I urgently need access to my private repos with cargo to continue my work...

Is there any info that I can provide that would be useful to debug this?
It used to work before, so I think something changed during an update of the GitHub Desktop application. But I'm not sure which version was the last working one because it auto updates without notifying me.
I just noticed that during some updates the path to git.exe changed and then I had to edit my PATH variable.
But I don't think this info is useful here because git cloning a private repo on the cmd line works, but in cargo it doesn't...

I'm not super familiar with how it's implemented on Windows. The implementation lives in libssh2, and you may be able to poke around the source to see what's expected.

@jjpe Why do you have to set git credentials? I never set git credentials and it used to work for me before.
When I do a manual git clone, it uses my ssh key which is stored on Github, and manual cloning works.
So why would I need to set any credentials?

Btw, when I do git config --global credential.helper it just prints an empty line.
And when I do git help -a | grep credential it prints:

credential
credential-manager
credential-store
credential-wincred

Why isn't cargo using my ssh key through ssh-agent.exe from GitHub Desktop (which is always running)?

I'm not sure if I have to per se, it just happened to be my observation at the time as my password had been changed due to company security policy.

commented

@alexcrichton I see the same error as the initial report above. I'm pretty sure it's because the git2 crate is trying to use sh when it calls the credential helper here :-
https://github.com/alexcrichton/git2-rs/blob/047c984d3b934e536fd4cdd54a691ceb233ce92a/src/cred.rs#L293

If I add C:\Program Files\Git\bin which contains sh.exe to the path, everything works as expected.

I'm getting the same error again, even though it was working after I had installed pageant.

> cargo build -vvvv
Updating git repository `https://github.com/Boscop/project`
failed to load source for a dependency on `project`

Caused by:
  Unable to update https://github.com/Boscop/project

Caused by:
  failed to fetch into C:\Users\me\.cargo\git\db\project-254061b0f975c506

Caused by:
  failed to authenticate when downloading repository
attempted to find username/password via git's `credential.helper` support, but failed

Caused by:
  an unknown git error occurred

Why isn't it working anymore?

I'm using this format in Cargo.toml:

project = { git = 'https://github.com/username/project' }

Do I have to write it differently now? Like this?:

project = { git = 'ssh://git@github.com:username/project.git' }

But then cargo complains about invalid manifest because of the :. And when I use / instead, it gives the same error as above..

I have GitHub Desktop: Chocolate-Covered Yaks (3.3.4.0) 50415df
git version 2.11.0.windows.3

Is it because of this?
https://github.com/Microsoft/Git-Credential-Manager-for-Windows#notice-experiencing-github-pushfetch-problems

How to fix this?

Can cargo please print more helpful error information about git failure in the future?

@Boscop Try this with https git repo. I had that error and got it working on windows. #5227

git config --global credential.helper manager

Not to hijack, but I have the same issue on linux with any "ssh" urls like "ssh://mike@mymachine.somewhere.com/var/git/myrepo.git" (or any other formatting that I've tried, for that matter). Nevermind, I forgot to "ssh-add"

I've got this now:

  • Ubuntu 18.04
  • cargo 1.37.0-nightly (4c1fa54 2019-06-24)
  • git config --global credential.helper "store --file <my credentials>"

Notes:

  • credential.helper 'cache' works in Cargo and it works from the git command line (outside of cargo)
  • same config credential.helper 'store' works from the git command line (outside of cargo) but fails in Cargo
  • Private repo is on a private enterprise server running BitBucket.
  • only using https, no ssh

I have the same issue as @norru on Windows 10.
Cargo version is 1.38.0-nightly (6e310f2ab 2019-07-07).

Ordinary checkout with git from command line works but not from cargo.
Private repo is on GitHub.com and needs https access because of lfs.
Note that we cannot use manager for git credentials, because our build is running on CI and you cannot provision credentials to manager from the script.

Any update on this? @stasostrovskyi did you find a solution?

Still open as of 209-08-16

Have to use credential.helper 'cache' and have to manually clone a bogus repository every time the cache expires to refresh the credentials.

I'm experiencing this too on macOS. It happens with private repos with restricted access. I'm able to git clone those repos without problems using the git command directly, but cargo update doesn't work: failed to acquire username/password from local configuration.

Edit: In my case, git config --global credential.helper osxkeychain made it work.

I'm facing this same problem in Linux (Arch).

commented

I encounter the same issue with https authentication.

Is there currently a solution available ?

In my case, I had this snippet in my ~/.gitconfig

[url "ssh://git@github.com/"]
	insteadOf = https://github.com/

I had to get rid of that. Then the error stopped happening for me.

Here is what I did for fixing my cargo add xx issue:

  • brew install cargo-edit
  • remove both url "git@github.com:" and url "ssh://git@github.com/" sections in ~/.gitconfig

I solved it on Mac by installing third-party (Microsoft) credential-manager

brew tap microsoft/git
brew install --cask git-credential-manager-core
git config --global credential.credentialStore keychain

I'm experiencing this too on macOS. It happens with private repos with restricted access. I'm able to git clone those repos without problems using the git command directly, but cargo update doesn't work: failed to acquire username/password from local configuration.

Edit: In my case, git config --global credential.helper osxkeychain made it work.

Worked flawlessly here on my MacBook. Thank you very much!