Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable SSL for Kafka Clients

Tags:

apache-kafka

Kafka allows clients to connect over SSL. By default SSL is disabled, but I have enabled by referring the below link. http://docs.confluent.io/2.0.0/kafka/ssl.html

After all configuration was done ,Producer/Consumer unable to produce/consume the message.

    [2016-02-29 09:20:49,189] ERROR Error when sending message to topic ssltopic with key: null, value: 2 bytes with error: Failed to update metadata after 60000 ms. (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
sas
[2016-02-29 09:21:16,031] WARN Failed to send SSL Close message  (org.apache.kafka.common.network.SslTransportLayer)
java.io.IOException: Connection reset by peer
like image 484
Mohammed Sahin Iqbal Avatar asked Feb 29 '16 08:02

Mohammed Sahin Iqbal


People also ask

Does Kafka support SSL?

Configuring Kafka Clients. SSL is supported only for the new Kafka Producer and Consumer (Kafka versions 0.9. 0 and higher), the older APIs are not supported. The configs for SSL will be the same for both the producer and consumer.

How does Kafka SSL work?

SSL Overview By default, Apache Kafka sends all data as clear text and without any authentication. First of all, we can configure SSL for encryption between the broker and the client. This, by default, requires one-way authentication using public key encryption where the client authenticates the server certificate.

What is the difference between SASL and SSL?

An obvious difference between SSL and SASL is that SASL allows you to select different mechanisms to authenticate the client while SSL is kind of binded to do authentication based on certificate. In SASL, you can choose to use GSSAPI, Kerberos, NTLM, etc.


1 Answers

The above answer by supermonk clarifies most of the places to check. I faced the similar problem as the OP and the mistake was not in the broker configuration but the client side configuration.
In the official documentation, although they implicitly mentioned to create the client.keystore as step 1, I missed signing the certificate with the CA as done for the server.keystore. This was causing the Kafka broker to refuse the connection from the clients (producer/consumer).

Performing these two steps has eliminated the problem in my case.

keytool -keystore kafka.client.keystore.jks -alias localhost -certreq -file cert-file
openssl x509 -req -CA ca-cert -CAkey ca-key -in cert-file -out cert-signed -days $VALIDITY -CAcreateserial -passin pass:$PASSWORD

keytool -keystore kafka.client.keystore.jks -alias CARoot -import -file ca-cert
keytool -keystore kafka.client.keystore.jks -alias localhost -import -file cert-signed

This will sign the certificate using the CA-cert and add the CARoot as well as signed certificates to the client.keystore.

Reference: Confluent blog on securing Apache Kafka

like image 162
Sai Kiriti Badam Avatar answered Sep 19 '22 10:09

Sai Kiriti Badam