Enable SSL for Kafka and Kafka Client Communication
Scripts self-signed certificates and keystores and truststores
1 | keytool -keystore kafka.server.keystore.jks -alias localhost -validity 365 -genkey -dname "CN=broker, OU=kafka" -keypass SuperTrust11 -storepass SuperTrust11 |
Add below configuration to Kafka Config
1 | ssl.keystore.location = /etc/security/certificates/kafka/kafka.server.keystore.jks |
Test one way SSL (Default)
Java Client connect to Kafka via SSL
1 | //configure the following three settings for SSL Encryption |
Command Line Client connect to Kafka server via SSL
https://docs.hortonworks.com/HDPDocuments/HDP2/HDP-2.6.1/bk_security/content/ch_wire-kafka.html
Change the producer.properties and consumer.properties file based on default under /usr/hdf/current/kafka-broker/conf, add below lines to each of the file,
1 | security.protocol=SSL |
Then trigger the producer using,
1 | /usr/hdf/current/kafka-broker/bin/kafka-console-producer.sh --broker-list broker1:6668,broker2:6668 --topic testtopic --producer.config /usr/hdf/current/kafka-broker/conf/producer.properties --security-protocol SSL |
Trigger the Consumer using,
1 | /usr/hdf/current/kafka-broker/bin/kafka-console-consumer.sh \ |
Enable Two way ssl
If we want to enable two way SSL then,
- “ssl.client.auth=required” should be added to the broker setting.
- Server should already import client cert (already done when generating the keystore and truststores)
Connect from command line
Add both keystore and trust store to the producer and consumer property files.
1 | security.protocol=SSL |
And used the same command line with one way SSL, we can consume and produce messages without issue.