davsclaus opened a new pull request, #30686: URL: https://github.com/apache/camel/pull/30686
_Claude Code on behalf of davsclaus_ [CAMEL-27480](https://issues.apache.org/jira/browse/CAMEL-27480) ### Problem camel-opensearch can only log in with a user and password. Since 3.7, the OpenSearch Security plugin has API keys ([docs](https://docs.opensearch.org/latest/security/access-control/api-keys/)). A client sends one as `Authorization: ApiKey os_...`. ### Change Same as camel-elasticsearch in #30684 (CAMEL-27479): - New `apiKey` component option (label `security`, secret). It takes the token OpenSearch returns when a key is created, as is. - The header goes only to the cluster nodes: the hosts of `hostAddresses`, and the nodes the sniffer finds. It is added by an HttpClient 5 request interceptor that checks the route's target host against the nodes, with the matching of `NodeScopedCredentialsProvider` (CAMEL-25708), now shared as `isNode`. - Why not a `RestClient` default header: on HttpClient 5.6, a default `Authorization` header doesn't leak, because `DefaultRedirectStrategy.isRedirectAllowed` refuses a redirect to another host when the request has an `Authorization` or `Cookie` header. But such a redirect then fails, and the client gets the 302. With the interceptor, redirects behave as they do without a key or with basic auth, and the key stays on the nodes. - Setting both `apiKey` and `user` fails when the endpoint is created, with a clear message. - A client set with the `client` or `openSearchClient` option is not changed, the same as for `user`/`password`. - Docs: new section "Authenticate with an API key". ### Tests - `OpensearchProducerApiKeyTest`: two local HTTP servers. The node answers with a 302 to the other server. The node receives `ApiKey <token>`, and the redirect target receives no `Authorization`. Nothing is sent without a key, and setting both `apiKey` and `user` fails. - All unit tests of camel-opensearch pass. - Checked by hand against an OpenSearch 3.10.0 container with security on and `api_tokens` turned on. With `Authorization: ApiKey <token>`, health returned 200, and index + get of a document worked. A wrong key returned 401, and `Bearer <token>` returned 401. Indexing needs `indices:data/write/bulk` as a cluster permission of the key (403 without it), so the docs now say so. - No container IT: the test-infra OpenSearch container runs with security off, and API keys must also be turned on in the security config (`config.dynamic.api_tokens.enabled`). The ppc64le image is 3.6, which has no API keys. 🤖 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]
