flux2: [GitLab] ssh: handshake failed: knownhosts: key mismatch
Describe the bug
After upgrading from 2.5.1 to 2.6.x, we are no longer able to bootstrap a new cluster when using ssh auth.
The source controller is erroring out with the following message:
failed to checkout and determine revision: unable to list remote for 'ssh://git@REPOSITORY_URL': ssh: handshake failed: knownhosts: key mismatch
Rolling back to 2.5.1 solves the issue.
Steps to reproduce
We are using terraform, helm and flux-operator to bootstrap the cluster. Terraform code is below:
# operator deployment
#
# Create the flux-system namespace.
resource "kubernetes_namespace" "flux_system" {
metadata {
name = "flux-system"
}
lifecycle {
ignore_changes = [metadata]
}
}
# Create a Kubernetes secret with the Git credentials
resource "kubernetes_secret" "git_auth" {
depends_on = [kubernetes_namespace.flux_system]
metadata {
name = "flux-system-operator"
namespace = "flux-system"
}
data = {
username = "git"
identity = var.flux_deployment_ssh_key.private
known_hosts = var.flux_deployment_ssh_key.known_hosts
}
type = "Opaque"
}
# Install the Flux Operator.
resource "helm_release" "flux_operator" {
depends_on = [kubernetes_namespace.flux_system]
name = "flux-operator"
namespace = "flux-system"
repository = "oci://ghcr.io/controlplaneio-fluxcd/charts"
chart = "flux-operator"
wait = true
}
# Configure the Flux instance.
resource "helm_release" "flux_instance" {
depends_on = [helm_release.flux_operator]
name = "flux"
namespace = "flux-system"
repository = "oci://ghcr.io/controlplaneio-fluxcd/charts"
chart = "flux-instance"
# Configure the Flux components and kustomize patches.
values = [
file("${path.module}/resources/components.yaml")
]
# Configure the Flux distribution.
set {
name = "instance.distribution.version"
value = var.flux_version
}
set {
name = "instance.distribution.registry"
value = var.flux_registry
}
# Configure Flux Git sync.
set {
name = "instance.sync.kind"
value = "GitRepository"
}
set {
name = "instance.sync.url"
value = var.flux_repository_url
}
set {
name = "instance.sync.path"
value = "clusters/${var.cluster_name}"
}
set {
name = "instance.sync.ref"
value = var.git_ref
}
set {
name = "instance.sync.pullSecret"
value = "flux-system-operator"
}
}
Expected behavior
The source controller can clone the repository, and the bootstrap works.
Screenshots and recordings
No response
OS / Distro
Talos Linux v1.10.1, Kubernetes v1.33
Flux version
n/a
Flux check
checking prerequisites ✔ Kubernetes 1.33.0 >=1.31.0-0 ► checking version in cluster ✔ distribution: flux-v2.6.1 ✔ bootstrapped: false ► checking controllers ✔ helm-controller: deployment ready ► ghcr.io/fluxcd/helm-controller:v1.3.0@sha256:db55d9d9f9b5106acd8c21da6916b8e285fcfc5572f214361ececd1a8571a4f0 ✔ image-automation-controller: deployment ready ► ghcr.io/fluxcd/image-automation-controller:v0.41.0@sha256:868010070f063758282bf0c64cf17c6150b51d6eee49d40647706ccbd93c109d ✔ image-reflector-controller: deployment ready ► ghcr.io/fluxcd/image-reflector-controller:v0.35.1@sha256:65e68ed78cac29a9f42b83098ec8fa1e40a6ef554f89303da1520cff68ec5a05 ✔ kustomize-controller: deployment ready ► ghcr.io/fluxcd/kustomize-controller:v1.6.0@sha256:d8c5445003196791441354f2d549e96cc6e69bb9ef6c5a7e440918dab0503776 ✔ notification-controller: deployment ready ► ghcr.io/fluxcd/notification-controller:v1.6.0@sha256:80174ff676407af7a6feff67b0c2f100de9f7f89df4c26fc871e4d4c4006544d ✔ source-controller: deployment ready ► ghcr.io/fluxcd/source-controller:v1.6.0@sha256:44ea51a40e4da2c0f19427df3219f29b86c8fce38539d227f6ffc2bdc944036f ► checking crds ✔ alerts.notification.toolkit.fluxcd.io/v1beta3 ✔ buckets.source.toolkit.fluxcd.io/v1 ✔ gitrepositories.source.toolkit.fluxcd.io/v1 ✔ helmcharts.source.toolkit.fluxcd.io/v1 ✔ helmreleases.helm.toolkit.fluxcd.io/v2 ✔ helmrepositories.source.toolkit.fluxcd.io/v1 ✔ imagepolicies.image.toolkit.fluxcd.io/v1beta2 ✔ imagerepositories.image.toolkit.fluxcd.io/v1beta2 ✔ imageupdateautomations.image.toolkit.fluxcd.io/v1beta2 ✔ kustomizations.kustomize.toolkit.fluxcd.io/v1 ✔ ocirepositories.source.toolkit.fluxcd.io/v1 ✔ providers.notification.toolkit.fluxcd.io/v1beta3 ✔ receivers.notification.toolkit.fluxcd.io/v1 ✔ all checks passed
Git provider
GitLab
Container Registry provider
ghcr.io
Additional context
No response
Code of Conduct
- I agree to follow this project’s Code of Conduct
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 4
- Comments: 21 (11 by maintainers)
This image version works with a single
ssh-ed25519host key.Flux check output confirming the image tag:
I think we have a fix, please update source-controller image to the RC below and let us know if it works:
ghcr.io/fluxcd/source-controller:rc-23333a82This image was build from https://github.com/fluxcd/source-controller/pull/1828
@stefanprodan I can confirm this works.
If you have multiple keys on the same line then that’s an invalid
known_hosts, too bad Go crypto does not error out and just picks the first one.Thanks for the thorough investigation, yes, it does.
I also had the problem that the error
ssh: handshake failed: knownhosts: key mismatchoccurred after the updating to 2.6.xafter replacing the host keys with the output of :
it works with v2.6.x.
Previously all my hostkey entries were
ssh-ed25519, now the entries for one cluster isecdsa-sha2-nistp256and the other isssh-rsa.I am struggling with two clusters at the moment. On one I had this error and could apply the workaround. This one was already updated to 2.6.1.
The other one is still on 2.5.1 but currently failing to verify my commits (unrelated). Once that is solved I will upgrade that one, too, and will report back, if I encounter the same issue.
The only change we made to SSH was to updated the
golang.org/x/crypto/sshpackage to fix CVE-2025-22870. I suggest regenerating the host keys.Also are these Git servers self-hosted IPv6?