davsclaus opened a new pull request, #31037: URL: https://github.com/apache/camel/pull/31037
JIRA: https://issues.apache.org/jira/browse/CAMEL-27708 ## What was wrong 1. **The aclToken was sent in the URL.** `ConsulClientConfiguration.createConsulClient()` used `Consul.Builder.withAclToken()`. In consul-client 1.12.2 that adds an okhttp interceptor which appends `?token=...` / `&token=...` to the URL of every request; it does not set the `X-Consul-Token` header (`withTokenAuth()` does that). On top of this, `AbstractConsulProducer.buildQueryOptions()` copied `aclToken` into `QueryOptions.token`, so the catalog actions, the health actions and agent `DEREGISTER` sent it twice (`token=x&token=x`). With a custom `consulClient`, these actions still added the endpoint `aclToken` to the URL, next to the token of that client. A token in a URL ends up in proxy and access logs, and Consul has deprecated the `token` query parameter. 2. **Received events were logged at INFO.** `ConsulEventConsumer.EventWatcher.onEvent()` logged every event with `info("{}", event)`, and the `toString()` of the event includes its payload. ## What changed - `ConsulClientConfiguration.createConsulClient()` uses `withTokenAuth(aclToken)`: the token goes in the `X-Consul-Token` header. This covers every endpoint (kv, event, catalog, health, agent, session, ...) and the `ConsulClusterService`, which creates its client the same way. - `AbstractConsulProducer.buildQueryOptions()` no longer puts the token into the `QueryOptions`. - With a custom `consulClient`, the endpoint `aclToken` is not used; the token of that client is used. The `aclToken` and `consulClient` option descriptions say so, and the component doc has a short "ACL token" section (recommending `withTokenAuth()` over `withAclToken()` for a custom client). - `ConsulEventConsumer` logs the event id and name at DEBUG, and the whole event only at TRACE. - No other consul consumer or producer logs received data at INFO, and no other code puts the token into query options. ## Tests New `ConsulAclTokenTest` (7 tests): a JDK `HttpServer` on port 0 stands in for the Consul agent and records the query string and the `X-Consul-Token` header of each request. It covers catalog LIST_NODES and LIST_SERVICES (with a datacenter, to check that the other query parameters stay), health SERVICE_CHECKS, agent DEREGISTER, kv GET_VALUE, a custom client with its own token, and a custom client without a token. No Docker needed. All 7 fail before the fix (for example `token=my-acl-token&token=my-acl-token` for the catalog, health and deregister actions, `token=my-acl-token` for kv) and pass after it. All unit tests of the module pass. ## Docs - Option descriptions of `aclToken` and `consulClient` (regenerated component JSON, catalog copy, endpoint and component DSL). - `consul-component.adoc` (and catalog copy): new "ACL token" section. - Upgrade guide 4.24: `camel-consul - the aclToken is sent in the X-Consul-Token header` (header instead of the query parameter, custom `consulClient` must configure its own token, event log level). _Claude Code on behalf of Claus Ibsen_ 🤖 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]
