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

Authentication failure with git dependencies via https on Windows (10) #5227

Closed
ghost opened this issue Mar 22, 2018 · 21 comments
Closed

Authentication failure with git dependencies via https on Windows (10) #5227

ghost opened this issue Mar 22, 2018 · 21 comments

Comments

@ghost
Copy link

ghost commented Mar 22, 2018

Summary

Cargo fails to load a git dependency over https on Windows because of not finding the credentials via git's credentials-helper. The credentials are saved in Windows Credentials Manager and a normal git clone works perfectly fine without entering credentials. The problem is not present on Linux using credentials-cache.

What we have tried

  • including a crate from an private repository via https located on a personal Gitlab instance or Bitbucket using cargo with a dependency like pfwr = { git = "https://git.****.****/****/pfwr.git" }
  • using plain text credentials-store in the global .gitconfig instead of the credentials-manager

What we expected

  • cargo should download the dependency from git authenticating via the credential-helper like on Linux when building the project

What happened instead

  • cargo fails to load the source:
> cargo run --verbose
    Updating git repository `https://git.****.****/****/pfwr.git`
error: failed to load source for a dependency on `pfwr`

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

Caused by:
  failed to fetch into C:\Users\****\.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
  • plain text credentials in global .gitconfig seems to work on one W8.1 machine, but not on two W10 machines tested on

Cargo version

  • the output of cargo --version on my W10 machine is: cargo 0.25.0 (96d8071da 2018-02-26)
@alexcrichton
Copy link
Member

Thanks for the report! Can you share the global .gitconfig you have for the credential helper support?

This is likely due to https://github.com/alexcrichton/git2-rs/issues/274 but I'd just want to confirm!

@ghost
Copy link
Author

ghost commented Mar 22, 2018

My .gitconfig is as plain as it could be. After reading your answer I just added the helper = manager line again, but it doesn't change anything.

[user]
	name = ****
	email = ****@****.****
	
[credential]
	helper = manager

Changing the helper to wincred or store or removing the line does not seem to change anything.

Now I tried adding the Git/bin to my Path variable and I am able to start sh from cmd. But unfortunately cargo still fails.

Update

I have restartet my machine and now cargo is downloading my dependency. So it seems to be necessary to add the Git/bin path to the Path variable.

@alexcrichton
Copy link
Member

Ok thanks @spaeger! The fact that updating PATH didn't fix this is quite suspicious!

Would you be willing to try out a custom build of Cargo to see what the issue is? I've just added some debug logging for failed credential helper invocations, testing that out should hopefully be as easy as cloning this repository, adding this to Cargo.toml at the root:

[patch.crates-io]
git2 = { git = 'https://github.com/alexcrichton/git2-rs' }

and then cargo build should build Cargo

@alexcrichton
Copy link
Member

Oh and getting the logging out would look like:

$ RUST_LOG=git2=trace path/to/cargo/checkout/target/debug/cargo build

@ghost
Copy link
Author

ghost commented Mar 22, 2018

As I added to my comment above, it is now working after a restart. Maybe Powershell does not take it before a logout/login. So it was just an error on my side.

@alexcrichton
Copy link
Member

oh oops, sorry I missed that!

I'll look into removing the need to do that.

@ghost
Copy link
Author

ghost commented Mar 22, 2018

Thank you for your fast help! 👍

@ghost
Copy link
Author

ghost commented Apr 3, 2018

Today I unfortunately found out, that adding the PATH does not seem to work on my other W10 machine. I can open a shell with sh and run cargo run successfully, but directly in PowerShell or CMD it does not work and fails with the same error as above.

I tried to compile Cargo with the following lines added at top of the Cargo.toml:

[patch.crates-io]
git2 = { git = 'https://github.com/alexcrichton/git2-rs' }

but it fails with:

> cargo build
    Updating registry `https://github.com/rust-lang/crates.io-index`
error: multiple packages link to native library `git2`, but a native library can be linked only once

package `libgit2-sys v0.7.1 (https://github.com/alexcrichton/git2-rs.git#0c1eb687)`
    ... which is depended on by `git2 v0.7.1 (https://github.com/alexcrichton/git2-rs.git#0c1eb687)`
    ... which is depended on by `git2-curl v0.8.1`
    ... which is depended on by `cargo v0.27.0 (file:///C:/****/cargo)`
