Skip to main content
双向 TLS(mTLS)对 Kafka 连接的双方进行身份验证。客户端验证 AutoMQ Server Certificate,AutoMQ 验证由可信客户端 CA 签发的 Client Certificate。AutoMQ 将证书身份映射到 Kafka ACL 用户,并执行 ACL 授权。

证书责任

Server Certificate 责任取决于创建实例时选择的 DNS Zone 模式。在两种模式下,用户都需要提供客户端 CA,并为每个客户端身份签发独立的 Client Certificate。
创建实例时需要选择 DNS Zone 模式并启用 mTLS。现有实例不能从未加密 Listener 变更为 mTLS。

配置流程

请按以下顺序完成配置:
  1. 创建或选择 Client CA,并签发 Client Certificate。两种 DNS Zone 模式都必须完成此步骤。
  2. 准备服务端身份。Public DNS Zone 由 AutoMQ 管理;Private DNS Zone 由用户提供。
  3. 配置 AutoMQ 实例。
  4. 配置 Kafka 客户端。

步骤 1:创建 Client CA 和 Client Certificate

两种 DNS Zone 模式都需要 Client CA 和 Client Certificate。优先使用组织的证书管理系统。如果需要自行创建和维护私有 Client CA,可参考以下步骤。
请按照组织的密钥管理要求保护 client-ca.keyclient.key。客户端身份验证只需上传 client-ca.crt,不要上传 Client CA Private Key 或 Client Private Key。用户管理的 Private DNS Zone 还需要上传步骤 3 中说明的服务端材料。

创建 Client CA

创建 client-ca.cnf,执行命令前替换证书主题信息。
生成 Client CA Private Key 和 Client CA Certificate:

签发 Client Certificate

签发 Client Certificate 前,先创建对应的 Kafka ACL 用户。除非配置了其他 Principal Mapping Rule,否则将证书 Common Name(CN)设置为 ACL 用户名。 默认 Principal Mapping Rule 从 Client Certificate 中提取 CN:
例如,包含 CN=user01 的证书映射到 ACL 用户 user01 创建 client.cnf
生成 Client Private Key 和 CSR,然后使用 Client CA 签发 Client Certificate:
检查证书身份、用途和有效期:

步骤 2:准备服务端身份

AutoMQ Managed Public DNS Zone

用户无需执行服务端证书操作。AutoMQ 提供、安装并续期 Server 权威证书。不要创建或上传 Server Certificate 和 Server Private Key。

用户管理的 Private DNS Zone

用户必须提供 Subject Alternative Name(SAN)覆盖 AutoMQ Private DNS Zone 私有接入域名的 Server Certificate。优先使用组织证书颁发机构签发的证书。 以下参考步骤使用步骤 1 创建的 Client CA 签发 Server Certificate。如果组织要求分别使用 Server CA 和 Client CA,请使用 Server CA 签发 Server Certificate,并保留两个 CA 的公共证书,用于步骤 3 的 CA Bundle。 创建 server.cnf。请根据实例接入地址使用准确域名或所需的通配符域名,不要依赖 Common Name 完成主机名验证。
生成 Server Private Key 和 CSR,然后使用 CA 签发 Server Certificate:
检查证书 SAN、用途和有效期:

步骤 3:配置 AutoMQ

AutoMQ Managed Public DNS Zone

  1. 创建实例时选择 Public DNS Zone 和 AutoMQ Managed 模式。
  2. 启用 mTLS Listener。
  3. client-ca.crt 作为 Client CA Certificate 上传。
  4. 不要上传 Server Certificate 或 Server Private Key。
  5. 创建与 Client Certificate 身份匹配的 ACL 用户,并仅授予所需的 Topic 和 Consumer Group 权限。

用户管理的 Private DNS Zone

  1. 创建实例时选择用户管理的 Private DNS Zone,并启用 mTLS Listener。
  2. 上传同时包含 Client CA 和 Server CA 公共证书的 PEM CA Bundle。如果像本示例一样使用同一个 CA 签发两类证书,只需上传一次 client-ca.crt
  3. server.crt 作为 Server Certificate、server.key 作为 Server Private Key 上传。
  4. 创建与 Client Certificate 身份匹配的 ACL 用户,并仅授予所需的 Topic 和 Consumer Group 权限。

步骤 4:配置 Kafka 客户端

将 Client Certificate 和 Client Private Key 转换为 PKCS#12 Keystore:
配置 Kafka 客户端:
使用 AutoMQ Managed Public DNS Zone 时,客户端通常通过操作系统或 Java 运行时信任公共 Server Certificate。除非组织安全策略另有要求,否则无需配置自定义 Server Truststore。 使用用户管理的 Private DNS Zone 且客户端默认不信任 Server CA 时,将 Server CA Certificate 导入客户端 Truststore。在上述单 CA 示例中,使用 client-ca.crt 作为 Server CA Certificate。
在客户端配置中添加 Truststore 参数:

证书过期责任

  • AutoMQ Managed Public DNS Zone: AutoMQ 监控并续期 Server Certificate;用户监控并轮转 Client CA 和所有 Client Certificate。
  • 用户管理的 Private DNS Zone: 用户监控并轮转 Server CA、Server Certificate、Client CA 和 Client Certificate。
服务端通过 kafka_stream_cert_expiry_timestamp_millisecondskafka_stream_cert_days_remaining 暴露已安装 Server Certificate 的有效期。采集方法请参见 Prometheus 监控与告警。Client Certificate 有效期需要纳入用户自己的证书管理流程。