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:[email protected]/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:[email protected]/username/bar.git
Initialized empty Git repository in /app/bevry-website/.git/
error: The requested URL returned error: 401 while accessing https://username:[email protected]/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:[email protected]/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).
Enabling GitHub Integration You can configure GitHub integration in the Deploy tab of apps in the Heroku Dashboard. To configure GitHub integration, you have to authenticate with GitHub. You only have to do this once per Heroku account. GitHub repo admin access is required for you to configure automatic GitHub deploys.
If you've been using git push heroku main to deploy your code, you can pull it down using the heroku git:clone command displayed in the Deploy section of the dashboard for your app. After pulling down your code, you can follow the instructions to push to your destination of choice.
Heroku does not have the private keys necessary to access your private Github repositories, and as such, attempts to access those private repos will fail. Rather than providing Heroku with the private keys necessary to access your Github repo, its much better to use OAuth 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With