cargo-scaffold
cargo-scaffold copied to clipboard
Scaffold cloning mechanism not respecting git ssh configuration
My authentication with GitHub is done with SSH keys (rather than https://
) and I use a Yubikey to provide my SSH keys. I assure you that my git
commands work properly. 😉
To ensure I use git+ssh
rather than https://
for cloning things, I have the following in my ~/.gitconfig
:
[url "[email protected]:"]
insteadOf = https://github.com/
So, proving my git
works:
$ git clone https://github.com/apollographql/router.git
Cloning into 'router'...
remote: Enumerating objects: 20071, done.
remote: Counting objects: 100% (110/110), done.
remote: Compressing objects: 100% (72/72), done.
remote: Total 20071 (delta 66), reused 61 (delta 38), pack-reused 19961
Receiving objects: 100% (20071/20071), 7.17 MiB | 6.66 MiB/s, done.
Resolving deltas: 100% (14418/14418), done.
However, when I try this with cargo-scaffold
using the https://
URL, I receive:
$ cargo-scaffold scaffold https://github.com/apollographql/router.git -r apollo-router-scaffold/templates/base
🔄 Cloning repository…
Error: authentication required but no callback set; class=Ssh (23); code=Auth (-16)
... and with the git+ssh
approach:
$ cargo-scaffold scaffold [email protected]:apollographql/router.git -r apollo-router-scaffold/templates/base
🔄 Cloning repository…
Error: Failed to authenticate SSH session: Unable to extract public key from private key file: Unable to open private key file; class=Ssh (23)
Ultimately, I think this comes down to the same challenge that cargo
ran into by trying to use an underlying git
library that wasn't a full implementation of the git
CLI's abilities — for example, the CARGO_NET_GIT_FETCH_WITH_CLI
env variable and its corresponding setting. (For what it's worth, I tried using that env variable, but it didn't help, though I'm not surprised since that's cargo
-specific behavior).
Those limitations are explained a bit in https://github.com/rust-lang/cargo/blob/9ded34a558a900563b0acf3730e223c649cf859d/src/cargo/sources/git/utils.rs#L816-L905 where you can see how they work around it.