How do I resolve "Host key verification" error on Heroku deployment?

Viewed 579

When trying to deploy a branch on a Heroku app, I'm getting the following error:

   Host key verification failed.
   fatal: Could not read from remote repository.

There is one exception to this verification failed: I can deploy my branch on one specific pre-existing app with no issue. However, other than that specific app, I can't seem to deploy the branch - even when I create entirely new apps.

Heroku has a support page for this particular issue here: https://help.heroku.com/SP5I8HXO/host-key-verification-error-when-accessing-private-github-repository

However, it's not clear to me what I should do once I generate the PAT. Also, it's not clear to me why this issue would show up on review apps (part of the same pipeline as the one app that's working) and on entirely new apps.

How do I resolve this issue?

Edit:

Here's the complete deployment log.

   Building on the Heroku-18 stack
   Determining which buildpack to use for this app
   Node.js app detected
   
   Creating runtime environment
   
   NPM_CONFIG_LOGLEVEL=error
   USE_YARN_CACHE=true
   NODE_ENV=production
   NODE_MODULES_CACHE=true
   NODE_VERBOSE=false
   
   Installing binaries
   engines.node (package.json):  16.x
   engines.npm (package.json):   unspecified (use default)
   engines.yarn (package.json):  1.22.x
   
   Resolving node version 16.x...
   Downloading and installing node 16.13.1...
   Using default npm version: 8.1.2
   Resolving yarn version 1.22.x...
   Downloading and installing yarn (1.22.17)
   Installed yarn 1.22.17
   
   Installing dependencies
   Installing node modules (yarn.lock)
   yarn install v1.22.17
   [1/4] Resolving packages...
   warning react-scripts > webpack-dev-server > chokidar > fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
   [2/4] Fetching packages...
   error Command failed.
   Exit code: 128
   Command: git
   Arguments: ls-remote --tags --heads ssh://git@github.com/ljharb/qs.git
   Directory: /tmp/build_5650c4ab
   Output:
   Host key verification failed.
   fatal: Could not read from remote repository.
   
   Please make sure you have the correct access rights
   and the repository exists.
   info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
2 Answers

I recently solved this issue which occurred when switching over to yarn from npm.

The solution was to clear the buildpack cache.

I was deploying using a github actions script, here is what I did.

In the file .github/workflows/deploy.yml which configured the deployment to heroku through github actions I added buildpack: false.

This cleared the buildpack cache in heroku and then the deployment completed successfully.

Afterwards I enabled buildpack caching again and all was well.

Heroku's documentation isn't entirely clear:

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.

This affects access via SSH, i.e. URLs named like git@github.com:username/repo.git.

The suggestion to use a token instead also requires that you change to an HTTPS URL. You can copy your HTTPS URL from your repository, via the "Code" dropdown:

Screenshot

Click on "HTTPS", then copy the URL. Or, you can just reformat your existing URL so that it matches https://github.com/username/repo.git.

The token you generated can be used in place of a password when cloning via HTTPS, but you need to provide it to Heroku somehow. URLs have a built-in mechanism for this, called the "authority".

To add the username username and personal access token token to the URL, add username:token@ between https:// and github.com:

https://username:token@github.com/username/repo.git

Give that URL to Heroku and try again.

Related