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

Cargo can't find git credentials for private repo anymore #3487

Open
Boscop opened this issue Jan 2, 2017 · 28 comments
Open

Cargo can't find git credentials for private repo anymore #3487

Boscop opened this issue Jan 2, 2017 · 28 comments
Labels
A-git Area: anything dealing with git C-bug Category: bug O-windows OS: Windows S-triage Status: This issue is waiting on initial triage.

Comments

@Boscop
Copy link

Boscop commented Jan 2, 2017

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)

@alexcrichton
Copy link
Member

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

@jjpe
Copy link

jjpe commented May 9, 2017

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).

@alexcrichton
Copy link
Member

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?

@Boscop
Copy link
Author

Boscop commented Jul 20, 2017

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?

@alexcrichton
Copy link
Member

@Boscop are you on Windows?

@Boscop
Copy link
Author

Boscop commented Jul 21, 2017

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.

@alexcrichton
Copy link
Member

@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?

@Boscop
Copy link
Author

Boscop commented Jul 22, 2017

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

@alexcrichton
Copy link
Member

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...

@Boscop
Copy link
Author

Boscop commented Jul 25, 2017

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...

@alexcrichton
Copy link
Member

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.

@Boscop
Copy link
Author

Boscop commented Aug 4, 2017

@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)?

@jjpe
Copy link

jjpe commented Aug 4, 2017

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.

@carols10cents carols10cents added A-git Area: anything dealing with git C-bug Category: bug O-windows OS: Windows labels Sep 29, 2017
@mcgoo
Copy link
Contributor

mcgoo commented Dec 5, 2017

@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.

@Boscop
Copy link
Author

Boscop commented Mar 25, 2018

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://[email protected]: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?

@drewkett
Copy link

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

git config --global credential.helper manager

@mikedilger
Copy link

mikedilger commented Oct 30, 2018

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

@norru
Copy link

norru commented Jul 3, 2019

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

@stasostrovskyi
Copy link

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.

@gruberb
Copy link

gruberb commented Aug 16, 2019

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

@norru
Copy link

norru commented Aug 16, 2019

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.

@golddranks
Copy link
Contributor

golddranks commented Oct 15, 2019

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.

@omarabid
Copy link

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

@steinemann
Copy link

I encounter the same issue with https authentication.

Is there currently a solution available ?

@floer32
Copy link

floer32 commented Dec 2, 2021

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

[url "ssh://[email protected]/"]
	insteadOf = https://github.com/

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

@chenrui333
Copy link

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

@AlexMikhalev
Copy link

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

@omatheuso
Copy link

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!

@epage epage added the S-triage Status: This issue is waiting on initial triage. label Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-git Area: anything dealing with git C-bug Category: bug O-windows OS: Windows S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests