source-controller: [GitHub] Handshake failed: knownhosts: key mismatch
Started getting these errors out of the blue on all clusters.
{"level":"error","ts":"2021-11-16T18:21:07.474Z","logger":"controller.gitrepository","msg":"Reconciler error","reconciler group":"source.toolkit.fluxcd.io","reconciler kind":"GitRepository","name":"flux-system","namespace":"flux-system","error":"unable to clone 'ssh://git@github.com/user/repository', error: ssh: handshake failed: knownhosts: key mismatch"}
Doing find -name known_hosts in the pod produces nothing.
Restarting the pod = same error immediately.
What’s going on, where’s the known_hosts file?
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 25
- Comments: 42 (14 by maintainers)
Links to this issue
Commits related to this issue
- (docs) Update GitHub's SSH public key Update the documentation and example to use the new SSH public key that GitHub deployed after Nov 16th 2021. See also fluxcd/source-controller#490 Signed-off-b... — committed to aledegano/terraform-provider-flux by aledegano 3 years ago
- (docs) Update GitHub's SSH public key and algo for private key Update the documentation and example to use the new SSH public key that GitHub deployed after Nov 16th 2021. See also fluxcd/source-con... — committed to aledegano/terraform-provider-flux by aledegano 3 years ago
GitHub has changed its SSH host keys from DSA to ECDSA! https://github.blog/2021-09-01-improving-git-protocol-security-github/
To fix the key mismatch error, you have two options:
Update the
known_hostsin theflux-systemsecret with theecdsa-sha2-nistp25value:Or rotate the SSH keys with
flux boostraplike so:kubectl -n flux-system delete secret flux-systemflux bootstrap githubwith the same arguments as beforeecdsa-sha2SSH key and Host keyAccording to: https://github.blog/2021-09-01-improving-git-protocol-security-github/
Today is the day that host keys get rotated at GitHub. There are two new host keys in the blog post, one for ECDSA and another for Ed25519.
If you’d like a short program to do it:
Ok so rotating the SSH key fixes it.
Before:
After:
I’m getting the same error on my cluster:
Looks like an issue with GitHub host keys.
I was finding that it sits in what appears to be due to a backed-off timer, such that it won’t try again for a while after several consecutive failures, but restarting it caused it to try again immediately.
@ninja9k1 - I assume by now that you’ve resolved this issue for your local
gitopsinstallation, but I’ll add a response to this Issue in case anyone else finds it and needs the same solution.The
gitopsCLI uses your local user’s~/.ssh/known_hostsfile as the source for this key, and this error generally means that you need to remove the old RSA host key and add the new ECDSA host key in that file.This command should remove the existing key:
You can then either use this command to insert the new key without actually trying to SSH to GitHub:
Or start an SSH connection to
github.comand let GitHub disconnect you after the connection succeeds:Variant on the above script: https://gist.github.com/ellieayla/76352313c4f5939db6d2268fb70b0d48
Then either wait or request each GitRepository to reconcile.
Worked for me as well, thanks! 👯
worked for us
@kaaboaye your user token doesn’t have permission to create deploy keys, you need to be a repo admin.
Thanks for the suggestion, in my case i also had to:
flux delete source git flux-systemThe known_hosts file is in the same secret as the SSH key, please see the docs here https://fluxcd.io/docs/components/source/gitrepositories/#ssh-authentication