setup-node: Installing npm dependency from public GitHub repository fails
In one of my projects I use simple-caldav which contains the following line in its package.json:
dependencies: {
"ical.js": "github:TimDaub/ical.js#feat/detect-module-mode-build",
...
}
It points to a branch here. I’ve submitted a PR to the upstream repo, but it seems they’re not having much time for maintenance.
Anyways, my GH action in the project that has simple-caldav as a dependency looks like this
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm test
However, when it runs npm ci
, it fails like this
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://git@github.com/TimDaub/ical.js.git
npm ERR!
npm ERR! Warning: Permanently added the RSA host key for IP address '140.82.113.4' to the list of known hosts.
npm ERR! git@github.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
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 61
- Comments: 28
Links to this issue
Commits related to this issue
- Update js-releases dep to fix build on GitHub Actions Ref: https://github.com/actions/setup-node/issues/214 — committed to hashicorp/vscode-terraform by aeschright 3 years ago
- Update js-releases dep to fix build on GitHub Actions (#554) Ref: https://github.com/actions/setup-node/issues/214 — committed to hashicorp/vscode-terraform by aeschright 3 years ago
- fix: ci/id github actions error https://github.com/actions/setup-node/issues/214 — committed to dapplets/dapplet-extension by alsakhaev 3 years ago
- fix workflow https://github.com/actions/setup-node/issues/214 — committed to bonartm/quizdown-js by deleted user 3 years ago
- Checkout with https: not ssh: ssh: URLs break npm ci. See https://github.com/actions/setup-node/issues/214#issuecomment-810829250 — committed to zooniverse/pfe-lab by eatyourgreens 3 years ago
- [Security] Upgrade all the things (#252) * Build with npm ci * Publish /commit_id.txt on deploy * npm audit fix * Upgrade mocha to 8.4 * Cache builds Re-use the npm cache across builds. ... — committed to zooniverse/pfe-lab by eatyourgreens 3 years ago
- Workaround for GH Actions failing with "Permission denied (publickey). Could not read from remote repository." See https://github.com/actions/setup-node/issues/214, https://github.com/npm/cli/issues/... — committed to affinidi/affinidi-core-sdk by inga-affinidi 3 years ago
- BF: workaround access denied, see description of this commit https://github.com/actions/setup-node/issues/214 — committed to tpronk/psychojs by deleted user 3 years ago
- Fix npm dependencies for correct production build (#87) * Fix npm dependencies for correct production build - Updated placement of the npm dependencies in package.json according to Dev or producti... — committed to affinidi/affinidi-core-sdk by sheremet 3 years ago
- GitHub workflows: Use HTTPS to install dependencies from GitHub Fixes an error when install dependencies from GitHub (rather than npm) directly in a GitHub workflow/pipeline. See: https://github.co... — committed to sdsna/nextjs-starter by deleted user 3 years ago
- Fix build? https://github.com/actions/setup-node/issues/214 — committed to jsmnbom/ao3-enhancements by jsmnbom 3 years ago
- build(front): fix npm install from GH repo bug Ref: https://github.com/actions/setup-node/issues/214#issuecomment-742596196 — committed to agrc/roadkill-mobile by stdavis 3 years ago
- build(front): fix npm install from GH repo bug Ref: https://github.com/actions/setup-node/issues/214#issuecomment-742596196 — committed to agrc/roadkill-mobile by stdavis 3 years ago
- Use workaround from https://github.com/actions/setup-node/issues/214 See also https://github.com/npm/cli/issues/2610 — committed to davedoesdev/b by davedoesdev 3 years ago
- Workaround from https://github.com/actions/setup-node/issues/214 — committed to davedoesdev/shared-memory-disruptor by davedoesdev 3 years ago
- Force upstream CI to checkout git deps using https When using ssh even public repositories require authentication with npm ci. Solution from: https://github.com/actions/setup-node/issues/214#issueco... — committed to ChoicescriptIDE/monaco-editor by CareyJWilliams 3 years ago
- use npm@8 for CI there are may installation issues using `npm ci` for older NPM versions, like workspace circular references or inability to install github branches(https://github.com/actions/setup-n... — committed to ro0gr/ember-cli-page-object by ro0gr 2 years ago
- use npm@8 for CI there are may installation issues using `npm ci` for older NPM versions, like workspace circular references or inability to install github branches(https://github.com/actions/setup-n... — committed to ro0gr/ember-cli-page-object by ro0gr 2 years ago
- use npm@8 for CI there are may installation issues using `npm ci` for older NPM versions, like workspace circular references or inability to install github branches(https://github.com/actions/setup-n... — committed to ro0gr/ember-cli-page-object by ro0gr 2 years ago
- use npm@8 for CI there are may installation issues using `npm ci` for older NPM versions, like workspace circular references or inability to install github branches(https://github.com/actions/setup-n... — committed to ro0gr/ember-cli-page-object by ro0gr 2 years ago
I fixed this in my workflows by adding an extra step after the
actions/checkout@v2
(withpersist-credentials: false
) step:Changing from SSH to HTTP makes everything work across all workflows using
npm ci
(which has several benefits overnpm install
). If you need to authenticate, use a PAT instead of SSH:What ended up fixing it for me is adding the unknown host in my ssh config beforenpm ci
:It’s far from perfect, but works well as a work around for now. Additionally, disabling ssh’s key checking via config may be an option too. I prefer to go with this more narrow solution.Edit: Turns out this won’t work all the time as the IPs that the package is requested from change
I’ve tested adding ranges and
ssh-keyscan
, but so far I wasn’t successful.Edit2:
I think I finally ended up solving it for good. This is what you’ll have to do:
~/.ssh
ssh-keygen -t rsa -C "your_email@example.com"
. Ideally don’t overwrite your existing keypair at~/.ssh
by entering a custom path.*.pub
key and add it to your SSH keys in your GitHub account settingsSSH_PRIVATE_KEY
the contents of the private key file that was generated-run: npm ci
For more details, check https://github.com/webfactory/ssh-agent
This is still an issue… An alternative solution is replacing the resolved url in the package lock file, for example:
git+ssh://git@github.com/zspecza/common-tags.git#946fcbf8cfc1a14c2183ef5a81b23727a2b531e3
becomes:git+https://git@github.com/zspecza/common-tags.git#946fcbf8cfc1a14c2183ef5a81b23727a2b531e3
Switching from node 14.x to 16.x solved the problem for me (using “npm ci”)
Workaround:
This will replace all appearances of
ssh:
forhttps:
in package-lock.json. You can run this beforenpm install
in the Github ActionsThis is probably caused by npm/cli#2610.
Currently working in dev & prod. Based on @TimDaub original post:
^ This still works and works well and is the only fix that I feel comfortable with. HTTPS over Github is out of the question imo. So to anyone just stumbling onto this – I highly recommend you follow his steps.
We use a simple azure PaaS to run a react app, but our component library is not yet published or ready to be published, but does have some awesome functionality for a few components. Ergo, we needed that, along with the deps, then build and deploy. All I had to do was gen the key, add it and configure as mentioned (you can obviously name the secret whatever you want). Here is an edited example:
FWIW, using npm@8 has finally fixed this my issue.
Why is this issue closed? I am still having this same issue and the workarounds are just that… workarounds.
Thought the same and even tried that locally and works fine locally
Thanks for sharing! 👏🏼
I adapted this solution to a simple action if someone needs something like this in the future in another context.
For me this issue started occurring when I tried to switch from
npm install
tonpm ci
so for some of you switching tonpm install
may be another workaround.Having the same issue, but within my workflows’ docker build step. There has to be easier ways to disseminate SSH agent keys/known hosts info to different contexts when SSH-git actions are so commonplace
Unfortunately, it’s not an option I have.
I haven’t had any luck getting the workarounds to succeed for this.
There are several very worrying aspects of this bug.
fwiw: my team swapped to use Yarn for performance improvements in the CI/CD and now the HTTP protocol workaround isn’t needed. Just saying 🤷♂️
@wallind There is no difference in terms of transport security. HTTPS and SSH rely on similar underlying crypto. Persisting your credentials by adding your secret PAT to the global git config (the last bit of my comment) does have security implications, but it’s the default behavior of the Checkout action already (
persist-credentials: true
) so no security is “lost” per se. If you don’t want the PAT hanging around, run some form of post-job cleanup.this did fix my problem so thank you for that. Out of curiosity though is there any security lost by doing this? I don’t care enough to not use this fix for the project I need it on but I am left wondering.
An update on my earlier workaround in this thread. A problem that I’ve discovered is that according to GitHub settings:
Hence, it becomes useless when trying to collaborate with others.
Nope, I’m quite confused by this problem. E.g. why does it say
git ls-remote
? Is npm using git internally? I could imagine another notation within package.dependencies could make a difference. But I haven’t tested that yet.