Heroku / Elixir Phoenix Framework - host key verification failing for private Gitlab repos - heroku

I'm working on deploying a Phoenix app to Heroku, but several of the dependencies are in private Gitlab repos, and I am having trouble gaining access to them via SSH. When I try to push my app up, I hit the following error related to one of the dependencies (to which I normally have SSH access on my local machine):
remote: -----> Fetching app dependencies with mix
remote: * Getting cool_dep (git#gitlab.com:group/cool_dep.git)
remote: Host key verification failed.
remote: fatal: Could not read from remote repository.
remote:
remote: Please make sure you have the correct access rights
remote: and the repository exists.
So here's what I've done so far - if anyone can tell me what I'm missing or have done wrong, it would be much appreciated...
Generated a new public/private key pair for this Heroku deployment. I put the public key into the SSH keys in my Gitlab settings. (the keys do not have a secret passphrase)
Added the debitoor/ssh-private-key buildpack to my buildpacks so that they read like so:
https://github.com/debitoor/ssh-private-key-buildpack.git
https://github.com/HashNuke/heroku-buildpack-elixir.git
https://github.com/gjaldon/heroku-buildpack-phoenix-static.git
Added the private key counterpart of the public key to the app's config:
$ heroku config:set SSH_KEY=$(cat /Users/username/.ssh/heroku_id_rsa | base64) --app cool-app-12345
Set the SSH hosts in the app's config:
$ heroku config:set SSH_HOSTS="git#gitlab.com" --app cool-app-12345
And finally, when I run git subtree push --prefix local_app cool-app-12345 master, it starts to load up but then flops when it hits the first private dependency.
Can anyone clarify what I am missing here? Why is that host key verification failing?
also worth noting - I tested the public/private key pair by doing a basic $ git clone ... and that worked just fine, so the key relationship is valid... just seems to be a problem when Heroku gets in the mix.

I pulled the source code for the buildpack and started poking around - I found that the SSH_HOST config variable that I was setting - git#gitlab.com - was not being found, and it was just defaulting to the single git#github.com host that's hard-coded in... the docs say that you can add additional hosts, but it didn't seem to be working for me.
I was able to resolve this issue by cloning the buildpack and replacing line 13 in bin/compile with
ssh_hosts=${SSH_HOSTS:-"git#gitlab.com"}
So if your private repos are in Github, you're probably fine... but if they're on a different host, you may need to grab the buildpack code and host it on your own repo with custom hosts.

Related

git push heroku master fails in heroku

I am starting out with heroku and am following the getting to start with heroku tutorial. I am on windows 7 and am using Windows powershell as the command line.
The commands that I am using are
git clone git://github.com/heroku/ruby-sample.git
cd ruby-sample
heroku login
heroku create
git push heroku master
heroku open
The directory was cloned and after heroku login I got Authentication successful. in the command line. After heroku create I got
Creating immense-lowlands-8694... done, stack is cedar
http://immense-lowlands-8694.herokuapp.com/ | git#heroku.com:immense-lowlands-8694.git
Git remote heroku added
so the app was added to my heroku account. But there was problem with git push heroku master. I got
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
What I have tried so far
This question said about adding keys but it is for Linux and didn't work for Windows 7.
I used heroku keys and it says that there is a key present for my e-mail ID.
As this answer says I tried heroku keys:add and got
this
Found existing public key: C:/Users/Aseem/.ssh/github_rsa.pub
Uploading SSH public key C:/Users/Aseem/.ssh/github_rsa.pub... done
but after that the error didn't end.
I tried what this answer says but ssh-keygen wasn't recognized so I guess it's for linux.
I tried removing using heroku keys:remove KEY_NAME and then heroku login to login again but that didn't take care of the error either.
What can I do to solve the problem?
Installed MSysGit instead of git. Added the C:\Program Files(x86)\Git\bin directory to the PATH variable and then doing what this answer says solved the problem.

Error trying to push a project into Heroku

Environment: Windows 7
I go to Start | Run and type cmd.
I changed to my directory on my local hard drive and I was able to successfully clone the Github project:
git clone git://github.com/heroku/ruby-sample.git
I then change to the directory:
cd ruby-sample
I'm able to run the Heroku create:
heroku create
I log into Heroku via Firefox and I can see my App directory on Heroku. So far, so good. Then I try and push:
git push heroku master
and every time I get the same error:
ssh_exchange_identification: Connection closed by remote host
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
I've Googgled and looked at a number of similar questions; but unfortunately, I'll be the first to admin that Linux is a very weak area for me. I haven't found an answer that is specific to this setup on a Windows 7 environment. I do have the Heroku Toolbelt installed.
Thank you!
V
(I realized I assumed Rails here and you did not specify that. If you aren't using Rails, ignore the comment about RailsInstaller and RailsBridge.)
You may need to add your ssh key to your heroku setup with:
heroku keys:add
If you used RailsInstaller, that should just work. If not, and you don't have an ssh key pair, you'll need to look up how to do that first. You can use PuTTY to do that: http://kb.site5.com/shell-access-ssh/how-to-generate-ssh-keys-and-connect-to-your-account-with-putty/
For a full procedure that will get an app bootstrapped onto Heroku with a Rails app, see: http://installfest.railsbridge.org/installfest/installfest

How do I access a private github repo from heroku?

I have a private repo that I'm trying to access when deploying to Heroku. However, Heroku doesn't let me clone the private repo, and gives me the following error (as i would expect):
Host key verification failed.
fatal: The remote end hung up unexpectedly
Git error: command `git clone
'git#github.com:pr/lm-models.git'
"/tmp/build_3r0z0znww0zda/vendor/bundle/ruby/1.9.1/cache/bundler/git/lm-models-aab025aaadbe07202b16e1db7505ae1726f8723a"
--bare --no-hardlinks` in directory /tmp/build_3r0z0znww0zda has failed.
!
! Failed to install gems via Bundler.
!
! Heroku push rejected, failed to compile Ruby/rails app
I have found this, but do not want to display my username/password in clear text:
Linking heroku app to a private(organization) github repo
This worked for me:
Generate a Github Access Token
In requirements.txt list private module as follows:
git+https://your_user_name:your_git_token#github.com/your_company/your_module.git
Heroku only supports HTTP(S) Basic authentication with Git out of the box. That's unfortunate as it means you'd need to add your credentials as part of the installation URL and commit that as plain text in your list of dependencies. For your app to support SSH keys instead, do the following:
Create a new SSH key which will be used by Heroku to access the GitHub repository. Choose a distinct name, e.g. id_rsa_heroku.
Add the public part of the key to your GitHub account (link to settings).
Use the heroku-buildpack-ssh-key: heroku buildpacks:add https://github.com/heroku/heroku-buildpack-ssh-key.git -i 1
Set the private part of the key as an environment variable for your Heroku app: heroku config:set BUILDPACK_SSH_KEY=$(cat ~/.ssh/id_rsa_heroku)
From this moment, Heroku should be able to access and download code from any private repositories you have access to.
You need to use username/password in the Gemfile, or vendor the dependency. You can also use Gemfury (assuming it's a gem):
https://devcenter.heroku.com/articles/git-submodules#vendoring
http://gembundler.com/v1.3/bundle_package.html
https://devcenter.heroku.com/articles/gemfury

git push heroku master Permission denied (publickey)

Edit #3
Updating this at the top because it solved my issue and gave me a good troubleshooting step I didn't know about (and could save you some time, too)
Try getting the output of ssh -vvv git#heroku.com. For me, ssh was getting hung up on trying keys in /c/Program Files (x86)/Emacs/.ssh when my public key was in /c/Users/NumberOverZero/.ssh
Deleting the Emacs ssh folder (which was empty) fixed my issue since ssh would then check my Users .ssh folder.
I'm getting Permission denied (publickey) when trying to git push heroku master.
A few things that makes this different from the posts below:
I have ssh working for github
I was able to successfully push to heroku last night
Since that push, I've made a single-line change to one js file, and committed and pushed. There have been no other changes.
The closest I could find was this post:
git clone heroku ssh permission denied
I've looked through the related issues (there's quite a few):
git push heroku master Permission denied (publickey). fatal: The remote end hung up unexpectedly
git push heroku master permission denied
git clone heroku ssh permission denied
https://stackoverflow.com/questions/13059076/git-push-permission-denied-publickey-windows-xp
heroku - rails - Permission denied (publickey)
I've tried:
heroku keys:clear
heroku keys:add
heroku keys:clear
*delete every key in .ssh*
heroku keys:add
*delete my application on heroku*
heroku keys:clear
heroku login (adds key for me)
heroku create
git push heroku master
fails
*delete the app on heroku*
delete keys in .ssh
heroku keys:clear
copy all files into a new repository
push new repository to github successfully
heroku login (adds github key for me)
heroku create
git push heroku master
fails
*delete the app on heroku*
heroku keys:clear
heroku login (adds key for me)
heroku create
heroku git:clone app app
fails
Any ideas? I've gone through all of the steps in the linked SOs - most of which were just people not running heroku:add or setting up ssh keys (which I've done in each of these).
I let heroku take the wheel most of the time, (instead of directly creating ssh keys) assuming that the built-in commands would do what they needed when there were no ssh keys present. It seems not.
EDIT: And now that I deleted the app, the new relic addon is alarming that the website is down. Trying to log in through their website asks me to log in through heroku. Which I can't find a way to do, since the app is gone. Is there a way to delete that addon now that I can't get to the app? heroku addons gives an error, so I don't think I'm getting to it through there.
EDIT #2: Added another step I tried - moved files into new repository and push to new application.
I had the same problem for Windows 7 box and found the solution here: http://www.gmarwaha.com/blog/2011/05/18/heroku-trouble-with-windows-and-ssh-keys/
Solution: Typically once you create the keys as mentioned above, two files – “id_rsa” and “id_rsa.pub” – are stored in the “.ssh” folder
within the user’s home folder. If you are working with linux that
seems to be good enough. But for the windows version of git that
doesn’t seem to cut it. It wants the keys to be stored inside the
“.ssh” folder within the “msysgit” installation folder as well. If you
don’t find a “.ssh” folder inside the “msysgit” installation folder,
feel free to create one. Once you drop these two key files there and
repeat the entire process, everything went as smooth and my
application got deployed in the heroku cloud and the world is again a
better place to live in.
In my case, I have to find where git.exe was installed, which is C:\Program Files\Git\. So here are the steps:
Create .ssh folder inside C:\Program Files\Git\
Copy id_rsa and id_rsa.pub from your home folder (C:\Users\username\.ssh\) to C:\Program Files\Git\.ssh\.
Try again with C:\dev\heroku\sample-app> git push heroku master.
Nice job linking to all the other things you've looked at and tried! (that will improve the responses you get, but still you should be prepared for a lot of 'have you tried...', and 'maybe it's ...' because this is a system/env issue that isn't on the normal flow)
You might have had something working in your local terminal session that has since been lost. (I've had this happen a bunch of times)
Things it might be:
your ssh keys on heroku
your ability to push up to heroku from that computer/network
something about your git repo
I ran into this once and it was driving me crazy. I hopped on my (FREE) cloud9 account, cloned some simple rails app from github and pushed it out to heroku, which helped me prove that my heroku account was fine, heroku itself was fine, but my local laptop had some issues in my configuration.
I think the issue was my username, but I don't remember. (moving to a different env and starting from scratch helped me realize the issue though)
The main reason you get this message is because you do not have ssh-keygen added to your environment variables.
This command is located in the bin-directory of Git program files.
You should add that bin directory to your environment variables.

Can't clone my heroku project

I'm not sure what's wrong with my heroku account, but I'm no longer able to clone my heroku project.
NOTE : Please do not close this question considering as duplicate question of this
as I have described below that I tried all solutions mentioned in the answers to that question
! Your key with fingerprint XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX is not authorized to access genqr
Whenever I do
git clone git#heroku.com:genqr.git
I have done everything humanly possible.
1. I have deleted all my keys of heroku added a new key
using
heroku keys:remove
and
heroku keys:add /home/vire2egi/.ssh/setup.pub
Still, the same problem when cloning the project happens.
2. I also added heroku key to ssh-add
ssh-add /home/vire2egi/.ssh/setup
3. Also added key to keychain
eval `keychain --eval setup`
All the above commands result in success but still I can't clone the repo
4. I also did
heroku keys:remove
heroku auth:logout
heroku auth:login ## Authenticated myself and then added the key: still no success
Still no success
5. I also defined a config for heroku, something like
Host heroku.com
Hostname heroku.com
User viren2egi
IdentityFile /home/vire2egi/.ssh/setup
Still no success.
6. Out of fustration I created a brand new key.
ssh-keygen -t rsa
And repeated all the above set for that key too, but still I get the same problem.
I also cleaned my known_hosts everytime I ran anyone of the above commands just to make sure it does not pick from it.
Note :
Whenever I tried heroku:keys, it always presented me with the correct information of the key that I have added
Can anyone help me?
When you do a git operation it uses any ssh keys you have loaded locally in some order (I believe the order in which they were loaded). It may be that you have an old key still loaded and when you do a git operation it tries that key first and fails and does not go on to the next key if there's a failure.
So... try unloading all your ssh-keys with ssh-add -D, then loading the most recent key you created and added to heroku:
$ ssh-add -D
$ ssh-add /home/vire2egi/.ssh/setup
$ git clone git#heroku.com:genqr.git
???
I had the same problem. The steps described in http://rakshasingh.weebly.com/1/post/2013/04/accessing-multiple-heroku-accounts-from-one-machine.html helped me well. Last part about cloning from existing heroku app is important.

Resources