简体   繁体   中英

Pulling in authenticated git repos on heroku

I've been trying to pull in some authenticated git repos on heroku, and hit a few problems.

Ideally, I'd love to be able to use the token solution here git pull https://<token>@github.com/username/bar.git or even a git pull https://username:password@github.com/username/bar.git solution is acceptable if the token solution isn't.

However, it seems heroku version of git (v1.7.0) struggles with https authenticated clones:

$ heroku run bash
$ git --version
git version 1.7.0
$ git clone https://username:password@github.com/username/bar.git
Initialized empty Git repository in /app/bevry-website/.git/
error: The requested URL returned error: 401 while accessing https://username:password@github.com/username/bar.git/info/refs
fatal: HTTP request failed

Installing a newer version of git (v1.7.12) onto the heroku instance and using that works fine:

$ heroku run bash
$ curl --silent --location http://git-core.googlecode.com/files/git-1.7.12.tar.gz | tar xz; cd git-1.7.12; make NO_TCLTK=YesPlease NO_PERL=YesPlease NO_GETTEXT=YesPlease NO_SVN_TESTS=YesPlease NO_MSGFMT=YesPlease NO_MSGFMT_EXTENDED_OPTIONS=YesPlease prefix=$HOME install; cd ..; rm -Rf git-1.7.12
$ ./bin/git --version
git version 1.7.12
$ ./bin/git clone https://username:password@github.com/username/bar.git
works fine :)

However, installing our own git version on the instance is not ideal as it takes a very long time to compile and install.

It seems that heroku does not offer any free support, which is unfortunte as I just need to tell them to upgrade their git version and all is good. However, as this is not possible, does anyone have any suggestions for doing authenticated https git clones on heroku? (I have managed to get authenticated ssh going by uploading a special .ssh directory with the repo, however that is not ideal for our situation as we would prefer to just use https and tokens).

If the git version is indeed 1.7.0, then it is way too old, since multiple fixes were done since then the http transport mechanism.
(like 1.11.7: Pushing to smart HTTP server with recent Git fails without having the username in the URL to force authentication, if the server is configured to allow GET anonymously, while requiring authentication for POST.)

Plus 1.7.8 introduces a way to cache the credentials:

The code to handle username/password for HTTP transactions used in " git push " & " git fetch " learned to talk "credential API" to external programs to cache or store them, to allow integration with platform native keychain mechanisms.

Your ssh workaround is one way, recompiling git another, but until heroku upgrade its default git, I don't see another way to safely authenticate with https for Heroku git repos.

I just had the exact same problem:

$ git clone https://username:password@github.com/username/bar.git
Initialized empty Git repository in /app/bevry-website/.git/
error: The requested URL returned error: 401 while accessing https://username:password@github.com/username/bar.git/info/refs
fatal: HTTP request failed

I used e-mail as username for Github. This is not supported by Heroku's git (version 1.7).

git clone https://username:password@github.com/username/bar.git

It works, if you use the actual Github username and NOT your e-mail.

The e-mail works as username with newer Git versions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM