diff --git a/README.md b/README.md index a66970e9..5a973c3d 100644 --- a/README.md +++ b/README.md @@ -36,3 +36,15 @@ schemas before selecting canonical `false`; `true` allows automatic registration Light's own Avro serializer retains its legacy fallback for handwritten old-key configurations, with the canonical key taking precedence. Users relying on that fallback must also migrate their values overrides to retain a `false` setting. + +## Kafka TLS endpoint identification (#265) + +Generated producer, consumer and Streams TLS examples now show `https` for +`ssl.endpoint.identification.algorithm`. The lines remain commented, preserving +Kafka's native hostname-verification default until explicitly enabled. If an +older generated example was uncommented, replace its `algo-name` value or +external override with `https`; `algo-name` is not a valid Java identification +algorithm and fails a TLS handshake. The `kafka-*.ssl.endpoint.identification.algorithm` +keys remain unchanged. An explicitly configured empty string disables hostname +verification; it is not the default. Certificates must match the broker hostname. +The generation regression covers both generators and all eight Kafka flag combinations. diff --git a/light-hybrid-4j/src/main/resources/templates/hybrid/kafkaConsumerYml.rocker.raw b/light-hybrid-4j/src/main/resources/templates/hybrid/kafkaConsumerYml.rocker.raw index 8e810018..5dc1eae7 100644 --- a/light-hybrid-4j/src/main/resources/templates/hybrid/kafkaConsumerYml.rocker.raw +++ b/light-hybrid-4j/src/main/resources/templates/hybrid/kafkaConsumerYml.rocker.raw @@ -23,7 +23,7 @@ properties: # sasl.jaas.config: "org.apache.kafka.common.security.plain.PlainLoginModule required username=\"${kafka-consumer.username:username}\" password=\"${kafka-consumer.password:password}\";" # ssl.truststore.location: ${kafka-consumer.ssl.truststore.location:/truststore/kafka.server.truststore.jks} # ssl.truststore.password: ${kafka-consumer.ssl.truststore.password:changeme} - # ssl.endpoint.identification.algorithm: ${kafka-consumer.ssl.endpoint.identification.algorithm:algo-name} + # ssl.endpoint.identification.algorithm: ${kafka-consumer.ssl.endpoint.identification.algorithm:https} # Apache Kafka 2.3 clients or later will then read from followers that have matching broker.rack as the specified client.rack ID. # client.rack: ${kafka-consumer.client.rack:rack-name} # basic authentication user:pass for the schema registry diff --git a/light-hybrid-4j/src/main/resources/templates/hybrid/kafkaProducerYml.rocker.raw b/light-hybrid-4j/src/main/resources/templates/hybrid/kafkaProducerYml.rocker.raw index bfe5b99c..0824280b 100644 --- a/light-hybrid-4j/src/main/resources/templates/hybrid/kafkaProducerYml.rocker.raw +++ b/light-hybrid-4j/src/main/resources/templates/hybrid/kafkaProducerYml.rocker.raw @@ -36,7 +36,7 @@ properties: # security.protocol: ${kafka-producer.security.protocol:SASL_SSL} # sasl.mechanism: ${kafka-producer.sasl.mechanism:PLAIN} # sasl.jaas.config: "org.apache.kafka.common.security.plain.PlainLoginModule required username=\"${kafka-producer.username:username}\" password=\"${kafka-producer.password:password}\";" - # ssl.endpoint.identification.algorithm: ${kafka-producer.ssl.endpoint.identification.algorithm:algo-name} + # ssl.endpoint.identification.algorithm: ${kafka-producer.ssl.endpoint.identification.algorithm:https} # ssl.truststore.location: ${kafka-producer.ssl.truststore.location:/truststore/kafka.server.truststore.jks} # ssl.truststore.password: ${kafka-producer.ssl.truststore.password:changeme} # client.rack: ${kafka-producer.client.rack:rack-name} diff --git a/light-hybrid-4j/src/main/resources/templates/hybrid/kafkaStreamsYml.rocker.raw b/light-hybrid-4j/src/main/resources/templates/hybrid/kafkaStreamsYml.rocker.raw index bcb0d454..280b0b9f 100644 --- a/light-hybrid-4j/src/main/resources/templates/hybrid/kafkaStreamsYml.rocker.raw +++ b/light-hybrid-4j/src/main/resources/templates/hybrid/kafkaStreamsYml.rocker.raw @@ -20,7 +20,7 @@ properties: # security.protocol: ${kafka-streams.security.protocol:SASL_SSL} # sasl.mechanism: ${kafka-streams.sasl.mechanism:PLAIN} # sasl.jaas.config: "org.apache.kafka.common.security.plain.PlainLoginModule required username=\"${kafka-streams.username:username}\" password=\"${kafka-streams.password:password}\";" - # ssl.endpoint.identification.algorithm: ${kafka-streams.ssl.endpoint.identification.algorithm:algo-name} + # ssl.endpoint.identification.algorithm: ${kafka-streams.ssl.endpoint.identification.algorithm:https} # Apache Kafka 2.3 clients or later will then read from followers that have matching broker.rack as the specified client.rack ID. # client.rack: ${kafka-streams.client.rack:rack-name} # basic authentication user:pass for the schema registry diff --git a/light-hybrid-4j/src/test/java/com/networknt/codegen/hybrid/KafkaSchemaRegistrationGenerationTest.java b/light-hybrid-4j/src/test/java/com/networknt/codegen/hybrid/KafkaSchemaRegistrationGenerationTest.java index 767a3467..1e17dbbf 100644 --- a/light-hybrid-4j/src/test/java/com/networknt/codegen/hybrid/KafkaSchemaRegistrationGenerationTest.java +++ b/light-hybrid-4j/src/test/java/com/networknt/codegen/hybrid/KafkaSchemaRegistrationGenerationTest.java @@ -66,6 +66,15 @@ private void assertConfigsAndValues(Path directory, Set expectedClients) String placeholder = "${" + client + ".auto.register.schemas:true}"; assertTrue(yaml.contains("auto.register.schemas: " + placeholder), path.toString()); assertFalse(yaml.contains("schema.registry.auto.register.schemas"), path.toString()); + String tlsKey = client + ".ssl.endpoint.identification.algorithm"; + String tlsPlaceholder = "${" + tlsKey + ":https}"; + assertTrue(yaml.contains("# ssl.endpoint.identification.algorithm: " + tlsPlaceholder), path.toString()); + assertFalse(yaml.contains(":algo-name}"), path.toString()); + ConfigInjection.setDecryptedValueMap(new HashMap<>()); + assertEquals("https", ConfigInjection.getInjectValue(tlsPlaceholder, true)); + ConfigInjection.setDecryptedValueMap(new HashMap<>(Map.of(tlsKey, ""))); + assertEquals("", ConfigInjection.getInjectValue(tlsPlaceholder, true)); + ConfigInjection.setDecryptedValueMap(new HashMap<>(Map.of(client + ".schema.registry.auto.register.schemas", false))); assertEquals(true, ConfigInjection.getInjectValue(placeholder, true), "Old names require explicit migration"); ConfigInjection.setDecryptedValueMap(new HashMap<>(Map.of(client + ".auto.register.schemas", false)));