cargo: Cargo can't find git credentials for private repo anymore

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)

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 8
  • Comments: 28 (8 by maintainers)

Most upvoted comments

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’ve got this now:

  • Ubuntu 18.04
  • cargo 1.37.0-nightly (4c1fa54d1 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’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

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!

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

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

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.