【问题标题】:Using apache kafka in SSL mode在 SSL 模式下使用 apache kafka
【发布时间】:2017-07-05 17:23:55
【问题描述】:

我正在尝试在 SSL [1-way] 模式下设置 kafka。我已经浏览了官方文档并成功生成了证书。我会记下两种不同情况的行为。此设置只有一个代理和一个动物园管理员。

案例 1:代理间通信 - 明文

我的server.properties文件中的相关条目如下:

listeners=PLAINTEXT://localhost:9092, SSL://localhost:9093
ssl.keystore.location=/Users/xyz/home/ssl/server.keystore.jks
ssl.keystore.password=****
ssl.key.password=****

我在 kafka 配置目录中添加了一个 client-ssl.properties,其中包含以下条目:

security.protocol=SSL
ssl.truststore.location=/Users/xyz/home/ssl/client.truststore.jks
ssl.truststore.password=****

如果我将bootstrap.servers=localhost:9093bootstrap.servers=localhost:9092 放在我的config/producer.properties 文件中,我的控制台生产者/消费者工作正常。这是预期的行为吗?如果是,那为什么?因为我专门尝试在 SSL 模式下从生产者/消费者连接到 localhost:9093

案例 2:代理间通信 - SSL

我的server.properties文件中的相关条目如下:

security.inter.broker.protocol=SSL
listeners=SSL://localhost:9093
ssl.keystore.location=/Users/xyz/home/ssl/server.keystore.jks
ssl.keystore.password=****
ssl.key.password=****

我的client-ssl.properties 文件保持不变。我将bootstrap.servers=localhost:9093 放入producer.properties 文件中。现在,我的生产者/消费者都无法连接到 kafka。我收到以下消息:

WARN Error while fetching metadata with correlation id 0 : {test=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)

我做错了什么?

在所有这些情况下,我都使用以下命令来启动生产者/消费者:

./kafka-console-producer.sh --broker-list localhost:9093 --topic test --producer.config ../config/client-ssl.properties
./kafka-console-consumer.sh --bootstrap-server localhost:9093 --topic test --consumer.config ../config/client-ssl.properties

【问题讨论】:

    标签: ssl apache-kafka


    【解决方案1】:

    确保证书中的通用名称 (CN) 与您的主机名匹配。 SSL 协议根据主机名验证 CN。我猜这里你应该有 CN=localhost。 我有一个类似的问题,这就是我解决它的方法。

    【讨论】:

    • 如果 CN 错误,我应该无法在 SSL 模式下使用 PLAINTEXT 中的 security.inter.broker.protocol 进行连接,对吧?
    • 好吧,我可以在 SSL 模式下使用纯文本代理间协议进行连接。看起来只有在 security.inter.broker.protocol=SSL 时才针对主机名检查 CN
    • 最近我不得不为我当前的项目重复相同的东西,我从@Venkateswararao T 的answer 中发现,当它要求你提供名字和姓氏时,它必须是localhost。我使用了来自 here 的 ssl 生成器
    【解决方案2】:

    关于此的一个重要信息:可以通过在 server.properties 中添加以下行来停用 CN 必须等于主机名的行为:

        ssl.endpoint.identification.algorithm=
    

    此设置的默认值设置为https,最终激活主机到CN验证。这是自 Kafka 2.0 以来的默认设置。

    我已经成功测试了具有以下属性的 SSL 设置(尽管只是在代理端):

        ############################ SSL Config #################################
        ssl.truststore.location=/path/to/kafka.truststore.jks
        ssl.truststore.password=TrustStorePassword
        ssl.keystore.location=/path/to/kafka.server.keystore.jks
        ssl.keystore.password=KeyStorePassword
        ssl.key.password=PrivateKeyPassword
        security.inter.broker.protocol=SSL
        listeners=SSL://localhost:9093
        advertised.listeners=SSL://127.0.0.1:9093
        ssl.client.auth=required
        ssl.endpoint.identification.algorithm=
    

    您还可以在此 github 项目中找到用于生成 SSL 证书(带有密钥和信任库)以及一些文档的 Shell 脚本:https://github.com/confluentinc/confluent-platform-security-tools

    【讨论】:

      【解决方案3】:

      嗯,两个给定的答案都指出了正确的方向,但需要添加更多细节来结束这种混乱。

      我使用这个来自 confluent 的 bash script 生成了证书,当我查看文件内部时,它是有道理的。我在此处粘贴相关部分:

      echo "     NOTE: currently in Kafka, the Common Name (CN) does not need to be the FQDN of"
      echo "     this host. However, at some point, this may change. As such, make the CN"
      echo "     the FQDN. Some operating systems call the CN prompt 'first / last name'"
      

      你去。生成证书时,请确保在要求输入名字/姓氏时输入 localhost(或 FQDN)。请记住,您需要使用相同的端点来公开代理。

      【讨论】:

        猜你喜欢
        • 2022-12-05
        • 1970-01-01
        • 2021-11-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-10
        • 1970-01-01
        • 1970-01-01
        • 2021-12-24
        相关资源
        最近更新 更多