Skip to content

Refactor ssh known hosts - #310

Merged
SergK merged 1 commit into
masterfrom
refactor-ssh-known-hosts
Aug 4, 2026
Merged

Refactor ssh known hosts#310
SergK merged 1 commit into
masterfrom
refactor-ssh-known-hosts

Conversation

@SergK

@SergK SergK commented Aug 4, 2026

Copy link
Copy Markdown
Member

EPMDEDP-17256: fix: Verify SSH host keys for all git, GitServer and Gerrit connections

Every outbound SSH connection accepted any host key: the git provider used InsecureIgnoreHostKey for all
repository traffic including the packless transport, the GitServer connectivity check did the same for every
provider, and the Gerrit client used a callback that unconditionally returned nil. A network-position attacker
could impersonate a git server to intercept pushed source or serve falsified refs.

Host keys are now verified against a known_hosts file shipped by the chart as a ConfigMap and mounted as a
directory rather than with subPath, so the kubelet refreshes it in place and added entries take effect without
restarting the operator. The file is seeded with keys for github.com, gitlab.com and bitbucket.org.

In the go-git paths the host key callback is left unset rather than replaced: go-git then derives
HostKeyAlgorithms from known_hosts as well, which avoids spurious key-mismatch failures when a server offers a
key type that is absent from the file.

Failures name the host, the port and the remediation command through GitServer .status.error. A key mismatch is
reported distinctly from an unknown host and never suggests re-scanning, since that would trust whatever key was
just presented.

BREAKING CHANGE: GitServers authenticating over SSH to a host outside the seeded providers must have their host
keys added to knownHosts.entries before upgrading. GitServers using token authentication are unaffected.

Note: git operations for the github, gitlab and bitbucket providers connect on port 22 regardless of
spec.sshPort, so a server on another port needs both entry forms pinned.

@SergK
SergK requested a review from a team as a code owner August 4, 2026 12:41
@epmd-edp

epmd-edp commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Pipeline review-codebase-operator-master-qkvnr ✅ Passed

Status Task Duration
github-set-pending-status 6s
fetch-repository 10s
init-values 4s
get-cache 2m6s
commit-validate 5s
dockerfile-lint 7s
helm-lint 5s
helm-docs 10s
build 1m5s
sonar 1m8s
save-cache 1m8s
buildkit-build 29s
github-report-pipeline-status 8s

…errit connections

Every outbound SSH connection accepted any host key: the git provider used InsecureIgnoreHostKey for all
repository traffic including the packless transport, the GitServer connectivity check did the same for every
provider, and the Gerrit client used a callback that unconditionally returned nil. A network-position attacker
could impersonate a git server to intercept pushed source or serve falsified refs.

Host keys are now verified against a known_hosts file shipped by the chart as a ConfigMap and mounted as a
directory rather than with subPath, so the kubelet refreshes it in place and added entries take effect without
restarting the operator. The file is seeded with keys for github.com, gitlab.com and bitbucket.org.

In the go-git paths the host key callback is left unset rather than replaced: go-git then derives
HostKeyAlgorithms from known_hosts as well, which avoids spurious key-mismatch failures when a server offers a
key type that is absent from the file.

Failures name the host, the port and the remediation command through GitServer .status.error. A key mismatch is
reported distinctly from an unknown host and never suggests re-scanning, since that would trust whatever key was
just presented.

BREAKING CHANGE: GitServers authenticating over SSH to a host outside the seeded providers must have their host
keys added to knownHosts.entries before upgrading. GitServers using token authentication are unaffected.

Note: git operations for the github, gitlab and bitbucket providers connect on port 22 regardless of
spec.sshPort, so a server on another port needs both entry forms pinned.

Design decisions, recorded here rather than as comments describing what the code does not do:

- No switch disables verification. An operator-wide opt-out would be turned on once and never turned off.
- The go-git paths leave AuthMethod.HostKeyCallback unset instead of supplying one, so go-git also derives
  HostKeyAlgorithms from known_hosts; supplying a callback suppresses that and turns a missing entry into a
  reported key mismatch.
- The chart mounts the ConfigMap as a directory rather than with subPath, because the kubelet only refreshes
  in-place directory mounts, so a host key can be added without restarting the operator.
- The Dockerfile's SSH_KNOWN_HOSTS moves onto the chart's path so the image default and the chart agree on one
  file instead of two.

Signed-off-by: Sergiy Kulanov <[email protected]>
@SergK
SergK force-pushed the refactor-ssh-known-hosts branch from 7ff524a to 7a0f20f Compare August 4, 2026 13:00
@SergK
SergK merged commit 0153b74 into master Aug 4, 2026
6 checks passed
@SergK
SergK deleted the refactor-ssh-known-hosts branch August 4, 2026 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants