When pushing to gitlab.com the runner quits with the following error message:
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://git@gitlab.com/group/subgroup/project.git
npm ERR! Warning: Permanently added the ECDSA host key for IP address '172.65.251.78' to the list of known hosts.
npm ERR! Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR! Please make sure you have the correct access rights
Tried for hours now, sucking up all available information on the web without success.
I’ve also tried various alternative authentication methods which all lead to the same error.
npm ERR! /usr/bin/git ls-remote -h -t ssh://git@gitlab.com/group/subgroup/project.git
npm ERR! Warning: Permanently added the ECDSA host key for IP address '172.65.251.78' to the list of known hosts.
npm ERR! Permission denied (publickey).
Would that error go away when using https insteaf of SSH?
Could it be that using HTTPS doesn’t work for me because I have 2FA enabled? Read that I need to use personal access tokens for that, but I’m not sure how to actually use the access token without modifying the repository URL in the packages.json file.
So, I finally understood all the moving parts and how to tuck them together.
What I missed were two things:
Authentication via .netrc is for HTTPS not for SSH
I wasn’t aware that using the .netrc file for authentication (within the Gitlab CI runner) was only for authenticating via HTTPS - I thought it would also work with git+ssh URLs.
2FA forces the use of a personal access token for HTTPS urls
I learned that when 2FA is enabled, a personal access token needs to be used for HTTPS authentication; the username is “oauth2” and the password is the actual personal access token.
I updated the Git URLs in the package.json file to use git+https and now I can use my PAT locally to run npm install and in CI the .netrc file in combination with the CI_JOB_TOKEN is used.
great that you figured it out by yourself! Thanks for sharing with everyone too. If you happen to have a blog or dev.to account, maybe share your adventure over there as well?