I am trying to configure Kafka with SSL using openssl and keytool command. I configured the certificates to accept a specific CN and some alternative names; here is what I did:
openssl req -x509 -nodes -newkey rsa:2048 -days 3650 -sha256 -keyout ca-key -out ca-cert -reqexts SAN -extensions SAN -subj '/CN=kafkabroker' -config <(cat /etc/ssl/openssl.cnf; printf "[SAN]\nsubjectAltName=DNS:kafkabroker,DNS:kafka-broker,DNS:localhost,DNS:host.docker.internal,IP:127.0.0.1,IP:1.1.1.1, IP:2.2.2.2")
keytool -keystore kafka.server.keystore.jks -alias kafkabroker -validity 365 -genkey -storepass passw -keypass passw -ext SAN=DNS:kafkabroker,DNS:localhost,IP:1.1.1.1,DNS:juliet,DNS:host.docker.internal,IP:2.2.2.2,IP:127.0.0.1
keytool -keystore kafka.client.truststore.jks -alias CARoot -import -file ca-cert
keytool -keystore kafka.server.keystore.jks -alias kafkabroker -certreq -file cert-file
openssl x509 -req -CA ca-cert -CAkey ca-key -in cert-file -out cert-signed -days 3650 -CAcreateserial -passin pass:passw
keytool -keystore kafka.server.keystore.jks -alias CARoot -import -file ca-cert
keytool -keystore kafka.server.keystore.jks -alias kafkabroker -import -file cert-signed
keytool -keystore kafka.client.keystore.jks -alias kafkabroker -validity 365 -genkey -storepass passw -keypass passw -ext SAN=DNS:kafkabroker,DNS:localhost,IP:1.1.1.1,DNS:juliet,DNS:host.docker.internal,IP:2.2.2.2,IP:127.0.0.1
keytool -keystore kafka.client.keystore.jks -alias kafkabroker -certreq -file cert-file
openssl x509 -req -CA ca-cert -CAkey ca-key -in cert-file -out cert-signed -days 3650 -CAcreateserial -passin pass:passw
keytool -keystore kafka.client.keystore.jks -alias CARoot -import -file ca-cert
keytool -keystore kafka.client.keystore.jks -alias kafkabroker -import -file cert-signed
keytool -keystore kafka.server.truststore.jks -alias CARoot -import -file ca-cert
In a local environment, having the hostname "kafkabroker" it works but when i run kafka with the same certificates on another environment which has an IP configured during the certificate creation, it says:
java.security.cert.CertificateException: No subject alternative names present
I don't understand why. I checked the jks files which are the truststore and keystore and I can see cleary the section "alternative names" fully populated with the above names and IP addresses.