Skip to content

[backport camel-4.18.x] CAMEL-25644: camel-ssh - match known_hosts entries by exact host pattern - #28218

Merged
oscerd merged 1 commit into
apache:camel-4.18.xfrom
oscerd:backport/CAMEL-25644-to-camel-4.18.x
Oct 21, 2026
Merged

oscerd merged 1 commit into
apache:camel-4.18.xfrom
oscerd:backport/CAMEL-25644-to-camel-4.18.x

Conversation

@oscerd

@oscerd oscerd commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Backport of #27821 onto camel-4.18.x.

Original PR: #27821 - CAMEL-25644: camel-ssh - match known_hosts entries by exact host pattern
Target branch: camel-4.18.x

CAMEL-25644

What it does

As on main, when knownHostsResource is set, ResourceBasedSSHKeyVerifier matches the entries of the known_hosts resource as OpenSSH does:

  • Each host pattern is compared, ignoring case, with the host the client connects to: the host configured on the endpoint, or the HostName that ~/.ssh/config gives for it, never resolved through DNS. It is written host for port 22 and [host]:port for another port. The producer and the consumer resolve the host configuration once per connection and hand it to the verifier.
  • * and ? are wildcards, ! excludes the hosts a pattern matches, and hashed |1| entries are supported.
  • Every entry for the host is considered, and the keys are compared with Apache MINA SSHD.
  • A key in a matching @revoked entry is rejected, and so is a key that none of the entries of a listed host has, whatever the value of failOnUnknownHost. @cert-authority entries are ignored.
  • A resource or a line that cannot be read makes every connection fail.
  • ssh-component.adoc has the new "Server host key verification" section.

Adaptations for camel-4.18.x

The verifier, SshHelper, the component doc and the tests are the same as in #27821. SshConfiguration differs on this branch, so this needs a review:

  • knownHostsResource and failOnUnknownHost have a bare @UriParam on this branch (no label, security or description), so their descriptions come from the setter javadoc. The knownHostsResource setter javadoc now carries the description that main has in the annotation. The failOnUnknownHost setter javadoc is updated as on main.
  • The generated files are regenerated for this branch: the component JSON, the catalog JSON, and the component and endpoint DSL builders. There is no catalog doc mirror on this branch.
  • The upgrade guide note for this branch is already on main, in the "Upgrading from 4.18.5 to 4.18.6" section of the 4.18 guide.

Tests

  • camel-ssh: 68 tests, 0 failures, none skipped. This branch has fewer camel-ssh tests than main, and every known_hosts test of CAMEL-25644: camel-ssh - match known_hosts entries by exact host pattern #27821 ran: 22 verifier tests, 12 SshComponentKnownHostTest, 8 SshComponentKnownHostIPv6Test and 1 SshComponentKnownHostEdDSATest.
  • A full reactor build of the branch: mvn clean install -DskipTests -DskipITs, BUILD SUCCESS, 657 modules. It regenerated only the three generated files above.

Claude Code on behalf of Andrea Cosentino

🤖 Generated with Claude Code

Backport of apache#27821 onto camel-4.18.x.

When knownHostsResource is set, ResourceBasedSSHKeyVerifier parsed
known_hosts with its own parser. It matched the host field with
String.contains and used only the first matching line, did not tell
[host]:port entries from plain ones, skipped comments, markers and CRLF
lines, had no wildcard, negated or hashed patterns, and looked up an
endpoint configured by address under its reverse-lookup name.

The verifier now matches entries as OpenSSH does. Each pattern is
compared, ignoring case, with the host the client connects to (or the
HostName of the host configuration, resolved once per connection),
written [host]:port for a port other than 22. Wildcard, negated and
hashed |1| patterns are supported. Every entry for the host is
considered, and keys are compared with Apache MINA SSHD. A key in a
matching @Revoked entry, or a key not listed for a host that has
entries, is rejected whatever failOnUnknownHost says, and a resource or
line that cannot be read fails every connection.

On this branch the options knownHostsResource and failOnUnknownHost
take their description from the setter javadoc, so the new wording is
there. The upgrade guide note for this branch is on main, in the 4.18.6
section of the 4.18 guide.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Andrea Cosentino <ancosen@gmail.com>
@oscerd oscerd added this to the 4.18.6 milestone Oct 21, 2026
@oscerd oscerd added bug Something isn't working backport indicate that a Pull request is a backport from a fix from the main branch labels Oct 21, 2026

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backport versioning oversight: @since tag must reflect the first version on this branch, not the main branch.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@oscerd
oscerd merged commit 3686f39 into apache:camel-4.18.x Oct 21, 2026
3 checks passed
@oscerd oscerd self-assigned this Oct 21, 2026
@oscerd
oscerd deleted the backport/CAMEL-25644-to-camel-4.18.x branch October 21, 2026 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport indicate that a Pull request is a backport from a fix from the main branch bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants