Giter Club home page Giter Club logo

kafka-tls-support-with-akka's Introduction

kafka-tls-support-with-akka

This repository contains the steps to enable TLS for Kafka and an example Scala application which demonstrates the TLS connection from Producer and Consumer.

Enable TLS for Kafka

All these steps are summarization of the official Kafka documentation that you can find here.

  • Create keypair for our CA

    openssl req -new -x509 -keyout ca-key -out ca-cert -days 9999

    This will create ca-cert and ca-key files which we will use at further steps.

  • Generate SSL key and certificate for each Kafka broker First we need to create a truststore using java keytool and we need to import our ca-cert into it.

    keytool -keystore kafka.broker0.truststore.jks -alias ca-cert -import -file ca-cert

    Then we need to create a keystore.

    keytool -keystore kafka.broker0.keystore.jks -alias broker0 -validity 9999 -genkey -keyalg RSA -ext SAN=dns:localhost

    Here, at this point it is important to set Subject Alternative Name (SAN) as your host DNS to prevent some Host Name Verification error. Also, when we run this command, it will ask us What is your first and last name? which represent the Common Name (CN). We need to set this property as we set in SAN value. The other approach to prevent Host Name Verification error is setting ssl.endpoint.identification.algorithm field as an empty string inside server.properties file.

    ssl.endpoint.identification.algorithm=
    

    Now, let's create our certificate signing request and sign it.

    keytool -keystore kafka.broker0.keystore.jks -alias broker0 -certreq -file ca-request-broker0
    openssl x509 -req -CA ca-cert -CAkey ca-key -in ca-request-broker0 -out ca-signed-broker0 -days 9999 -CAcreateserial

    For the last step, import the signed certificate and CA into keystore.

    keytool -keystore kafka.consumer.keystore.jks -alias ca-cert -import -file ca-cert
    keytool -keystore kafka.consumer.keystore.jks -alias consumer -import -file ca-signed-consumer



  • Configuring Kafka Brokers

    • Inside the server.properties file we need to add following configurations.

      ssl.client.auth=required
      ssl.keystore.location=<PATH_TO_kafka.broker0.keystore.jks> //for the example application it is under resources folder.
      ssl.keystore.password=<keystore_password> //for the example application it is 123456
      ssl.key.password=<key_password> //for the example application it is 123456
      ssl.truststore.location=<PATH_TO_kafka.broker0.truststore.jks> //for the example application it is under resources folder.
      ssl.truststore.password=<truststore_password> //for the example application it is 123456
      ssl.protocol=TLSv1.2
      
    • Also we need to change listeners and listener.security.protocol.map properties as follow:

      listeners=PLAINTEXT://localhost:9092,SSL://localhost:9093 // to complitely disable not secured way you can delete `PLAINTEXT://localhost:9092` part.
      listener.security.protocol.map=PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL
      

      And run the broker with the server.properties configuration.

  • Configuring Kafka Clients

    • See the example project. In the application we created different keystores and truststores following the above steps for each client(Producer and Consumer)

kafka-tls-support-with-akka's People

Contributors

dagdelenmustafa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.