links to native library `git2`

package `libgit2-sys v0.7.1`
    ... which is depended on by `cargo v0.27.0 (file:///C:/****/cargo)`
also links to native library `git2`

Did I miss something?

@alexcrichton
Copy link
Member

@spaeger what version of Cargo/Rustc were you testing with?

@ghost
Copy link
Author

ghost commented Apr 3, 2018

I should be using the latest version:

> cargo --version
cargo 0.26.0 (41480f5cc 2018-02-26)

> rustup update
info: syncing channel updates for 'stable-x86_64-pc-windows-msvc'
info: syncing channel updates for 'nightly-x86_64-pc-windows-msvc'
info: checking for self-updates

   stable-x86_64-pc-windows-msvc unchanged - rustc 1.25.0 (84203cac6 2018-03-25)
  nightly-x86_64-pc-windows-msvc unchanged - rustc 1.26.0-nightly (06fa27d7c 2018-04-01)

@alexcrichton
Copy link
Member

@spaeger can you try using nightly and see if that helps?

@ghost
Copy link
Author

ghost commented Apr 4, 2018

@alexcrichton I just installed the latest nightly and tried building cargo (and downloading my git dependency). Both does still not work.

But the error got a bit shorter:

> cargo build
    Updating git repository `https://github.com/alexcrichton/git2-rs`
    Updating registry `https://github.com/rust-lang/crates.io-index`
error: multiple packages link to native library `git2`, but a native library can be linked only once

package `libgit2-sys v0.7.1`
    ... which is depended on by `cargo v0.27.0 (file:///C:/****/cargo)`
links to native library `git2`

package `libgit2-sys v0.7.1 (https://github.com/alexcrichton/git2-rs#0c1eb687)`
    ... which is depended on by `git2 v0.7.1 (https://github.com/alexcrichton/git2-rs#0c1eb687)`
    ... which is depended on by `cargo v0.27.0 (file:///C:/****/cargo)`
also links to native library `git2`
This is my `Cargo.toml` of the cargo crate, maybe I misunderstood something: [Expand]
[patch.crates-io]
git2 = { git = 'https://github.com/alexcrichton/git2-rs' }

[package]
name = "cargo"
version = "0.27.0"
authors = ["Yehuda Katz <[email protected]>",
           "Carl Lerche <[email protected]>",
           "Alex Crichton <[email protected]>"]
license = "MIT OR Apache-2.0"
homepage = "https://crates.io"
repository = "https://github.com/rust-lang/cargo"
documentation = "https://docs.rs/cargo"
description = """
Cargo, a package manager for Rust.
"""

[lib]
name = "cargo"
path = "src/cargo/lib.rs"

[dependencies]
atty = "0.2"
crates-io = { path = "src/crates-io", version = "0.16" }
crossbeam = "0.3"
crypto-hash = "0.3"
curl = "0.4.6"
env_logger = "0.5"
failure = "0.1.1"
filetime = "0.1"
flate2 = "1.0"
fs2 = "0.4"
git2 = "0.7.0"
git2-curl = "0.8"
glob = "0.2"
hex = "0.3"
home = "0.3"
ignore = "0.4"
lazy_static = "1.0.0"
jobserver = "0.1.9"
lazycell = "0.6"
libc = "0.2"
libgit2-sys = "0.7"
log = "0.4"
num_cpus = "1.0"
same-file = "1"
semver = { version = "0.9.0", features = ["serde"] }
serde = "1.0"
serde_derive = "1.0"
serde_ignored = "0.0.4"
serde_json = "1.0"
shell-escape = "0.1"
tar = { version = "0.4", default-features = false }
tempfile = "3.0"
termcolor = "0.3"
toml = "0.4"
url = "1.1"
clap = "2.31.2"

# Not actually needed right now but required to make sure that rls/cargo build
# with the same set of features in rust-lang/rust
num-traits = "0.2" # enable the default feature

[target.'cfg(target_os = "macos")'.dependencies]
core-foundation = { version = "0.5.1", features = ["mac_os_10_7_support"] }

