How to do client authentication with Kafka

How to do client authentication with Kafka
Written by Abhishek JalanApril 25, 2020
3 min read
Kafka
6 VIEWS 1 LIKES 0 DISLIKES SHARE
1 LIKES 0 DISLIKES 6 VIEWS SHARE
Abhishek Jalan

DevSecOps Engineer

In this blog, we will learn how to expose our Kafka brokers so that external clients can communicate with them.

Scenario:
Suppose there is a requirement to expose your Kafka brokers so that external clients can communicate with them.
So here we will be implementing authentication with client certificates in an existing Kafka cluster, and then authenticate as a client to verify that your implementation works.

Generate Your Client Certificate Files

Generate a client certificate. Choose a password for the client keystore when prompted:

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"

Sign the key, then import the certificate authority and signed key into the 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

Move the client keystore into an appropriate location:

sudo cp client.keystore.jks /var/private/ssl/
sudo chown root:root /var/private/ssl/client.keystore.jks

Enable Client Authentication for the Broker

Set client authentication to required in server.properties:

sudo vi /etc/kafka/server.properties

Locate the line that begins with ssl.client.auth and change it:

ssl.client.auth=required

Restart Kafka and then verify that everything is working:

sudo systemctl restart confluent-kafka
sudo systemctl status confluent-kafka

Add Client Authentication Settings to Your Client Config File

Edit client-ssl.properties:

cd ~/
vi client-ssl.properties

Add the following lines:

ssl.keystore.location=/var/private/ssl/client.keystore.jks
ssl.keystore.password=<your client keystore password>
ssl.key.password=<your client key password>

Create a console consumer using client authentication to make verify that everything is working:

kafka-console-consumer --bootstrap-server zoo1:9093 --topic inventory_purchases --from-beginning --consumer.config client-ssl.properties

kafka
kafka-authentication
6 VIEWS 1 LIKES 0 DISLIKES SHARE
1 LIKES 0 DISLIKES 6 VIEWS SHARE
Was this blog helpful?
You must be Logged in to comment
Code Block
Abhishek Jalan
DevSecOps Engineer
+21 more
17 Blog Posts
4 Discussion Threads
Trending Categories
93
Software12
DevOps34
Frontend Development13
Backend Development13
Server Administration13
Linux Administration12
Data Center14
Sentry11
Terraform15
Ansible9
Docker13
Penetration Testing12
Kubernetes12
NGINX8
JenkinsX10
Jenkins18
SSL6
Ethical-Hacking10
Python8
NodeJs9
RedHat8
Github11
AngularJs15
Google Cloud Platform (GCP)6
SonarQube9
Amazon Web Service (AWS)2
VMware17
Blockchain6
Snipe-IT7