使用 SASL 的 Kafka 身份验证 - 重复的管理员用户?

Kafka Authentication with SASL - duplicate admin user?

我是 运行 分布式 Kafka-Broker,其中代理间通信是使用 SASL/SSL 设置的。为此,我调整了给定的 JAAS 配置 here。完成的文件如下所示:

KafkaServer {
  org.apache.kafka.common.security.plain.PlainLoginModule required
  username="admin"
  password="admin-secret"
  user_admin="admin-secret"
  user_alice="alice-secret"
  security.protocol=SASL_PLAINTEXT
  sasl.mechanism=PLAIN;

  org.apache.kafka.common.security.scram.ScramLoginModule required;
};

Client {
  org.apache.kafka.common.security.plain.PlainLoginModule required
  username="admin"
  password="admin-secret";
};

我注意到“KafkaServer”部分有 2 个管理员用户。我也学到了我需要两者的艰难方式,但这是为什么呢?我感觉几个月前我已经读过(忘记了)原因,但我似乎再也找不到了。

根据 Apache Kafka documentationKafkaServer 部分用于配置身份验证 此代理到其他代理,以及客户端和其他连接 这个经纪人的经纪人。 Client 部分用于连接到 Zookeeper。

由于您的问题是关于 KafkaServer 部分,并且您正在配置 SASL/PLAIN 身份验证机制,请参阅 Apache Kafka 文档的 this part

This configuration defines two users (admin and alice). The properties username and password in the KafkaServer section are used by the broker to initiate connections to other brokers. In this example, admin is the user for inter-broker communication. The set of properties user_userName defines the passwords for all users that connect to the broker and the broker validates all client connections including those from other brokers using these properties.

换句话说,这里配置了两种不同的情况:

  • 当此代理连接到其他代理时 它将使用 usernamepassword 中定义的用户名和密码。
  • 当客户端和其他代理连接到此代理时,user_userName 条目用于验证这些连接,其中用户名是 userName user_userName 密钥的一部分,密码是值。

因此,在您的示例中,由于以下两行,该经纪人将使用用户名 admin 和密码 admin-secret 连接到其他经纪人:

username="admin"
password="admin-secret"

并且,客户和其他经纪人可以使用 admin / admin-secretalice / alice-secret 的用户名密码组合连接到此经纪人,因为这两个行:

user_admin="admin-secret"
user_alice="alice-secret"

如果您只接受来自其他代理的连接以在该侦听器上进行 inter-broker 通信,他们可能正在使用配置的 user_admin="admin-secret" 部分,而 user_alice="alice-secret" 可能是多余的.