nvm: Unable to clone repo with a deploy key

We’re unable to clone this repo when using the deploy key that’s set up in our CircleCI. The key is correctly set up in github as a deploy key and we’ve been using it since 2021 with no issues (yes, we should probably rotate it). Here’s the error message that git returns when trying to clone from within the CircleCI container:

root@408047b2bc79:~# git clone git@github.com:nvm-sh/nvm.git
Cloning into 'nvm'...
ERROR: Permission to nvm-sh/nvm.git denied to deploy key
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Using that same key to clone another public repo (ex: node) works fine so I’m assuming the issue is with this repo’s settings rather than a global change.

Can you please look into any recent changes to this repo’s settings?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 37
  • Comments: 19 (1 by maintainers)

Most upvoted comments

Confirmed, the issue seems resolved. I checked the .gitconfig files between the failed and successful builds (had SSH sessions open to both containers) and there are no differences. So far it’s looking like this was a github issue rather than CircleCI or the settings of a specific repo but that’s just guessing from limited info.

I’ll keep the issue open for another hour or so just while we confirm the fix is stable and close it out after. Thanks for the group debugging and workarounds everyone!

I’ve opened a support ticket with CircleCI and I suggest everyone that can do the same so they get eyes on this.

An ugly (TEMPORARY!) workaround for people that need this working now: use a user key in CircleCI instead of deploy.

We saw only our repos using deploy keys failing like this, and the few that make use of user keys for various reasons were not failing.

Be sure to make note of any projects you switch to user keys so you can go back and revert them to deploy keys!

RESOLVED! It is working Again!!!

Seems to be working now

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 15916  100 15916    0     0   295k      0 --:--:-- --:--:-- --:--:--  298k
=> Downloading nvm from git to '/home/circleci/.nvm'
=> Cloning into '/home/circleci/.nvm'...
remote: Enumerating objects: 378, done.        
remote: Counting objects: 100% (378/378), done.        
remote: Compressing objects: 100% (326/326), done.        
remote: Total 378 (delta 43), reused 163 (delta 25), pack-reused 0 (from 0)        
Receiving objects: 100% (378/378), 375.87 KiB | 34.17 MiB/s, done.
Resolving deltas: 100% (43/43), done.
* (HEAD detached at FETCH_HEAD)
  master

Running this command in a step before installing Node fixes the issue:

git config --global --remove-section url."ssh://git@github.com"

Not completely sure about the repercussions though—nor why this config would be needed in the first place.

I too am here because my CircleCI builds are failing, but I can reproduce the issue locally by generating a new SSH key, adding it as a deploy key to a repo, and adding it to my SSH agent with no other keys, so it doesn’t seem to be an issue with CircleCI specifically. I was also able to clone other public repos with the same key and configuration.

Edit: I do think it’s CircleCI specifically - they must have forced cloning over ssh rather than https with some git config.

cross-posting here just to amplify:

I think this is just an issue across the board with public github repos, we are also seeing:

Cloning into 'bats-core'...
ERROR: Permission to bats-core/bats-core.git denied to deploy key
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

my guess is that either circleci made a change to inject the insteadOf directive into the gitconfig:

~$ cat ~/.gitconfig
[safe]
	directory = *
[url "ssh://git@github.com"]
	insteadOf = https://github.com
[gc]
	auto = 0

or github changed the ability for deploy keys to clone public repos.

This seems to happen because CircleCI sets git to change all GitHub HTTPS URLs to SSH URLs.

$ git config --list
# ...
url.ssh://git@github.com.insteadof=https://github.com

Is it possible that a deploy key was recently added to this repo?