Cargo git dependency - https authentication fails


#1

I found out about the possibility to directly include a git repository as dependency in cargo.
So I tried this for a private repo on my personal Gitlab instance via https, but it seems to have trouble authenticating:

error: failed to load source for a dependency on `pfwr`

Caused by:
  Unable to update https://git.*removed*.*removed*/pfwr.git

Caused by:
  failed to fetch into C:\Users\*removed*\.cargo\git\db\pfwr-3bec381543b163f9

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

I am using Windows 10 Pro and the Git Windows Credentials Manager, which is also set in my git config as credential-helper.
I can easily clone my repository even from the same command line instance via ‘git clone https://git.removed.removed/pfwr.git’ without entering my credentials, because they are already saved. But somehow cargo doesn’t seem to have access to this.
Does someone know how to solve this problem or is this a bug?
Thank you in advance! :slight_smile:


#2

It is a bug! I feel like I have seen it before, but cargo has a lot of open bugs so it is hard to find the exact one mabe https://github.com/rust-lang/cargo/issues/4605

If that does not match please open a new one!


#3

Do you have 2FA enabled? I have found that git has issues with 2fa & using https for repositories since it cannot complete the 2nd stage of authentication. Can you try using ssh and see if it works or not?


#4

Thank you for the answers.
No, I do not have 2FA enabled. I have disabled ssh on my personal Gitlab instance, but I tried it with a Bitbucket repository. Again, I can clone it via git and ssh, but I currently do not get it to work in cargo. How does the adress need to look like when using ssh?
I tried my normal Gitlab repo via https on Windows Subsystem for Linux and it worked using the credentials-cache. It seems to be a Windows related issue.


#5

This bug can be fixed by adding the Git/bin path to the Path environment variable. You can take a look at the Github issue I opened for more information: https://github.com/rust-lang/cargo/issues/5227