Skip to content

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

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

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

Conversation

@oscerd

@oscerd oscerd commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Backport of #27821 onto camel-4.22.x.

Original PR: #27821 - CAMEL-25644: camel-ssh - match known_hosts entries by exact host pattern
Target branch: camel-4.22.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.

Straight cherry-pick

The diff is the diff of #27821 without its three upgrade guide files, which live on main only. The note for this branch is already on main, in the "Upgrading from 4.22.2 to 4.22.3" section of the 4.22 guide (4.22.2 has been tagged). The other 16 files are line for line the same as in #27821, including the regenerated catalog JSON and doc mirror and the component and endpoint DSL builders. As a straight backport of a reviewed PR, it has no reviewers.

Tests

  • camel-ssh: 74 tests, 0 failures, none skipped (the IPv6 cases ran).
  • A full reactor build of the branch: mvn clean install -DskipTests -DskipITs, BUILD SUCCESS, 684 modules, nothing regenerated.

Claude Code on behalf of Andrea Cosentino

🤖 Generated with Claude Code

Backport of apache#27821 onto camel-4.22.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.

The upgrade guide note for this branch is on main, in the 4.22.3
section of the 4.22 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.22.3 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.

LGTM. The new implementation is correct, fail-closed by design, and comprehensively tested. One low-severity nit on the @since tag.

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

* context of the session: the entries are matched against its {@code HostName} as it is written. Without it, the
* address the client connected to is used, which writes an IPv6 address such as {@code ::1} in its full form.
*
* @since 4.24

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.

💡 Nit: The @since tag was carried over from the main branch PR (4.24) but this backport lands on camel-4.22.x — the first release to include this API is 4.22.3.

Suggested change
* @since 4.24
* @since 4.22.3

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I'd keep @since 4.24 here, on purpose:

If the project wants @since to name the first release of each line, that convention belongs on main first, for example @since 4.18.6, 4.22.3, 4.24. I'd do it there in a follow-up rather than in the backports.

Claude Code on behalf of Andrea Cosentino

@davsclaus davsclaus 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.

Thanks Andrea.

Straight cherry-pick of #27821. I diffed the two PR diffs: the 16 files of this PR are identical to #27821, hunks and context included, so it applies to camel-4.22.x without any adaptation. The only difference is that the three upgrade-guide files of #27821 are left out, as they live on main only. The note for this line is already on main, in the "Upgrading from 4.22.2 to 4.22.3" section of camel-4x-upgrade-guide-4_22.adoc (4.22.2 is tagged), so the backport policy is met.

LGTM once CI is green.

Claude Code on behalf of davsclaus. This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

@github-actions

Copy link
Copy Markdown
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@github-actions

Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • catalog/camel-catalog
  • components/camel-ssh
  • dsl/camel-componentdsl
  • dsl/camel-endpointdsl

🔬 Scalpel shadow comparison — Scalpel: 16 tested, 26 compile-only — current: 13 all tested

Maveniverse Scalpel detected 42 affected modules (current approach: 13).

⚠️ Modules only in Scalpel (29)
  • apache-camel
  • camel-allcomponents
  • camel-catalog
  • camel-catalog-console
  • camel-catalog-lucene
  • camel-catalog-maven
  • camel-catalog-suggest
  • camel-componentdsl
  • camel-csimple-maven-plugin
  • camel-endpointdsl
  • camel-endpointdsl-support
  • camel-itest
  • camel-jbang-core
  • camel-jbang-it
  • camel-jbang-main
  • camel-jbang-plugin-edit
  • camel-jbang-plugin-generate
  • camel-jbang-plugin-kubernetes
  • camel-jbang-plugin-test
  • camel-kamelet-main
  • camel-launcher
  • camel-report-maven-plugin
  • camel-route-parser
  • camel-yaml-dsl
  • camel-yaml-dsl-deserializers
  • camel-yaml-dsl-maven-plugin
  • coverage
  • docs
  • dummy-component

