问题描述
我正在尝试使用openssl和keytool命令使用SSL配置Kafka.我将证书配置为接受特定的CN和一些备用名称.这是我所做的:
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
在本地环境中,它具有主机名"kafkabroker",但是当我在具有在证书创建过程中配置的IP的另一个环境中运行具有相同证书的kafka时,它说:
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:
我不明白为什么.我检查了作为信任库和密钥库的jks文件,可以清楚地看到替代名称"部分已完全填充了上述名称和IP地址.
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.
推荐答案
主要问题在于,kafka需要在签名的SERVER证书(位于server.keystore.jks中)中使用SAN.如我所见,在您的请求部分中,您没有添加SAN名称:
The main problem, that kafka requires SAN in signed SERVER certificate (which is in server.keystore.jks). As I can see, in your request section you do not have SAN names added:
openssl x509 -req -CA ca-cert -CAkey ca-key -in cert-file -out cert-signed -days 3650 -CAcreateserial -passin pass:passw -extfile openssl-sign.cnf -extensions server_cert
准备添加/编辑/etc/pki/tls/openssl.cnf(CentOS/RHEL目录)或/etc/ssl/openssl.cnf(其他)-server_cert(或类似)部分.另一种方法是创建自己的openssl.cnf副本,如我的示例所示(文件openssl-sigh.cnf).server_cert部分可以是这样的(在cnf文件中的任何地方):
Be ready to add/edit your /etc/pki/tls/openssl.cnf (CentOS/RHEL catalog) or /etc/ssl/openssl.cnf (others) - server_cert (or analogue) section. Another way is to create your own copy of openssl.cnf as shown in my example (file openssl-sigh.cnf).server_cert section can be something like this (anywhere in cnf file):
[ server_cert ]
# Extensions for server certificates (`man x509v3_config`).
basicConstraints = CA:FALSE
nsCertType = server
nsComment = "Openssl Server generated Certificate"
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer:always
keyUsage = critical, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth,clientAuth
subjectAltName = 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
然后通过以下方法检查结果:
Then check your results by:
openssl req -text -noout -verify -in cert-file
openssl x509 -text -noout -in cert-signed
并且您应该在x509扩展名中看到SAN文本行.
And you should see SAN text lines in x509 extensions.
我不确定client.keystore-您用另一个具有相同名称的证书创建另一对.尝试先进行server.keystore.jks检查.
I'm not sure about the client.keystore - you create another pair with another certs with the same names. Try first server.keystore.jks check.
这篇关于X509 SSL:没有与< hostname>匹配的名称;成立的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!