This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch CAMEL-27708-consul-acl-token in repository https://gitbox.apache.org/repos/asf/camel.git
commit 5db4b2d558006a97a96f1da2349e8d667be127bd Author: Claus Ibsen <[email protected]> AuthorDate: Fri Nov 27 17:29:58 2026 +0100 CAMEL-27708: camel-consul - send the aclToken in the X-Consul-Token header, and log received events at DEBUG The client was created with Consul.Builder.withAclToken(), which adds the token to the URL of every request as the token query parameter, and the catalog, health and agent DEREGISTER actions added it a second time through QueryOptions.token, also next to the token of a custom consulClient. The client is now created with withTokenAuth() (the X-Consul-Token header), and the token is no longer put into the query options. The event consumer logged every received event, with its payload, at INFO. It now logs the id and name at DEBUG and the whole event at TRACE. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../apache/camel/catalog/components/consul.json | 8 +- .../camel/catalog/docs/consul-component.adoc | 9 + .../org/apache/camel/component/consul/consul.json | 8 +- .../src/main/docs/consul-component.adoc | 9 + .../consul/ConsulClientConfiguration.java | 7 +- .../component/consul/ConsulConfiguration.java | 4 +- .../consul/endpoint/AbstractConsulProducer.java | 3 +- .../consul/endpoint/ConsulEventConsumer.java | 11 +- .../camel/component/consul/ConsulAclTokenTest.java | 198 +++++++++++++++++++++ .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 16 ++ .../dsl/ConsulComponentBuilderFactory.java | 6 +- .../endpoint/dsl/ConsulEndpointBuilderFactory.java | 24 ++- 12 files changed, 278 insertions(+), 25 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/consul.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/consul.json index 7d62daf0c175..3ef962296e97 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/consul.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/consul.json @@ -38,11 +38,11 @@ "autowiredEnabled": { "index": 11, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching [...] "configuration": { "index": 12, "kind": "property", "displayName": "Configuration", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.consul.ConsulConfiguration", "deprecated": false, "autowired": false, "secret": false, "description": "The shared configuration of the endpoints that this component creates. Each endpoint gets a copy, and the endpoint options override it." }, "consistencyMode": { "index": 13, "kind": "property", "displayName": "Consistency Mode", "group": "advanced", "label": "advanced", "required": false, "type": "enum", "javaType": "org.kiwiproject.consul.option.ConsistencyMode", "enum": [ "DEFAULT", "STALE", "CONSISTENT" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "DEFAULT", "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description [...] - "consulClient": { "index": 14, "kind": "property", "displayName": "Consul Client", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.kiwiproject.consul.Consul", "deprecated": false, "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The Consul client (org.kiwiproject.consul.Consul) to use instead of creating one. When set [...] + "consulClient": { "index": 14, "kind": "property", "displayName": "Consul Client", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.kiwiproject.consul.Consul", "deprecated": false, "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The Consul client (org.kiwiproject.consul.Consul) to use instead of creating one. When set [...] "datacenter": { "index": 15, "kind": "property", "displayName": "Datacenter", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The datacenter to query instead of the datacenter of the agent. Used by the catalog and health queries, the [...] "nearNode": { "index": 16, "kind": "property", "displayName": "Near Node", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The name of a node (or _agent for the node of the agent) from which Consul sorts the results of the catalog an [...] "nodeMeta": { "index": 17, "kind": "property", "displayName": "Node Meta", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "Comma separated node metadata filters, each as key:value, so that the catalog and health queries return only t [...] - "aclToken": { "index": 18, "kind": "property", "displayName": "Acl Token", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "security": "secret", "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The ACL token that the client sends with each request to Consul." }, + "aclToken": { "index": 18, "kind": "property", "displayName": "Acl Token", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "security": "secret", "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The ACL token that the client sends with each request to Consul, in the X-Consul-Token he [...] "password": { "index": 19, "kind": "property", "displayName": "Password", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "security": "secret", "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The password for HTTP basic authentication to the Consul agent. Used only together with us [...] "sslContextParameters": { "index": 20, "kind": "property", "displayName": "Ssl Context Parameters", "group": "security", "label": "security", "required": false, "type": "object", "javaType": "org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The SSL configuration of the HTTPS connection to th [...] "useGlobalSslContextParameters": { "index": 21, "kind": "property", "displayName": "Use Global Ssl Context Parameters", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to use the global SSL context parameters of the CamelContext for the endpoints that have no sslContextParameters." }, @@ -105,11 +105,11 @@ "action": { "index": 12, "kind": "parameter", "displayName": "Action", "group": "producer", "label": "producer", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "CHECKS", "SERVICES", "MEMBERS", "AGENT", "REGISTER", "DEREGISTER", "PUT", "GET_VALUE", "GET_VALUES", "GET_KEYS", "GET_SESSIONS", "DELETE_KEY", "DELETE_KEYS", "LOCK", "UNLOCK", "LIST_DATACENTERS", "LIST_NODES", "LIST_SERVICES", "GET_SERVICE", "GET_NODE", "NODE_CHECKS", "SERVICE_CHECKS", "SERVICE_I [...] "lazyStartProducer": { "index": 13, "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a produ [...] "consistencyMode": { "index": 14, "kind": "parameter", "displayName": "Consistency Mode", "group": "advanced", "label": "advanced", "required": false, "type": "enum", "javaType": "org.kiwiproject.consul.option.ConsistencyMode", "enum": [ "DEFAULT", "STALE", "CONSISTENT" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "DEFAULT", "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "descriptio [...] - "consulClient": { "index": 15, "kind": "parameter", "displayName": "Consul Client", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.kiwiproject.consul.Consul", "deprecated": false, "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The Consul client (org.kiwiproject.consul.Consul) to use instead of creating one. When se [...] + "consulClient": { "index": 15, "kind": "parameter", "displayName": "Consul Client", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.kiwiproject.consul.Consul", "deprecated": false, "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The Consul client (org.kiwiproject.consul.Consul) to use instead of creating one. When se [...] "datacenter": { "index": 16, "kind": "parameter", "displayName": "Datacenter", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The datacenter to query instead of the datacenter of the agent. Used by the catalog and health queries, th [...] "nearNode": { "index": 17, "kind": "parameter", "displayName": "Near Node", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The name of a node (or _agent for the node of the agent) from which Consul sorts the results of the catalog a [...] "nodeMeta": { "index": 18, "kind": "parameter", "displayName": "Node Meta", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "Comma separated node metadata filters, each as key:value, so that the catalog and health queries return only [...] - "aclToken": { "index": 19, "kind": "parameter", "displayName": "Acl Token", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "security": "secret", "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The ACL token that the client sends with each request to Consul." }, + "aclToken": { "index": 19, "kind": "parameter", "displayName": "Acl Token", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "security": "secret", "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The ACL token that the client sends with each request to Consul, in the X-Consul-Token h [...] "password": { "index": 20, "kind": "parameter", "displayName": "Password", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "security": "secret", "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The password for HTTP basic authentication to the Consul agent. Used only together with u [...] "sslContextParameters": { "index": 21, "kind": "parameter", "displayName": "Ssl Context Parameters", "group": "security", "label": "security", "required": false, "type": "object", "javaType": "org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The SSL configuration of the HTTPS connection to t [...] "userName": { "index": 22, "kind": "parameter", "displayName": "User Name", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "security": "secret", "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The user name for HTTP basic authentication to the Consul agent. Used only together with [...] diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/consul-component.adoc b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/consul-component.adoc index 3acf26b59932..8de171fc41e2 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/consul-component.adoc +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/consul-component.adoc @@ -58,6 +58,15 @@ The `apiEndpoint` denotes the type of https://www.consul.io/api-docs[consul api] | session | ConsulSessionProducer | - |=== +=== ACL token + +The client that the endpoint creates sends the `aclToken` in the `X-Consul-Token` header of each request, never in +the URL. + +When you set your own `consulClient`, the `aclToken` option is not used: configure the token on that client, for +example with `Consul.builder().withTokenAuth(token)`. The `withAclToken(token)` method of the Consul client adds the +token to the URL of each request as the `token` query parameter. + == Examples === Producer Examples diff --git a/components/camel-consul/src/generated/resources/META-INF/org/apache/camel/component/consul/consul.json b/components/camel-consul/src/generated/resources/META-INF/org/apache/camel/component/consul/consul.json index 7d62daf0c175..3ef962296e97 100644 --- a/components/camel-consul/src/generated/resources/META-INF/org/apache/camel/component/consul/consul.json +++ b/components/camel-consul/src/generated/resources/META-INF/org/apache/camel/component/consul/consul.json @@ -38,11 +38,11 @@ "autowiredEnabled": { "index": 11, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching [...] "configuration": { "index": 12, "kind": "property", "displayName": "Configuration", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.consul.ConsulConfiguration", "deprecated": false, "autowired": false, "secret": false, "description": "The shared configuration of the endpoints that this component creates. Each endpoint gets a copy, and the endpoint options override it." }, "consistencyMode": { "index": 13, "kind": "property", "displayName": "Consistency Mode", "group": "advanced", "label": "advanced", "required": false, "type": "enum", "javaType": "org.kiwiproject.consul.option.ConsistencyMode", "enum": [ "DEFAULT", "STALE", "CONSISTENT" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "DEFAULT", "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description [...] - "consulClient": { "index": 14, "kind": "property", "displayName": "Consul Client", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.kiwiproject.consul.Consul", "deprecated": false, "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The Consul client (org.kiwiproject.consul.Consul) to use instead of creating one. When set [...] + "consulClient": { "index": 14, "kind": "property", "displayName": "Consul Client", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.kiwiproject.consul.Consul", "deprecated": false, "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The Consul client (org.kiwiproject.consul.Consul) to use instead of creating one. When set [...] "datacenter": { "index": 15, "kind": "property", "displayName": "Datacenter", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The datacenter to query instead of the datacenter of the agent. Used by the catalog and health queries, the [...] "nearNode": { "index": 16, "kind": "property", "displayName": "Near Node", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The name of a node (or _agent for the node of the agent) from which Consul sorts the results of the catalog an [...] "nodeMeta": { "index": 17, "kind": "property", "displayName": "Node Meta", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "Comma separated node metadata filters, each as key:value, so that the catalog and health queries return only t [...] - "aclToken": { "index": 18, "kind": "property", "displayName": "Acl Token", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "security": "secret", "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The ACL token that the client sends with each request to Consul." }, + "aclToken": { "index": 18, "kind": "property", "displayName": "Acl Token", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "security": "secret", "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The ACL token that the client sends with each request to Consul, in the X-Consul-Token he [...] "password": { "index": 19, "kind": "property", "displayName": "Password", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "security": "secret", "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The password for HTTP basic authentication to the Consul agent. Used only together with us [...] "sslContextParameters": { "index": 20, "kind": "property", "displayName": "Ssl Context Parameters", "group": "security", "label": "security", "required": false, "type": "object", "javaType": "org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The SSL configuration of the HTTPS connection to th [...] "useGlobalSslContextParameters": { "index": 21, "kind": "property", "displayName": "Use Global Ssl Context Parameters", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to use the global SSL context parameters of the CamelContext for the endpoints that have no sslContextParameters." }, @@ -105,11 +105,11 @@ "action": { "index": 12, "kind": "parameter", "displayName": "Action", "group": "producer", "label": "producer", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "CHECKS", "SERVICES", "MEMBERS", "AGENT", "REGISTER", "DEREGISTER", "PUT", "GET_VALUE", "GET_VALUES", "GET_KEYS", "GET_SESSIONS", "DELETE_KEY", "DELETE_KEYS", "LOCK", "UNLOCK", "LIST_DATACENTERS", "LIST_NODES", "LIST_SERVICES", "GET_SERVICE", "GET_NODE", "NODE_CHECKS", "SERVICE_CHECKS", "SERVICE_I [...] "lazyStartProducer": { "index": 13, "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a produ [...] "consistencyMode": { "index": 14, "kind": "parameter", "displayName": "Consistency Mode", "group": "advanced", "label": "advanced", "required": false, "type": "enum", "javaType": "org.kiwiproject.consul.option.ConsistencyMode", "enum": [ "DEFAULT", "STALE", "CONSISTENT" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "DEFAULT", "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "descriptio [...] - "consulClient": { "index": 15, "kind": "parameter", "displayName": "Consul Client", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.kiwiproject.consul.Consul", "deprecated": false, "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The Consul client (org.kiwiproject.consul.Consul) to use instead of creating one. When se [...] + "consulClient": { "index": 15, "kind": "parameter", "displayName": "Consul Client", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.kiwiproject.consul.Consul", "deprecated": false, "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The Consul client (org.kiwiproject.consul.Consul) to use instead of creating one. When se [...] "datacenter": { "index": 16, "kind": "parameter", "displayName": "Datacenter", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The datacenter to query instead of the datacenter of the agent. Used by the catalog and health queries, th [...] "nearNode": { "index": 17, "kind": "parameter", "displayName": "Near Node", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The name of a node (or _agent for the node of the agent) from which Consul sorts the results of the catalog a [...] "nodeMeta": { "index": 18, "kind": "parameter", "displayName": "Node Meta", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "Comma separated node metadata filters, each as key:value, so that the catalog and health queries return only [...] - "aclToken": { "index": 19, "kind": "parameter", "displayName": "Acl Token", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "security": "secret", "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The ACL token that the client sends with each request to Consul." }, + "aclToken": { "index": 19, "kind": "parameter", "displayName": "Acl Token", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "security": "secret", "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The ACL token that the client sends with each request to Consul, in the X-Consul-Token h [...] "password": { "index": 20, "kind": "parameter", "displayName": "Password", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "security": "secret", "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The password for HTTP basic authentication to the Consul agent. Used only together with u [...] "sslContextParameters": { "index": 21, "kind": "parameter", "displayName": "Ssl Context Parameters", "group": "security", "label": "security", "required": false, "type": "object", "javaType": "org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The SSL configuration of the HTTPS connection to t [...] "userName": { "index": 22, "kind": "parameter", "displayName": "User Name", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "security": "secret", "configurationClass": "org.apache.camel.component.consul.ConsulConfiguration", "configurationField": "configuration", "description": "The user name for HTTP basic authentication to the Consul agent. Used only together with [...] diff --git a/components/camel-consul/src/main/docs/consul-component.adoc b/components/camel-consul/src/main/docs/consul-component.adoc index 3acf26b59932..8de171fc41e2 100644 --- a/components/camel-consul/src/main/docs/consul-component.adoc +++ b/components/camel-consul/src/main/docs/consul-component.adoc @@ -58,6 +58,15 @@ The `apiEndpoint` denotes the type of https://www.consul.io/api-docs[consul api] | session | ConsulSessionProducer | - |=== +=== ACL token + +The client that the endpoint creates sends the `aclToken` in the `X-Consul-Token` header of each request, never in +the URL. + +When you set your own `consulClient`, the `aclToken` option is not used: configure the token on that client, for +example with `Consul.builder().withTokenAuth(token)`. The `withAclToken(token)` method of the Consul client adds the +token to the URL of each request as the `token` query parameter. + == Examples === Producer Examples diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulClientConfiguration.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulClientConfiguration.java index c30459fe07a8..cfc0ca5da68b 100644 --- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulClientConfiguration.java +++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulClientConfiguration.java @@ -68,7 +68,8 @@ public abstract class ConsulClientConfiguration implements Cloneable { + " SSL context parameters are used if the component enables useGlobalSslContextParameters.") private SSLContextParameters sslContextParameters; @UriParam(label = "security", security = "secret", - description = "The ACL token that the client sends with each request to Consul.") + description = "The ACL token that the client sends with each request to Consul, in the X-Consul-Token" + + " header. Not used when a consulClient is set: configure the token on that client instead.") private String aclToken; @UriParam(label = "security", security = "secret", description = "The user name for HTTP basic authentication to the Consul agent. Used only together with" @@ -289,7 +290,9 @@ public abstract class ConsulClientConfiguration implements Cloneable { builder.withSslContext(sslContextParameters.createSSLContext(camelContext)); } if (ObjectHelper.isNotEmpty(aclToken)) { - builder.withAclToken(aclToken); + // withTokenAuth sends the token in the X-Consul-Token header, while withAclToken adds it to the URL of + // every request as the token query parameter + builder.withTokenAuth(aclToken); } if (requiresBasicAuthentication()) { builder.withBasicAuth(userName, password); diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulConfiguration.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulConfiguration.java index f33f35f9ffdc..a7875dffa7d7 100644 --- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulConfiguration.java +++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulConfiguration.java @@ -27,8 +27,8 @@ public class ConsulConfiguration extends ConsulClientConfiguration { @UriParam(label = "advanced", description = "The Consul client (org.kiwiproject.consul.Consul) to use instead of creating one. When set, the" - + " options that create the client (url, sslContextParameters, userName, password, the" - + " timeouts and pingInstance) are not used.") + + " options that create the client (url, sslContextParameters, aclToken, userName, password," + + " the timeouts and pingInstance) are not used.") @Metadata(autowired = true) private Consul consulClient; @UriParam diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/AbstractConsulProducer.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/AbstractConsulProducer.java index d79ca2c3d277..c4b4d4a6893e 100644 --- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/AbstractConsulProducer.java +++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/AbstractConsulProducer.java @@ -116,7 +116,8 @@ abstract class AbstractConsulProducer<C> extends HeaderSelectorProducer { builder::datacenter); ObjectHelper.ifNotEmpty(message.getHeader(ConsulConstants.CONSUL_NEAR_NODE, conf.getNearNode(), String.class), builder::near); - ObjectHelper.ifNotEmpty(conf.getAclToken(), builder::token); + // the ACL token is not added to the query options: the client sends it in the X-Consul-Token header, and + // the query options would add it to the URL as the token query parameter ObjectHelper.ifNotEmpty( message.getHeader(ConsulConstants.CONSUL_CONSISTENCY_MODE, conf.getConsistencyMode(), ConsistencyMode.class), builder::consistencyMode); diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/ConsulEventConsumer.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/ConsulEventConsumer.java index 3ae01ebb574c..500a2d250642 100644 --- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/ConsulEventConsumer.java +++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/ConsulEventConsumer.java @@ -34,9 +34,13 @@ import org.kiwiproject.consul.async.EventResponseCallback; import org.kiwiproject.consul.model.EventResponse; import org.kiwiproject.consul.model.event.Event; import org.kiwiproject.consul.option.QueryOptions; +import org.slf4j.Logger; import org.slf4j.LoggerFactory; public final class ConsulEventConsumer extends AbstractConsulConsumer<EventClient> { + + private static final Logger LOG = LoggerFactory.getLogger(ConsulEventConsumer.class); + private final ExecutorServiceManager executorServiceManager; private ScheduledExecutorService scheduledExecutorService; @@ -110,7 +114,12 @@ public final class ConsulEventConsumer extends AbstractConsulConsumer<EventClien } private void onEvent(Event event) { - LoggerFactory.getLogger(ConsulEventConsumer.this.getClass()).info("{}", event); + // the event holds the payload, so only its id and name are logged at DEBUG + if (LOG.isTraceEnabled()) { + LOG.trace("Received event: {}", event); + } else { + LOG.debug("Received event with id: {} and name: {}", event.getId(), event.getName()); + } final Exchange exchange = createExchange(false); try { diff --git a/components/camel-consul/src/test/java/org/apache/camel/component/consul/ConsulAclTokenTest.java b/components/camel-consul/src/test/java/org/apache/camel/component/consul/ConsulAclTokenTest.java new file mode 100644 index 000000000000..77fb98015d21 --- /dev/null +++ b/components/camel-consul/src/test/java/org/apache/camel/component/consul/ConsulAclTokenTest.java @@ -0,0 +1,198 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.consul; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CopyOnWriteArrayList; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpServer; +import org.apache.camel.BindToRegistry; +import org.apache.camel.component.consul.endpoint.ConsulAgentActions; +import org.apache.camel.component.consul.endpoint.ConsulCatalogActions; +import org.apache.camel.component.consul.endpoint.ConsulHealthActions; +import org.apache.camel.component.consul.endpoint.ConsulKeyValueActions; +import org.apache.camel.test.junit6.CamelTestSupport; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.kiwiproject.consul.Consul; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +/** + * The ACL token is sent in the X-Consul-Token header, and never as the token query parameter of the URL. + */ +public class ConsulAclTokenTest extends CamelTestSupport { + + private static final String TOKEN = "my-acl-token"; + private static final String CLIENT_TOKEN = "client-acl-token"; + + private static HttpServer server; + private static final List<RecordedRequest> REQUESTS = new CopyOnWriteArrayList<>(); + + private record RecordedRequest(String method, String path, String query, String token) { + } + + @BindToRegistry("clientWithoutToken") + public Consul clientWithoutToken() { + return Consul.builder().withUrl(url()).withPing(false).build(); + } + + @BindToRegistry("clientWithToken") + public Consul clientWithToken() { + return Consul.builder().withUrl(url()).withPing(false).withTokenAuth(CLIENT_TOKEN).build(); + } + + @BeforeAll + public static void startServer() throws IOException { + // port 0: the OS picks a free port + server = HttpServer.create(new InetSocketAddress("localhost", 0), 0); + server.createContext("/", ConsulAclTokenTest::handle); + server.start(); + } + + @AfterAll + public static void stopServer() { + if (server != null) { + server.stop(0); + } + } + + @BeforeEach + public void clearRequests() { + REQUESTS.clear(); + } + + private static String url() { + return "http://localhost:" + server.getAddress().getPort(); + } + + private static void handle(HttpExchange exchange) throws IOException { + try (InputStream in = exchange.getRequestBody()) { + in.readAllBytes(); + } + REQUESTS.add(new RecordedRequest( + exchange.getRequestMethod(), exchange.getRequestURI().getPath(), exchange.getRequestURI().getRawQuery(), + exchange.getRequestHeaders().getFirst("X-Consul-Token"))); + + String json = exchange.getRequestURI().getPath().equals("/v1/catalog/services") ? "{}" : "[]"; + byte[] body = "GET".equals(exchange.getRequestMethod()) ? json.getBytes(StandardCharsets.UTF_8) : new byte[0]; + exchange.getResponseHeaders().add("Content-Type", "application/json"); + exchange.getResponseHeaders().add("X-Consul-Index", "1"); + exchange.getResponseHeaders().add("X-Consul-Knownleader", "true"); + exchange.getResponseHeaders().add("X-Consul-Lastcontact", "0"); + exchange.sendResponseHeaders(200, body.length == 0 ? -1 : body.length); + try (OutputStream out = exchange.getResponseBody()) { + out.write(body); + } + } + + private String endpoint(String api, String action) { + return "consul:" + api + "?url=" + url() + "&pingInstance=false&aclToken=" + TOKEN + "&action=" + action; + } + + private RecordedRequest lastRequest() { + assertEquals(1, REQUESTS.size(), "Expected one request but got: " + REQUESTS); + return REQUESTS.get(0); + } + + @Test + public void testCatalogListNodes() { + template.sendBody(endpoint("catalog", ConsulCatalogActions.LIST_NODES), null); + + RecordedRequest request = lastRequest(); + assertEquals("/v1/catalog/nodes", request.path()); + assertNull(request.query(), "The token must not be in the URL"); + assertEquals(TOKEN, request.token()); + } + + @Test + public void testCatalogListServicesWithDatacenter() { + template.sendBody(endpoint("catalog", ConsulCatalogActions.LIST_SERVICES) + "&datacenter=dc1", null); + + RecordedRequest request = lastRequest(); + assertEquals("/v1/catalog/services", request.path()); + assertEquals("dc=dc1", request.query()); + assertEquals(TOKEN, request.token()); + } + + @Test + public void testHealthServiceChecks() { + template.sendBodyAndHeader(endpoint("health", ConsulHealthActions.SERVICE_CHECKS), null, + ConsulConstants.CONSUL_SERVICE, "my-service"); + + RecordedRequest request = lastRequest(); + assertEquals("/v1/health/checks/my-service", request.path()); + assertNull(request.query(), "The token must not be in the URL"); + assertEquals(TOKEN, request.token()); + } + + @Test + public void testAgentDeregister() { + template.sendBodyAndHeader(endpoint("agent", ConsulAgentActions.DEREGISTER), null, + ConsulConstants.CONSUL_SERVICE_ID, "my-service-1"); + + RecordedRequest request = lastRequest(); + assertEquals("PUT", request.method()); + assertEquals("/v1/agent/service/deregister/my-service-1", request.path()); + assertNull(request.query(), "The token must not be in the URL"); + assertEquals(TOKEN, request.token()); + } + + @Test + public void testKeyValueGetValue() { + template.sendBodyAndHeader(endpoint("kv", ConsulKeyValueActions.GET_VALUE), null, + ConsulConstants.CONSUL_KEY, "my-key"); + + RecordedRequest request = lastRequest(); + assertEquals("/v1/kv/my-key", request.path()); + assertNull(request.query(), "The token must not be in the URL"); + assertEquals(TOKEN, request.token()); + } + + @Test + public void testCustomClientUsesItsOwnToken() { + template.sendBody("consul:catalog?consulClient=#clientWithToken&aclToken=" + TOKEN + "&action=" + + ConsulCatalogActions.LIST_NODES, + null); + + RecordedRequest request = lastRequest(); + assertNull(request.query(), "The token must not be in the URL"); + assertEquals(CLIENT_TOKEN, request.token()); + } + + @Test + public void testCustomClientWithoutToken() { + template.sendBodyAndHeaders("consul:health?consulClient=#clientWithoutToken&aclToken=" + TOKEN + "&action=" + + ConsulHealthActions.SERVICE_CHECKS, + null, Map.of(ConsulConstants.CONSUL_SERVICE, "my-service")); + + // the aclToken option configures the client that the endpoint creates, not a custom client + RecordedRequest request = lastRequest(); + assertNull(request.query(), "The token must not be in the URL"); + assertNull(request.token()); + } +} diff --git a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc index 25708c2cd51b..92c4d724d279 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc @@ -12297,6 +12297,22 @@ With `allowUrlBody=true`, a body that does not start with `version: 1` and is no with a space or a relative name, now fails with an `InvalidPayloadException`, as a URL with an unknown scheme already did. Before, it failed with an `IllegalArgumentException`. A URL that cannot be fetched keeps its own exception. +=== camel-consul - the aclToken is sent in the X-Consul-Token header + +The Consul client that the endpoint (and the `ConsulClusterService`) creates now sends the `aclToken` in the +`X-Consul-Token` header of each request. Before, the token was added to the URL of each request as the `token` query +parameter, and the catalog, health and agent `DEREGISTER` actions added it a second time. The Consul agent accepts +both, so a working setup keeps working, but a proxy in front of Consul that relies on the `token` query parameter +must read the header instead. + +When you set your own `consulClient`, the `aclToken` option of the endpoint is no longer used: the catalog, health and +agent `DEREGISTER` actions used to add it to the URL next to the token of that client. Configure the token on your +client, preferably with `Consul.builder().withTokenAuth(token)` (the header) instead of `withAclToken(token)` (the +query parameter). + +The event consumer now logs the received events at DEBUG level (id and name) and TRACE level (the whole event with its +payload), instead of logging each event with its payload at INFO level. + === Kamelets - removed Kamelets The Kamelet catalog (camel-kamelets 4.24) removes Kamelets that could not work on Camel 4.23 or 4.24: diff --git a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/ConsulComponentBuilderFactory.java b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/ConsulComponentBuilderFactory.java index 20fba89213b1..4ae2e6ea1d04 100644 --- a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/ConsulComponentBuilderFactory.java +++ b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/ConsulComponentBuilderFactory.java @@ -336,7 +336,7 @@ public interface ConsulComponentBuilderFactory { /** * The Consul client (org.kiwiproject.consul.Consul) to use instead of * creating one. When set, the options that create the client (url, - * sslContextParameters, userName, password, the timeouts and + * sslContextParameters, aclToken, userName, password, the timeouts and * pingInstance) are not used. * * The option is a: @@ -406,7 +406,9 @@ public interface ConsulComponentBuilderFactory { } /** - * The ACL token that the client sends with each request to Consul. + * The ACL token that the client sends with each request to Consul, in + * the X-Consul-Token header. Not used when a consulClient is set: + * configure the token on that client instead. * * The option is a: <code>java.lang.String</code> type. * diff --git a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/ConsulEndpointBuilderFactory.java b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/ConsulEndpointBuilderFactory.java index 083dba6ad855..7046fe57482a 100644 --- a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/ConsulEndpointBuilderFactory.java +++ b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/ConsulEndpointBuilderFactory.java @@ -263,7 +263,9 @@ public interface ConsulEndpointBuilderFactory { return this; } /** - * The ACL token that the client sends with each request to Consul. + * The ACL token that the client sends with each request to Consul, in + * the X-Consul-Token header. Not used when a consulClient is set: + * configure the token on that client instead. * * The option is a: <code>java.lang.String</code> type. * @@ -621,7 +623,7 @@ public interface ConsulEndpointBuilderFactory { /** * The Consul client (org.kiwiproject.consul.Consul) to use instead of * creating one. When set, the options that create the client (url, - * sslContextParameters, userName, password, the timeouts and + * sslContextParameters, aclToken, userName, password, the timeouts and * pingInstance) are not used. * * The option is a: <code>org.kiwiproject.consul.Consul</code> type. @@ -638,7 +640,7 @@ public interface ConsulEndpointBuilderFactory { /** * The Consul client (org.kiwiproject.consul.Consul) to use instead of * creating one. When set, the options that create the client (url, - * sslContextParameters, userName, password, the timeouts and + * sslContextParameters, aclToken, userName, password, the timeouts and * pingInstance) are not used. * * The option will be converted to a @@ -957,7 +959,9 @@ public interface ConsulEndpointBuilderFactory { return this; } /** - * The ACL token that the client sends with each request to Consul. + * The ACL token that the client sends with each request to Consul, in + * the X-Consul-Token header. Not used when a consulClient is set: + * configure the token on that client instead. * * The option is a: <code>java.lang.String</code> type. * @@ -1133,7 +1137,7 @@ public interface ConsulEndpointBuilderFactory { /** * The Consul client (org.kiwiproject.consul.Consul) to use instead of * creating one. When set, the options that create the client (url, - * sslContextParameters, userName, password, the timeouts and + * sslContextParameters, aclToken, userName, password, the timeouts and * pingInstance) are not used. * * The option is a: <code>org.kiwiproject.consul.Consul</code> type. @@ -1150,7 +1154,7 @@ public interface ConsulEndpointBuilderFactory { /** * The Consul client (org.kiwiproject.consul.Consul) to use instead of * creating one. When set, the options that create the client (url, - * sslContextParameters, userName, password, the timeouts and + * sslContextParameters, aclToken, userName, password, the timeouts and * pingInstance) are not used. * * The option will be converted to a @@ -1447,7 +1451,9 @@ public interface ConsulEndpointBuilderFactory { return this; } /** - * The ACL token that the client sends with each request to Consul. + * The ACL token that the client sends with each request to Consul, in + * the X-Consul-Token header. Not used when a consulClient is set: + * configure the token on that client instead. * * The option is a: <code>java.lang.String</code> type. * @@ -1580,7 +1586,7 @@ public interface ConsulEndpointBuilderFactory { /** * The Consul client (org.kiwiproject.consul.Consul) to use instead of * creating one. When set, the options that create the client (url, - * sslContextParameters, userName, password, the timeouts and + * sslContextParameters, aclToken, userName, password, the timeouts and * pingInstance) are not used. * * The option is a: <code>org.kiwiproject.consul.Consul</code> type. @@ -1597,7 +1603,7 @@ public interface ConsulEndpointBuilderFactory { /** * The Consul client (org.kiwiproject.consul.Consul) to use instead of * creating one. When set, the options that create the client (url, - * sslContextParameters, userName, password, the timeouts and + * sslContextParameters, aclToken, userName, password, the timeouts and * pingInstance) are not used. * * The option will be converted to a