Skip-tests mode would test 16 modules (4 direct + 12 downstream), skip tests for 26 (generated code, meta-modules)

Modules Scalpel would test (16)
  • camel-azure-files
  • camel-catalog
  • camel-componentdsl
  • camel-endpointdsl
  • camel-ftp
  • camel-jbang-mcp
  • camel-jbang-plugin-mcp
  • camel-jbang-plugin-route-parser
  • camel-jbang-plugin-tui
  • camel-jbang-plugin-validate
  • camel-jsch
  • camel-launcher-container
  • camel-ssh
  • camel-yaml-dsl-validator
  • camel-yaml-dsl-validator-maven-plugin
  • camel-zookeeper-master
Modules with tests skipped (26)
  • apache-camel
  • camel-allcomponents
  • camel-catalog-console
  • camel-catalog-lucene
  • camel-catalog-maven
  • camel-catalog-suggest
  • camel-csimple-maven-plugin
  • camel-endpointdsl-support
  • camel-itest
  • camel-jbang-core
  • camel-jbang-it
  • camel-jbang-main
  • camel-jbang-plugin-edit
  • camel-jbang-plugin-generate
  • camel-jbang-plugin-kubernetes
  • camel-jbang-plugin-test
  • camel-kamelet-main
  • camel-launcher
  • camel-report-maven-plugin
  • camel-route-parser
  • camel-yaml-dsl
  • camel-yaml-dsl-deserializers
  • camel-yaml-dsl-maven-plugin
  • coverage
  • docs
  • dummy-component

ℹ️ Shadow mode — Scalpel observes but does not affect test execution. Learn more

All tested modules (42 modules)
  • Camel :: All Components Sync point
  • Camel :: Assembly
  • Camel :: Azure :: Files
  • Camel :: Catalog :: CSimple Maven Plugin (deprecated)
  • Camel :: Catalog :: Camel Catalog
  • Camel :: Catalog :: Camel Report Maven Plugin
  • Camel :: Catalog :: Camel Route Parser
  • Camel :: Catalog :: Console
  • Camel :: Catalog :: Dummy Component
  • Camel :: Catalog :: Lucene (deprecated)
  • Camel :: Catalog :: Maven
  • Camel :: Catalog :: Suggest
  • Camel :: Component DSL
  • Camel :: Coverage
  • Camel :: Docs
  • Camel :: Endpoint DSL
  • Camel :: Endpoint DSL :: Support
  • Camel :: FTP
  • Camel :: Integration Tests
  • Camel :: JBang :: Core
  • Camel :: JBang :: Integration tests
  • Camel :: JBang :: MCP
  • Camel :: JBang :: Main
  • Camel :: JBang :: Plugin :: Edit
  • Camel :: JBang :: Plugin :: Generate
  • Camel :: JBang :: Plugin :: Kubernetes
  • Camel :: JBang :: Plugin :: MCP
  • Camel :: JBang :: Plugin :: Route Parser
  • Camel :: JBang :: Plugin :: TUI
  • Camel :: JBang :: Plugin :: Testing
  • Camel :: JBang :: Plugin :: Validate
  • Camel :: Jsch
  • Camel :: Kamelet Main
  • Camel :: Launcher
  • Camel :: Launcher :: Container
  • Camel :: SSH
  • Camel :: YAML DSL
  • Camel :: YAML DSL :: Deserializers
  • Camel :: YAML DSL :: Maven Plugins
  • Camel :: YAML DSL :: Validator
  • Camel :: YAML DSL :: Validator Maven Plugin
  • Camel :: Zookeeper Master

⚙️ View full build and test results

@gnodet
gnodet merged commit a2615d6 into apache:camel-4.22.x Oct 21, 2026
5 checks passed
@oscerd oscerd self-assigned this Oct 21, 2026
@oscerd
oscerd deleted the backport/CAMEL-25644-to-camel-4.22.x branch October 21, 2026 10:08
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 catalog components docs dsl

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants