Using Client Authentication with Kafka
If you want to expose your Kafka brokers so that external clients can communicate with them, it is important to make sure that your implementation is secure. In some situations, this means implementing client authentication. In this lab, you will have the opportunity to work hands-on with one of the client authentication methods available in Kafka: client certificates. You will implement authentication with client certificates in an existing cluster, and then authenticate as a client to verify that your implementation works. This will give you hands-on experience with the process of securing a Kafka cluster.
Challenge
Generate Your Client Certificate Files
cd ~/certs/
keytool -keystore client.keystore.jks -alias kafkauser -validity 365 -genkey -keyalg RSA -dname "CN=kafkauser, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown"
keystore. When asked for the password to the ca-key, enter the password AllTheKeys:
keytool -keystore client.keystore.jks -alias kafkauser -certreq -file client-cert-file
openssl x509 -req -CA ca-cert -CAkey ca-key -in client-cert-file -out client-cert-signed -days 365 -CAcreateserial
keytool -keystore client.keystore.jks -alias CARoot -import -file ca-cert
keytool -keystore client.keystore.jks -alias kafkauser -import -file client-cert-signed
sudo cp client.keystore.jks /var/private/ssl/
sudo chown root:root /var/private/ssl/client.keystore.jks
Challenge
Enable Client Authentication for the Broker
required in server.properties:
sudo vi /etc/kafka/server.properties
ssl.client.auth and change it:
ssl.client.auth=required
sudo systemctl restart confluent-kafka
sudo systemctl status confluent-kafka
Challenge
Add Client Authentication Settings to Your Client Config File
client-ssl.properties:
cd ~/
vi client-ssl.properties
ssl.keystore.location=/var/private/ssl/client.keystore.jks
ssl.keystore.password=<your client keystore password>
ssl.key.password=<your client key password>
kafka-console-consumer --bootstrap-server zoo1:9093 --topic inventory_purchases --from-beginning --consumer.config client-ssl.properties