davsclaus opened a new pull request, #3205:
URL: https://github.com/apache/camel-kamelets/pull/3205

   Part of #3170: `nats-source` and `nats-sink` can connect with TLS, also to a 
server with a certificate from a private certificate authority, and log in with 
a NATS credentials file. `nats-source` can join a queue group, so that several 
copies of an integration share the messages instead of each receiving all of 
them.
   
   ### The options
   
   | Option | Kamelets | Template mapping |
   |---|---|---|
   | `secure` (boolean) | both | `secure: "{{?secure}}"` |
   | `credentialsFilePath` (`pattern: ^(file\|classpath\|http\|https):.+`) | 
both | `credentialsFilePath: "{{?credentialsFilePath}}"` |
   | `queueName` (`pattern: ^\S+$`) | `nats-source` | `queueName: 
"{{?queueName}}"` |
   
   - **TLS.** With `secure: true` the Kamelet connects with TLS and checks the 
certificate of the server against the certificate authorities that Java trusts. 
Before, a server with TLS in its configuration refused the Kamelets with `SSL 
required by server`. A `tls://` address in `servers` also connects with TLS 
(that already worked on `main`), but camel-nats hands its own TLS settings to 
the client only when `secure` is true, so `secure` is what makes a private 
trust store work.
   - **Why no trust store file option, unlike the MQTT Kamelets in #3194.** 
Paho takes its TLS settings as a `Properties` option, so #3194 could map 
`sslTruststoreLocation` to an entry of it. camel-nats takes them only as an 
`SSLContextParameters` object (`sslContextParameters`), and the jnats trust 
store settings are not exposed. A trust store file option would need a bean in 
the template, and that bean would be in the endpoint URI even when no trust 
store is set, which would change the endpoint of every existing user and switch 
off the global settings. So the Kamelets use the global Camel TLS settings, as 
`http-sink` already does: `camel.ssl.enabled=true`, `camel.ssl.trustStore`, 
`camel.ssl.trustStorePassword` and 
`camel.component.nats.useGlobalSslContextParameters=true`. The NATS component 
then uses that trust store for each endpoint with `secure`, in place of the one 
of Java. The same settings also give a client certificate 
(`camel.ssl.keyStore`) for mutual TLS, but that was not 
 tested.
   - **`credentialsFilePath`** is a NATS credentials file (`.creds`): a user 
JWT and the NKey seed of the user, as `nsc generate creds` makes it and as 
servers with decentralized authentication (operator, accounts, resolver) want. 
camel-nats reads it as a Camel resource, so the value starts with `file:`, 
`classpath:`, `http:` or `https:`. Without a prefix it is looked up on the 
classpath: Camel JBang also found an absolute path without a prefix, but a 
plain runtime would not, so the `pattern` asks for the prefix.
   - **`queueName`.** The sources with the same queue group share the messages 