[target.'cfg(windows)'.dependencies]
miow = "0.3"

[target.'cfg(windows)'.dependencies.winapi]
version = "0.3"
features = [
  "handleapi",
  "jobapi",
  "jobapi2",
  "minwindef",
  "ntdef",
  "ntstatus",
  "processenv",
  "processthreadsapi",
  "psapi",
  "synchapi",
  "winerror",
  "winbase",
  "wincon",
  "winnt",
]

[dev-dependencies]
bufstream = "0.1"

[[bin]]
name = "cargo"
test = false
doc = false

@ghost
Copy link
Author

ghost commented Apr 4, 2018

Okay, thanks to someones help, loading the git dependency works now.
Additionally to adding the Path I did the following:

  1. Installed Git Credential Manager for Windows

  2. Ran the command git config --global credential.helper manager

  3. Ran the command git config --global credentail.useHttpPath true

  4. Recloned the project from my git and entered the necessary login credentials

The first step should not be necessary, if one has already installed the manager with the git installation, since on my other machine it is working without the additional installation.

The third step should also not be necessary, since it was working without this on my other machine and I could remove the setting useHttpPath = true from the global .gitignore on this machine afterwards without breaking it.

Summary

To make git dependencies with https authentication working, this steps should be sufficient:

  • Add the ...\Git\bin folder (the bin dir inside the Git installation folder) to your PATH variables and restart the machine or relogin

  • Install Git Credential Manager for Windows if not already done with the normal Git for Windows installation

  • Set the credential helper: git config --global credential.helper manager

  • Clone some repository from the effected Git instance to save the login credentials in the manager

Should I close the issue or would you prefer to let it opened until this is implemented inside cargo?

@alexcrichton
Copy link
Member

@spaeger ok I'm glad you got it working!

With nightly though I was curious about whether nightly works for your project, not for building Cargo itself. Does nightly require the extra steps you mentioned shouldn't be neessary?

@ghost
Copy link
Author

ghost commented Apr 5, 2018

Loading the git dependency now seems to work on both of my machines with both nightly and stable.
In the global .gitconfig besides the user data just

[credential]
helper = manager

is set. On both the Path to Git/bin is added and on one additionally to the manager version installable with Git for Windows installation I have Git Credential Manager for Windows installed. So this extra installation could be redundant.

@alexcrichton
Copy link
Member

Ok good to confirm!

I think this was fixed in alexcrichton/git2-rs@256f12b which should be in nightly Cargo, so I'm going to close this in that case.

@insanitybit
Copy link

I'm on the latest nightly,

nightly-x86_64-unknown-linux-gnu unchanged - rustc 1.27.0-nightly (eeea94c11 2018-04-06)
cargo 1.26.0-nightly (b70ab13 2018-04-04)

This is a fairly 'fresh' install of Ubuntu and cargo. Ubuntu 16.04.3.

error: failed to load source for a dependency on `tower-grpc-build`             

Caused by:
  Unable to update https://github.com/tower-rs/tower-grpc-build

Caused by:
  failed to fetch into /home/indie/.cargo/git/db/tower-grpc-build-34ae44599ab52f58

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

Caused by:
  failed to acquire username/password from local configuration

@alexcrichton
Copy link
Member

@insanitybit do you have git's credential helper support configured and has your password previously been cached?

@insanitybit
Copy link

Er, actually, I probably don't have it configured since the system is new. But I pulled down other deps just fine:

tower-grpc = { git = "https://github.com/tower-rs/tower-grpc" }

This works, for example.

I'm unfamiliar with the credential helper/ configuration stuff - if this is on my end I'll happily go sort that out.

@alexcrichton
Copy link
Member

If you're cloning a public repo you probably don't need authentication and the way github is set up if you're asked for authentication it may mean that a typo was made?

@drewkett
Copy link

I just ran into this problem as well.

Each of the following failed

  • I tried adding Git/bin to path without any luck
  • I tried nightly and that didn't work either
  • git config --system credential.helper manager did not work

What did work was this

  • git config --global credential.helper manager did work

I undid the other changes before I tried the last one, so that seems to be all that's needed. So it looks like git in this case is not picking up the system config settings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants