You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kafka双向TLS认证下ACL阻止客户端连接的问题求助

Kafka双向TLS+ACL配置后授权失败排查

环境概述

单Broker(kafka-0)POC环境,已完成双向TLS认证配置。无ACL时,持有受信任密钥库/信任库(含自签CA签发证书)的客户端可正常连接并操作主题;所有证书均包含SAN扩展(Kubernetes集群内FQDN),主机名验证无问题。

密钥库与信任库配置

broker:
-------
truststore:
 - CA证书(别名caroot)
keystore:
 - CA证书(别名caroot)
 - Broker密钥对(别名localhost)

client{1/2}:
------------
truststore:
 - CA证书(别名caroot)
keystore:
 - CA证书(别名caroot)
 - Client{1/2}密钥对(别名localhost)

客户端证书DN信息

client1证书:
-------------
所有者: CN=client1,O={company},L={City},ST={State},C={Country}
签发者: CN={自签CA},O={company},L={City},ST={State},C={Country}
// 包含用于主机名验证的FQDN的SAN扩展

client2证书:
-------------
所有者: CN=client2,O={company},L={City},ST={State},C={Country}
签发者: CN={自签CA},O={company},L={City},ST={State},C={Country}
// 包含用于主机名验证的FQDN的SAN扩展

客户端配置与启动命令

无ACL时,客户端可通过kafka-0.kafka-headless.kafka.svc.cluster.local:9092正常连接,客户端配置文件如下:

client.properties:
------------------
client.id=client{1/2}
group.id=client{1/2}-group

security.protocol=SSL
ssl.truststore.type=JKS
ssl.truststore.location=/path/to/truststore
ssl.keystore.type=JKS
ssl.keystore.location=/path/to/keystore
ssl.endpoint.identification.algorithm=https
ssl.truststore.password={password}
ssl.keystore.password={password}
ssl.key.password={password}

生产者启动命令

kafka-console-producer.sh \
  --producer.config /path/to/client.properties \
  --broker-list kafka-0.kafka-headless.kafka.svc.cluster.local:9092 \
  --topic client{1/2}

消费者启动命令

kafka-console-consumer.sh \
  --consumer.config=/path/to/client.properties \
  --bootstrap-server kafka-0.kafka-headless.kafka.svc.cluster.local:9092 \
  --topic client{1/2} \
  --group client{1/2}-group \
  --from-beginning

ACL配置步骤

创建主题

# 创建client1主题
kafka-topics.sh \
  --bootstrap-server localhost:9093 \
  --create \
  --topic client1

# 创建client2主题
kafka-topics.sh \
  --bootstrap-server localhost:9093 \
  --create \
  --topic client2

配置ACL规则

# 配置client1的主题与消费组权限
kafka-acls.sh \
  --bootstrap-server localhost:9093 \
  --add \
  --allow-principal "User:client1" \
  --topic client1 \
  --group client1-group \
  --consumer \
  --producer

# 配置client2的主题与消费组权限
kafka-acls.sh \
  --bootstrap-server localhost:9093 \
  --add \
  --allow-principal "User:client2" \
  --topic client2 \
  --group client2-group \
  --consumer \
  --producer

错误现象

客户端错误日志

WARN [Producer clientId=client1] Error while fetching metadata with correlation id 4 : {client1=TOPIC_AUTHORIZATION_FAILED} (org.apache.kafka.clients.NetworkClient)
ERROR [Producer clientId=client1] Topic authorization failed for topics [client1] (org.apache.kafka.clients.Metadata)
ERROR Error when sending message to topic client1 with key: null, value: 4 bytes with error: (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback) org.apache.kafka.common.errors.TopicAuthorizationException: Not authorized to access topics: [client1]

Broker错误日志

INFO Principal = User: is Denied Operation = Describe from host = {IP} on resource = Topic:LITERAL:client1 for request = Metadata with resourceRefCount = 1 (kafka.authorizer.logger)

疑问与排查方向

已在server.properties中配置使用DefaultKafkaPrincipalBuilder,且日志显示该组件已正常启动,但Broker日志中解析出的Principal为User:(无具体用户名),推测未正确从客户端证书的CN字段提取用户主体,请求协助排查根因。

内容的提问来源于stack exchange,提问作者Matthew

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 00:54:12