argo-cd: SSH connections to github.com stopped working with host key mismatch
Describe the bug
On Nov. 16th, GitHub.com has made changes to their SSH endpoint that prevents Argo CD to connect to github.com repositories when using the SSH protocol. More details can be found here: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/githubs-ssh-key-fingerprints
The error message observed is:
rpc error: code = Unknown desc = ssh: handshake failed: knownhosts: key mismatch
Determining the root cause is still under progress, but we believe it’s a combination of GitHub.com changing the host key algorithm preference to ECDSA or Ed25519 and Argo CD not shipping the appropriate keys, which leads to our SSH implementation refusing to continue. Argo CD does not, nor did, use DSA as the protocol for validating SSH host keys.
Workaround
As a workaround, you need to import the new ECDSA and Ed25519 keys into Argo CD’s SSH known hosts configuration.
First, get the new host keys using ssh-keyscan
, which is part of OpenSSH’s client package:
$ ssh-keyscan github.com
# github.com:22 SSH-2.0-babeld-a73e1397
github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
# github.com:22 SSH-2.0-babeld-a73e1397
github.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg=
# github.com:22 SSH-2.0-babeld-a73e1397
github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl
Then, run argocd cert add-ssh --batch
and paste the keys to the terminal when asked to do so. Alternatively, you can use the UI or declarative setup for adding the new keys. Please refer to the documentation for more details.
Important Make sure to verify the fingerprints of the keys to match the fingerprints on https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/githubs-ssh-key-fingerprints - Argo CD helps you to view the fingerprints using the argocd cert list
command.
A fix for adding the new keys to Argo CD is being worked on here: #7722
Update Nov 18 2022
Argo CD v2.1.7 has been released with updated manifests containing the new host keys in the argocd-known-hosts-cm
ConfigMap. Please note that it is not sufficient to update your image tags to the new version, since the host keys are stored in a ConfigMap and are not part of the container image. You need to apply v2.1.7 manifests when upgrading.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 87
- Comments: 20 (4 by maintainers)
I had to fix this earlier today, so wanted to share.
Remediation Steps
1. Create a file named
argocd-ssh-known-hosts-cm.yaml
with the following contents:2. Apply the
argocd-ssh-known-hosts-cm.yaml
file:3. Restart the
argocd-repo-server
pods:Afterwards, things in the ArgoCD UI should update, and any “unknown” applications should sort themselves out. Cheers!
Its Open Source, feel free to contribute. Kudos to the ArgoCD team for all great work and for a fix.
Thanks for this fix.
~~I don’t know who is in charge of argo-helm ; but this fix is to propagate here too https://github.com/argoproj/argo-helm/blob/master/charts/argo-cd/values.yaml#L1485~~
Edit: Fix is propagated : https://github.com/argoproj/argo-helm/commit/27aa2a9ad02cd29de35f8130bea592f2723d745a
Here’s the Kustomize code.
The overlay file:
The kustomize.yaml to use the overlay (change filename/path and namespace as needed):
@jannfis thanks for pining this and getting the information out so quickly. I also appreciate that Argo has done 99% of the administration work that we as users are ultimately responsible for here in maintaining our own installations, and that there is an easy workaround.
Rather than “adding the new keys” to argoCD how about implementing an actual ssh handshake process and flow?
@eytanhanig another great way is to use a
configMapGenerator
.Create a file named
ssh_known_hosts
with the following contents:Then, reference it from a (existing)
kustomization.yaml
file:Already logged here: https://github.com/argoproj/argo-helm/issues/1019 And fixed here: https://github.com/argoproj/argo-helm/issues/1018 😄
Distressing that argoCD hardcoded in a DSA verification key like that.
first of all thx for flagging this!
… but kind of lost on this one:
argocd repocreds add git@github.com:xx/ --ssh-private-key-path ~/.ssh/argocd
works with an ssh-ed25519 key.argocd repo add git@github.com:xx/xx-config --ssh-private-key-path ~/.ssh/argocd
fails with the handshake errorEDIT: needed to add
github.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg=
as well