of the subject, and each message goes to one of them. It does this only without 
JetStream: with `jetstreamEnabled`, each copy makes its own ephemeral JetStream 
consumer, and the queue group shares the messages only within one consumer, so 
each copy still receives every message. The description says so. Sharing a 
JetStream stream needs a durable consumer (`durableName`, also in #3170), which 
is not in this PR.
   - The existing login stays as it was: a user and password, or a token, in 
the address in `servers`. The `servers` descriptions now mention the token 
form, which was tested.
   - None of the options has a `default`, so with them unset the endpoint URI 
is exactly as on `main`.
   - The "Good to know" paragraphs, the option descriptions and both partial 
pages are updated, with a TLS, credentials file and queue group example. The 
examples were run against the test servers.
   
   ### Verification
   
   Tested with Camel JBang 4.24.0-SNAPSHOT (`camel run 
--local-kamelet-dir=kamelets`) against `nats:2` (nats-server 2.15.3) in Docker, 
with `natsio/nats-box` (`nats`, `nsc`) as the other client. The TLS server had 
a certificate from a self-signed test CA, for `localhost`. For the credentials 
file, `nsc` made an operator, the accounts `APP` and `OTHER` with a user each, 
and the server ran with the memory resolver config from `nsc generate config 
--mem-resolver`. A second operator made a user the server does not know. The 
PKCS12 trust store password was `p@ss&w+rd=1`.
   
   | Case | Sink | Source |
   |---|---|---|
   | Options unset, endpoint URI from `main` and from this PR (`camel get 
endpoint --json`) | Same: 
`nats://<topic>?jetstreamAsync=true&jetstreamEnabled=false&servers=...` | Same |
   | TLS server, `secure` unset (as on `main`) | Fails to start: `SSL required 
by server` | The same |
   | TLS server, `secure: true`, no trust store | Fails to start: `PKIX path 
building failed` | The same |
   | `secure: true`, `camel.ssl` trust store with the test CA (PKCS12), 
`nats://` address | Sent; the `nats-box` subscriber over TLS received all 3 | 
Received a message published over TLS |
   | The same with a `tls://` address | Sent and received | - |
   | The same with a JKS trust store | Sent and received | - |
   | `tls://` address, `secure` unset, `camel.ssl` trust store set | Fails: 
`PKIX path building failed`, the trust store is not used | - |
   | `nats://` address, `secure` unset, `camel.ssl` trust store set | Fails: 
`SSL required by server` | - |
   | `secure: true`, `camel.ssl` trust store without 
`useGlobalSslContextParameters` | Fails: `PKIX path building failed` | - |
   | `secure: true`, `camel.ssl` trust store with another CA | Fails: `PKIX 
path building failed` | - |
   | `secure: true`, wrong trust store password | Fails to start: `keystore 
password was incorrect` | - |
   | `secure: true`, JVM trusts the test CA (`-Djavax.net.ssl.trustStore`), no 
`camel.ssl` | Sent and received | - |
   | JVM trusts the test CA, `camel.ssl` trust store with another CA | Fails: 
the `camel.ssl` trust store replaces the one of Java | - |
   | `secure: true` against a server without TLS | Fails to start: `SSL 
connection wanted by client` | - |
   | Operator server, no credentials (as on `main`) | Fails to start: 
`Authorization Violation` | - |
   | `credentialsFilePath: file:.../app-user.creds` | Sent | Received all 3 |
   | `credentialsFilePath` with the user of an operator the server does not 
know | Fails to start: `Authorization Violation` | - |
   | `credentialsFilePath` as `classpath:` and as `http://` | Sent | - |
   | `credentialsFilePath` to a file that does not exist | Fails to start: 
`FileNotFoundException` | - |
   | `tls://` + `secure` + `camel.ssl` trust store + credentials file, on a 
server with TLS and the resolver | Sent | Received |
   | User and password in the address (as on `main`); a wrong password | Sent 
and received; `Authorization Violation` | Received |
   | Token in the address, `nats://token@host:4222` | Sent | - |
   | Two sources with `queueName: workers`, 20 messages | - | 8 and 12: each 
message received once |
   | Two sources without `queueName` (as on `main`), 20 messages | - | 20 and 
20 |
   | Two JetStream sources with `queueName: workers`, 20 messages | - | 20 and 
20: no sharing with JetStream, as documented |
   | Partial-page examples (`tls://`, `secure`, credentials file, queue group; 
the `camel.ssl` properties of the page), addresses and paths replaced | Sent | 
Received |
   
   `./mvnw clean verify -DskipTests` and `./mvnw clean verify` from the root 
both pass. The generated `kamelets-index.json` and the `library/camel-kamelets` 
copies of the Kamelets were regenerated and are committed; the copies were made 
with `./mvnw -pl library/camel-kamelets 
resources:copy-resources@copy-resource-one`. No Citrus test was added.
   
   _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]

Reply via email to