Securing data in motion for Apache Kafka
You must create a secure key and keystore to be able to encrypt and decrypt messages with Apache Kafka.
Procedure
- Log on to the computer where Apache Kafka is installed as the root user.
- Create a key and a keystore for each Kafka broker.
keytool -genkey -alias SIKafkaServerSSL -validity 365 -keystore SIKafkaServerSSLKeystore.jks -dname "CN=si.ibm.com,O=IBM,OU=IBMAnalytics,L=IN,ST=ON,C=CA" -keypass YourKeyPassword - When prompted, enter a password for the key. For example, enter sifs123.
-
Export the certificate from the keystore.
keytool -certreq -file SIKafkaCert -alias SIKafkaServerSSL -keystore SIKafkaServerSSLKeystore.jks - When prompted, enter the password that you used. For example, enter
sifs123. Note: The certificate must be signed by a certificate authority.
- Generate the certificate authority key.
openssl req -new -x509 -keyout ca-key -out ca-cert -days 365Follow the prompts to generate the key.
- Add the key to the server truststore.
keytool -import -file ca-cert -keystore SIKafkaServerSSLKeystore.jks -alias CARootThe truststore is automatically created.
- Add the key to the server keystore.
keytool -import -file ca-cert -keystore SIKafkaServerSSLKeystore.jks -alias CARoot - Sign the certificate:
openssl x509 -req -CA ca-cert -CAkey ca-key -in SIKafkaCert -out SIKafkaCertSigned -days 365 -CAcreateserial -passin pass:YourPassword - Import the signed certificate into the server keystore:
keytool -import -file SIKafkaCertSigned -keystore SIKafkaServerSSLKeystore.jks -alias SIKafkaServerSSL - Update the KafkaInstallLocation/config/server.properties file to
include the following text:
listeners=SSL://<IP>:<Port> advertised.listeners=SSL://<IP>:<Port> ssl.keystore.location=/home/SIUser/SIKafkaServerSSLKeystore.jks ssl.keystore.password=YourPassword ssl.key.password= YourKeyPassword ssl.truststore.location=/home/SIUser/SIKafkaServerSSLTruststore.jks ssl.truststore.password=YourPassword ssl.client.auth=required security.inter.broker.protocol=SSLWhere
<IP>is the IP address where Kafka is running and<Port>can be any open port number, such as 2182. - Copy the SIKafkaServerSSLKeystore.jks and
SIKafkaServerSSLTruststore.jks files to the
/home/streamsadmin/security directory Note: Ensure that the streamsadmin user has access to this file.