Running a npm install git+ssh://<git repo url> from the Kudu's console in an Azure App Service instance fails with following error:
npm ERR! Host key verification failed.
npm ERR! fatal: Could not read from remote repository.
People often solve this error by adding the host's key to the .ssh/known_hosts file. The problem is that the correct key is already there. If it wasn't there, git clone <git repo url> would fail with the same error, but it does not. It successfully clones the repository.
In order to debug the issue, I tried to set the SSH's log level to DEBUG3 via the ~/.ssh/config file but the output did not change (while with git clone, it prints the debug info).
So, because of that I suspect that the problem is that the SSH client used by npm in Azure does not take the ~/.ssh directory into account.
My question is, is this documented somewhere or is it bug? Do you have any idea in which component the bug is?
FTR, the full output is:
npm ERR! git clone --template=D:\local\AppData\npm-cache\_git-remotes\_templates --mirror <git repo url> D:\local\AppData\npm-cache\_git-remotes\git-ssh-<git repo url>-dc8c35134031285cb7109c3e32618e85: Cloning into bare repository 'D:\local\AppData\npm-cache\_git-remotes\git-ssh-<git repo url>-dc8c35134031285cb7109c3e32618e85'...
npm ERR! git clone --template=D:\local\AppData\npm-cache\_git-remotes\_templates --mirror <git repo url> D:\local\AppData\npm-cache\_git-remotes\git-ssh-<git repo url>-dc8c35134031285cb7109c3e32618e85:
npm ERR! git clone --template=D:\local\AppData\npm-cache\_git-remotes\_templates --mirror <git repo url> D:\local\AppData\npm-cache\_git-remotes\git-ssh-<git repo url>-dc8c35134031285cb7109c3e32618e85: Host key verification failed.
npm ERR! git clone --template=D:\local\AppData\npm-cache\_git-remotes\_templates --mirror <git repo url> D:\local\AppData\npm-cache\_git-remotes\git-ssh-<git repo url>-dc8c35134031285cb7109c3e32618e85: fatal: Could not read from remote repository.
npm ERR! git clone --template=D:\local\AppData\npm-cache\_git-remotes\_templates --mirror <git repo url> D:\local\AppData\npm-cache\_git-remotes\git-ssh-<git repo url>-dc8c35134031285cb7109c3e32618e85:
npm ERR! git clone --template=D:\local\AppData\npm-cache\_git-remotes\_templates --mirror <git repo url> D:\local\AppData\npm-cache\_git-remotes\git-ssh-<git repo url>-dc8c35134031285cb7109c3e32618e85: Please make sure you have the correct access rights
npm ERR! git clone --template=D:\local\AppData\npm-cache\_git-remotes\_templates --mirror <git repo url> D:\local\AppData\npm-cache\_git-remotes\git-ssh-<git repo url>-dc8c35134031285cb7109c3e32618e85: and the repository exists.
npm ERR! Windows_NT 6.2.9200
npm ERR! argv "D:\\Program Files (x86)\\nodejs\\4.2.3\\node.exe" "D:\\Program Files (x86)\\npm\\3.5.1\\node_modules\\npm\\bin\\npm-cli.js" "install" "git+ssh://<git repo url>"
npm ERR! node v4.2.3
npm ERR! npm v3.5.1
npm ERR! code 128
npm ERR! Command failed: git -c core.longpaths=true clone --template=D:\local\AppData\npm-cache\_git-remotes\_templates --mirror <git repo url> D:\local\AppData\npm-cache\_git-remotes\git-ssh-<git repo url>-dc8c35134031285cb7109c3e32618e85
npm ERR! Host key verification failed.
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR!
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! D:\home\site\foo\npm-debug.log
Here's how SSH settings (config file, known hosts, public / private keys) seem to be handled on Azure App Service:
The default folder for SSH configuration is D:\home\.ssh. This is what SSH and Git in the Kudu Debug Console use.
When you trigger host key generation through https://your-site.scm.azurewebsites.net/sshkey?ensurePublicKey=1, it'll create the D:\home\.ssh folder and place a config file with StrictHostKeyChecking no into it (as well as the newly generated SSH key). This means that SSH run through the Debug Console will now auto-accept hostkeys.
npm on Azure App Service expects the SSH configuration in %USERPROFILE%. You can see that when you run npm in the Debug Console for the first time, it will create the empty folder %USERPROFILE%\.ssh.
For npm compatibility, Kudu's deployment script will copy the D:\home\.ssh folder to %USERPROFILE% (see issue / fix). This should be happening every time you deploy through the web app's local Git repository, through Github or any of the other deployment options that trigger Kudu.
In my experience, that copied .ssh folder in %USERPROFILE% will be removed again when scaling and when restarting the app.
What I think happened in my case was that while debugging a different npm/git/ssh issue, I restarted the web app. I then ended up with the host key verification issue when running npm install manually in the Debug Console.
So for me the problem was that my app service was deployed through Github and hence had a deployment key associated with it's repo on Github.
To be able to access my other private repos I needed to do the following.
Remove the deployment key.
Get the public key from https://[your-web-app].scm.azurewebsites.net/api/sshkey?ensurePublicKey=1
Add the key to my SSH keys in github.
After this npm would happily install my private repos.
Related
I am getting the error below when using "npm run deploy". This repo was cloned using https.
UPDATE: It seems to be working after this quick revision of the remote set-url. The repo wasn't cloned using the SSH option so the remote set-url required the appropriate "https://" instead. Have a great day!
I changed the "git remote set-url origin git#github.com!laurenwatkins!laurenwatkins.github.io"
to git remote set-url origin https://github.com/laurenwatkins/laurenwatkins.github.io.git
> saadpasta.github.io#0.1.0 deploy C:\Users\laurenwatkins\Software\developerFolio
> gh-pages -b master -d build
Cloning into 'node_modules\gh-pages\.cache\git#github.com!laurenwatkins!laurenwatkins.github.io'...
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! saadpasta.github.io#0.1.0 deploy: `gh-pages -b master -d build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the saadpasta.github.io#0.1.0 deploy script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\laurenwatkins\AppData\Roaming\npm-cache\_logs\2020-02-13T11_07_18_464Z-debug.log
UPDATE: It seems to be working after this quick revision of the remote set-url. The repo wasn't cloned using the SSH option so the remote set-url required the appropriate "https://" instead. Have a great day!
The following "git remote set-url origin was changed.
Previous URL(error): git#github.com!laurenwatkins!laurenwatkins.github.io"
Updated URL(working): git remote set-url origin https://github.com/laurenwatkins/laurenwatkins.github.io.git
Getting permission denied error for a local repo, which I can clone successfully, however getting error for npm install:npm install
npm ERR! Error while executing:
npm ERR! C:\Program Files\Git\cmd\git.EXE ls-remote -h -t ssh://git#stash.company.com:2222/castor/module-name.git
npm ERR!
npm ERR! git#stash.company.com: Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR!
npm ERR! exited with error code: 128
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\MOEL3\AppData\Roaming\npm-cache\_logs\2018-03-08T18_12_33_006Z-debug.log
However, I have to put my password each time I do a git command regarding the remote repo pull, push etc... would that be the reason? howto solve this problem?
Recently came across this issue, so frustrating...
I could git clone a private repo no problems, but as soon as I tried to npm install a package through Visual Studio Code, it fell over on what looked like an authentication error.
git#github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
What fixed it for me was opening Sublime Text as Administrator, locating the ssh_config file in the C:ProgramFiles/Git/etc/ssh/ folder, opening this in the Admin sublime window, and adding this at the bottom
HOST github.com
IdentityFile /c/Users/me/.ssh/id_rsa
It turned out that npm install was looking in the root folder for my key, not in the home folder. Telling it to take the key from the identity in my user folder solved the issue.
Hope this may help someone else.
I need to install a private github module via npm on an AWS Beanstalk instance.
I'm using a Github personal access token to authenticate with github and access the repo.
My package.json lists the dependency like this:
"privatepackage": "git+https://jaf91ja9jasflkjasf98109asf10asdf:x-oauth-basic#github.com/user123/privatepackage.git"
However, on Beanstalk I get the following error when deploying:
npm ERR! node v0.12.2
npm ERR! npm v2.7.4
npm ERR! code 128
npm ERR! Command failed: git clone --template=/tmp/.npm/_git-remotes/_templates --mirror git#github.com...
npm ERR! Cloning into bare repository '/tmp/.npm/_git-remotes/git-github-com...
npm ERR! Host key verification failed.
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
I think you are missing ssh key on your machine and adding same on github.
Please look into generating-ssh-keys which might helps you to resolve this issue.
I'm getting an error deploying to Elastic Beanstalk, because there is no git on the instance. One of the dependencies in my package.json is dependant on a git repository and needs to git clone.
Git is not installed on the instances. I tried installing it through .ebextensions .conf file while deploying, through yum, but when I ssh into the instance it's not there.
Question is: what is the correct way to install and have git on a Linux instance running on Elastic Beanstalk before npm install is called on that instance?
Here's the log showing the error:
[2015-04-18T09:00:02.815Z] ERROR [1777] : Command execution failed: Activity failed. (ElasticBeanstalk::ActivityFatalError)
caused by: + /opt/elasticbeanstalk/containerfiles/ebnode.py --action npm-install
npm WARN package.json amity-api-v2#2.0.0 No repository field.
npm WARN package.json amity-api-v2#2.0.0 No README data
npm WARN `git config --get remote.origin.url` returned wrong result (https://github.com/awslabs/dynamodb-document-js-sdk) undefined
npm WARN `git config --get remote.origin.url` returned wrong result (https://github.com/awslabs/dynamodb-document-js-sdk) undefined
npm ERR! git clone https://github.com/awslabs/dynamodb-document-js-sdk undefined
npm ERR! git clone https://github.com/awslabs/dynamodb-document-js-sdk undefined
npm ERR! Linux 3.14.35-28.38.amzn1.x86_64
npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v0.12.0-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v0.12.0-linux-x64/bin/npm" "--production" "install"
npm ERR! node v0.12.0
npm ERR! npm v2.5.1
npm ERR! code ENOGIT
npm ERR! not found: git
npm ERR!
npm ERR! Failed using git.
npm ERR! This is most likely not a problem with npm itself.
npm ERR! Please check if you have git installed and in your PATH.
If you put a config file in your .ebextensions folder like this:
packages:
yum:
git: []
Make sure the git package is in a config file with a higher execution index then one that actually requires git. It is common to have it in a first config file named: 00-packages.config.
I can think of three ways you could ensure git(or any dependency) is installed on the system before npm install is run.
Define a preinstall script in your package.json that installs git if required.
You can add a script(file), using ebextensions in either the pre-appdeploy hooks directory, or the preinit hooks directory. I would suggest the preinit hook, as that's where the hook for installing packages is. Just set the path of your script to /opt/ebextensions/hooks/preinit/99_install_git.sh, or if you want to do in pre-appdeploy, /opt/ebextensions/hooks/appdeploy/pre/99_install_git.sh, and make the file executable by using the mode field.
Using ebextensions to install a package.
For your use case, I think #3 is the best option. Kinda late, but I hope you find it useful
I am in process of setting up the the deployment of a Node.js Service with Docker.
The Dockerfile I have is pieced together from various examples from around the net.
The directory for the Dockerfile includes:
Dockerfile
id_rsa
start.sh
This is the Dockerfile:
FROM ubuntu:13.10
# make sure apt is up to date
RUN apt-get update
# install npm, git, ssh, curl
RUN apt-get install -y npm git git-core ssh curl
RUN mkdir /nodejs && curl http://nodejs.org/dist/v0.10.31/node-v0.10.31-linux-x64.tar.gz | tar xvzf - -C /nodejs --strip-components=1
# Fixes empty home
ENV PATH $PATH:/nodejs/bin
ENV HOME /root
# SSH SETUP
RUN mkdir -p /root/.ssh
ADD id_rsa /root/.ssh/id_rsa
RUN chmod 700 /root/.ssh/id_rsa
RUN echo "IdentityFile /root/.ssh/id_rsa" >> /root/.ssh/ssh_config
RUN ssh-keyscan github.com >> /root/.ssh/known_hosts
ADD start.sh /tmp/
RUN chmod +x /tmp/start.sh
CMD ./tmp/start.sh
After the set-up is complete, start.sh runs and I experience problems with a private NPM dependency that the private Node.js service has. This is what start.sh is doing:
cd /tmp
# try to remove the repo if it already exists
rm -rf MediaFX; true
git clone https://<username>:<password>#github.com/company/ExampleRepo.git
cd RepoName
node --version
ls
npm install
NODE_ENV=test DEBUG=* PORT=3000 node server.js
In package.json for ExampleRepo, there is one private module that we import like this:
"dependencies": {
"scribe": "git+ssh://git#github.com:Company/PrivateDep.git"
},
When npm install gets to this repo, it outputs these logs:
npm ERR! git clone git#github.com:InboxAppCo/scribe.git Cloning into bare repository '/root/.npm/_git-remotes/git-github-com-InboxAppCo-scribe-git-abae334a'...
npm ERR! git clone git#github.com:InboxAppCo/scribe.git
npm ERR! git clone git#github.com:InboxAppCo/scribe.git Warning: Permanently added the RSA host key for IP address '192.30.252.130' to the list of known hosts.
npm ERR! git clone git#github.com:InboxAppCo/scribe.git Permission denied (publickey).
npm ERR! git clone git#github.com:InboxAppCo/scribe.git fatal: Could not read from remote repository.
npm ERR! git clone git#github.com:InboxAppCo/scribe.git
npm ERR! git clone git#github.com:InboxAppCo/scribe.git Please make sure you have the correct access rights
npm ERR! git clone git#github.com:InboxAppCo/scribe.git and the repository exists.
npm ERR! Error: `git "clone" "--mirror" "git#github.com:InboxAppCo/scribe.git" "/root/.npm/_git-remotes/git-github-com-InboxAppCo-scribe-git-abae334a"` failed with 128
npm ERR! at ChildProcess.cpclosed (/usr/share/npm/lib/utils/exec.js:59:20)
npm ERR! at ChildProcess.EventEmitter.emit (events.js:98:17)
npm ERR! at Process.ChildProcess._handle.onexit (child_process.js:789:12)
npm ERR! If you need help, you may report this log at:
npm ERR! <http://bugs.debian.org/npm>
npm ERR! or use
npm ERR! reportbug --attach /tmp/MediaFX/npm-debug.log npm
npm ERR! System Linux 3.16.4-tinycore64
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install"
npm ERR! cwd /tmp/MediaFX
npm ERR! node -v v0.10.15
npm ERR! npm -v 1.2.18
I thought that since the git clone of the private Node service works fine, any of its private NPM dependencies would install smoothly.
I am fairly positive that my SSH set up is flawed (and that it didn't manifest its self while git cloning the private parents repo) because I added username and password to the link. However, I am unsure and would appreciate some guidance on how to do this correctly.
git clone https://<username>:<password>#github.com/company/ExampleRepo.git
Works, because you are passing the username and password and doing it over https
"dependencies": {
"scribe": "git+ssh://git#github.com:Company/PrivateDep.git"
},
Fails, because you are connecting directly over ssh and Docker doesn't do any ssh agent forwarding from the host machine.
Unfortunatly it dosen't look like npm supports any url format to send username and password like your clone line: https://docs.npmjs.com/files/package.json#git-urls-as-dependencies
You'd have to add your ssh keys to the docker container ( Not Reccomended )
Or do something funky like share you SSH_SOCKET from the host like:
https://gist.github.com/d11wtq/8699521
Here's an approach I'm going to try implementing this evening:
docker create --build-arg TOKEN <my priv token> <dockerFile>
maybe declare the arg in the docker file?
ARG TOKEN
then in the script have npm install use that TOKEN in dependencies
"privModule": "git+https://${TOKEN}:x-oauth-basic#github.com/<githubID>/<privateModule>.git"
and if that doesn't work, somehow replace that var in the package.json (with sed) or have npm use an environment var.