davsclaus opened a new pull request, #30684: URL: https://github.com/apache/camel/pull/30684
_Claude Code on behalf of davsclaus_ [CAMEL-27479](https://issues.apache.org/jira/browse/CAMEL-27479) ### Problem camel-elasticsearch can only log in with a user and password. Elastic recommends API keys, also on Elastic Cloud, where a client sends `Authorization: ApiKey <base64 of id:key>`. The Kamelets elasticsearch-index-sink and elasticsearch-search-action need this. ### Change - New `apiKey` component option (label `security`, secret). It takes the encoded key as Elasticsearch shows it when the key is created (the `encoded` field), or `id:key`, which Camel base64-encodes. Base64 never contains a colon, so the two forms can't be confused. - The header goes only to the cluster nodes: the hosts of `hostAddresses`, and the nodes the sniffer finds. It is added by a request interceptor that checks the target host with the same matching as `NodeScopedCredentialsProvider` (CAMEL-25706). It is not a `RestClient` default header. On a redirect, HttpClient's `MainClientExec` copies the headers of the original request, where the default headers are, onto the new request, whatever its host. The interceptor runs per request on the wrapper, with the real target host. - Setting both `apiKey` and `user` fails when the endpoint is created, with a clear message. - A client set with the `client` option is not changed, the same as for `user`/`password`. - Docs: new section "Authenticate with an API key". ### Tests - `ElasticsearchProducerApiKeyTest`: two local HTTP servers. The node answers with a 302 to the other server. The node receives the key, and the redirect target does not. The `id:key` form is encoded, nothing is sent without a key, and setting both `apiKey` and `user` fails. With the key as a `setDefaultHeaders` header instead, 2 of these tests fail: the redirect target receives the key. - `ElasticsearchApiKeyIT`: Elasticsearch 9.1.0 container with security and TLS. It creates a key with the container's user, then the components use only the key: index + get with the encoded key, ping with `id:key`, and a wrong key fails. - All unit tests of camel-elasticsearch pass. The OpenSearch side (OpenSearch 3.7+ has the same `ApiKey` header) follows in CAMEL-27480. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
