Skip to content

[backport camel-4.18.x] CAMEL-25706, CAMEL-25707, CAMEL-25708: camel-elasticsearch, camel-elasticsearch-rest-client, camel-opensearch - bind the basic authentication credentials to the cluster nodes - #28051

Merged
davsclaus merged 3 commits into
apache:camel-4.18.xfrom
oscerd:backport/CAMEL-25706-25708-to-camel-4.18.x
Oct 18, 2026

Conversation

@oscerd

@oscerd oscerd commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Description

Backport of #27949 (CAMEL-25707), #27948 (CAMEL-25708) and #27946 (CAMEL-25706) to camel-4.18.x, picked from the merged commits f8bd57d57c79, 004809689f98 and 442e440e43e6, in merge order.

  • camel-opensearch: the pick applies as it is.
  • camel-elasticsearch and camel-elasticsearch-rest-client: on this branch, createClient() sets the HTTP client callback only when credentials are configured, and that callback also applies certificatePath.
    • That structure is kept. The callback is installed when createCredentialsProvider(...) returns a provider, and it sets that provider instead of the AuthScope.ANY one.
    • Because this differs from main, it is not a straight cherry-pick.
  • The new classes and tests are the same as on main. They use only JUnit Jupiter and DefaultCamelContext, so they run unchanged with this branch's test setup.
  • The camel-4x-upgrade-guide-4_24.adoc hunks are dropped, because the upgrade guides live on main. The 4.18.6 notes are added on main in CAMEL-25706, CAMEL-25707, CAMEL-25708: upgrade guide notes for the 4.22.3 and 4.18.6 backports #28052.

Tests

  • Full reactor mvn clean install -DskipTests -DskipITs on this branch: green, no generated-file changes.
  • Module tests pass, including all the new tests; this branch has fewer existing tests than main:
Module Tests
camel-elasticsearch 12
camel-elasticsearch-rest-client 12
camel-opensearch 12

Claude Code on behalf of oscerd

🤖 Generated with Claude Code

oscerd and others added 3 commits October 18, 2026 12:16
…ication credentials to the cluster nodes

[CAMEL-25707](https://issues.apache.org/jira/browse/CAMEL-25707): `ElasticsearchRestClientProducer.createClient()` registered the configured `user` and `password` with `AuthScope.ANY`, which matches any host.

- The credentials are now held by a `NodeScopedCredentialsProvider`, which offers them only to the nodes the client talks to: the hosts of `hostAddressesList` and, when `enableSniffer` is set, the nodes the sniffer finds.
- A node matches on scheme, host name (in any case) and port. A node without a port matches the default port of its scheme.
- The provider reads the nodes from the `RestClient` (`getNodes()`) on each lookup, so it follows the nodes the sniffer adds or removes. Every configured node keeps receiving the credentials.
- HttpClient 4's `BasicCredentialsProvider` matches an `AuthScope` on host and port only, never on the scheme. The provider therefore checks the origin of the scope that HttpClient looks the credentials up with, both preemptively and after a challenge.
- `setCredentials` and `clear` do nothing, because the credentials come from the endpoint configuration only. HttpClient calls `setCredentials` for the user info of a request URI.
- A client set with the `restClient` option is not changed.

This is the same change as apache#27946 (CAMEL-25706) for camel-elasticsearch. The provider class is duplicated because the two components are separate modules.

Closes apache#27949

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit f8bd57d)
Signed-off-by: Andrea Cosentino <ancosen@gmail.com>
…ials to the cluster nodes

[CAMEL-25708](https://issues.apache.org/jira/browse/CAMEL-25708): `OpensearchProducer.createClient()` registered the configured `user` and `password` with `new AuthScope(null, null, -1, null, null)`, which matches any host. [CAMEL-24815](https://issues.apache.org/jira/browse/CAMEL-24815) switched to it so that every node of a multi-host cluster receives the credentials, not only the first configured host.

- The credentials are now held by a `NodeScopedCredentialsProvider`, which offers them only to the nodes the client talks to: the hosts of `hostAddresses` and, when `enableSniffer` is set, the nodes the sniffer finds. Every configured node keeps receiving them, as CAMEL-24815 intended.
- A node matches on scheme, host name (in any case) and port. A node without a port matches the default port of its scheme.
- The provider reads the nodes from the `RestClient` (`getNodes()`) on each lookup, so it follows the nodes the sniffer adds or removes.
- A client set with the `client` or `openSearchClient` option is not changed.

This is the same change as apache#27946 (CAMEL-25706) for camel-elasticsearch. Here it is written against HttpClient 5, whose `CredentialsProvider` only looks credentials up, and whose `AuthScope` carries the scheme (`getProtocol()`).

Upgrade guide (4.24): a request to another host is sent without the credentials. This includes the host of a node with another scheme or port.

Closes apache#27948

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 0048096)
Signed-off-by: Andrea Cosentino <ancosen@gmail.com>
…entials to the cluster nodes

[CAMEL-25706](https://issues.apache.org/jira/browse/CAMEL-25706): `ElasticsearchProducer.createClient()` registered the configured `user` and `password` with `AuthScope.ANY`, which matches any host.

- The credentials are now held by a `NodeScopedCredentialsProvider`, which offers them only to the nodes the client talks to: the hosts of `hostAddresses` and, when `enableSniffer` is set, the nodes the sniffer finds.
- A node matches on scheme, host name (in any case) and port. A node without a port matches the default port of its scheme.
- The provider reads the nodes from the `RestClient` (`getNodes()`) on each lookup, so it follows the nodes the sniffer adds or removes. Every configured node keeps receiving the credentials.
- HttpClient 4's `BasicCredentialsProvider` matches an `AuthScope` on host and port only, never on the scheme. The provider therefore checks the origin of the scope that HttpClient looks the credentials up with, both preemptively and after a challenge.
- `setCredentials` and `clear` do nothing, because the credentials come from the endpoint configuration only. HttpClient calls `setCredentials` for the user info of a request URI.
- A client set with the `client` option is not changed.

Closes apache#27946

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 442e440)
Signed-off-by: Andrea Cosentino <ancosen@gmail.com>

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

Well-structured security backport that correctly replaces AuthScope.ANY with node-scoped credential matching across all three Elasticsearch/OpenSearch components.

The NodeScopedCredentialsProvider correctly scopes credentials to the nodes the client knows about, following sniffer-discovered nodes via the AtomicReference<RestClient> pattern. The test coverage (unit tests for NodeScopedCredentialsProvider, integration-style tests for BasicAuthentication, and producer-level credential tests) is solid. The port adaptation to the 4.18.x branch structure (HttpClient 4 API, Collection<HttpHost> instead of List<HttpHost>) is correct.

One pre-existing structural note on camel-elasticsearch and camel-elasticsearch-rest-client (unchanged by this PR):

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

@davsclaus davsclaus added this to the 4.18.6 milestone Oct 18, 2026
@davsclaus davsclaus added backport indicate that a Pull request is a backport from a fix from the main branch bug Something isn't working labels Oct 18, 2026
@davsclaus
davsclaus merged commit 8b0806e into apache:camel-4.18.x Oct 18, 2026
3 checks passed
@oscerd
oscerd deleted the backport/CAMEL-25706-25708-to-camel-4.18.x branch October 19, 2026 07:12
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