Kafka 在 kubernetes 上使用 sasl.jaas.config 配置 jaas
Kafka configure jaas using sasl.jaas.config on kubernetes
我正在使用这个 helm 图表:https://github.com/helm/charts/tree/master/incubator/kafka
这些覆盖在 values.yaml
configurationOverrides:
advertised.listeners: |-
EXTERNAL://kafka-${KAFKA_BROKER_ID}.host-removed:$((31090 + ${KAFKA_BROKER_ID}))
listener.security.protocol.map: |-
PLAINTEXT:SASL_PLAINTEXT,EXTERNAL:SASL_PLAINTEXT
sasl.enabled.mechanisms: SCRAM-SHA-256
auto.create.topics.enable: false
inter.broker.listener.name: PLAINTEXT
sasl.mechanism.inter.broker.protocol: SCRAM-SHA-256
listener.name.EXTERNAL.scram-sha-256.sasl.jaas.config: org.apache.kafka.common.security.scram.ScramLoginModule required username="user" password="password";
基于此文档:https://kafka.apache.org/documentation/#security_jaas_broker
(快速摘要)
Brokers may also configure JAAS using the broker configuration property sasl.jaas.config. The property name must be prefixed with the listener prefix including the SASL mechanism, i.e. listener.name.{listenerName}.{saslMechanism}.sasl.jaas.config. Only one login module may be specified in the config value. If multiple mechanisms are configured on a listener, configs must be provided for each mechanism using the listener and mechanism prefix
listener.name.sasl_ssl.scram-sha-256.sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required \
username="admin" \
password="admin-secret";
问题是当我启动 Kafka 时出现以下错误:
java.lang.IllegalArgumentException: Could not find a 'KafkaServer' or 'plaintext.KafkaServer' entry in the JAAS configuration. System property 'java.security.auth.login.config' is not set
根据优先顺序,如果没有设置上面的配置,应该使用静态jass文件。
If JAAS configuration is defined at different levels, the order of precedence used is:
- 代理配置属性 listener.name.{listenerName}.{saslMechanism}.sasl.jaas.config
- {listenerName}.KafkaServer 静态 JAAS 配置部分
- 静态 JAAS 配置的 KafkaServer 部分
helm chart 不支持配置此 jaas 文件的方法,因此使用此 属性 似乎是所需的方法,我只是对配置不正确感到困惑。
注意:如果我禁用所有 SASL 并仅使用纯文本,集群工作正常,但在真实环境中效果不佳。
我们定义了 2 个侦听器:PLAINTEXT
和 EXTERNAL
。您已将两者都映射到 SASL_PLAINTEXT
.
这真的是你想做的吗?还是您希望 PLAINTEXT
不需要 SASL 而只是纯文本?
如果你真的想让两者都是SASL,那么它们都需要一个JAAS配置。在您的问题中,我只看到 EXTERNAL 的 JAAS 配置:
listener.name.EXTERNAL.scram-sha-256.sasl.jaas.config: org.apache.kafka.common.security.scram.ScramLoginModule required username="user" password="password";
由于您已将 PLAINTEXT
映射到 SASL_PLAINTEXT,它还需要 JAAS 配置。您可以指定它,例如:
listener.name.PLAINTEXT.scram-sha-256.sasl.jaas.config: org.apache.kafka.common.security.scram.ScramLoginModule required username="user" password="password";
如果您希望 PLAINTEXT
侦听器实际上是没有 SASL 的纯文本,那么您需要更新侦听器映射:
listener.security.protocol.map: |-
PLAINTEXT:PLAINTEXT,EXTERNAL:SASL_PLAINTEXT
我正在使用这个 helm 图表:https://github.com/helm/charts/tree/master/incubator/kafka
这些覆盖在 values.yaml
configurationOverrides:
advertised.listeners: |-
EXTERNAL://kafka-${KAFKA_BROKER_ID}.host-removed:$((31090 + ${KAFKA_BROKER_ID}))
listener.security.protocol.map: |-
PLAINTEXT:SASL_PLAINTEXT,EXTERNAL:SASL_PLAINTEXT
sasl.enabled.mechanisms: SCRAM-SHA-256
auto.create.topics.enable: false
inter.broker.listener.name: PLAINTEXT
sasl.mechanism.inter.broker.protocol: SCRAM-SHA-256
listener.name.EXTERNAL.scram-sha-256.sasl.jaas.config: org.apache.kafka.common.security.scram.ScramLoginModule required username="user" password="password";
基于此文档:https://kafka.apache.org/documentation/#security_jaas_broker
(快速摘要)
Brokers may also configure JAAS using the broker configuration property sasl.jaas.config. The property name must be prefixed with the listener prefix including the SASL mechanism, i.e. listener.name.{listenerName}.{saslMechanism}.sasl.jaas.config. Only one login module may be specified in the config value. If multiple mechanisms are configured on a listener, configs must be provided for each mechanism using the listener and mechanism prefix
listener.name.sasl_ssl.scram-sha-256.sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required \
username="admin" \
password="admin-secret";
问题是当我启动 Kafka 时出现以下错误:
java.lang.IllegalArgumentException: Could not find a 'KafkaServer' or 'plaintext.KafkaServer' entry in the JAAS configuration. System property 'java.security.auth.login.config' is not set
根据优先顺序,如果没有设置上面的配置,应该使用静态jass文件。
If JAAS configuration is defined at different levels, the order of precedence used is:
- 代理配置属性 listener.name.{listenerName}.{saslMechanism}.sasl.jaas.config
- {listenerName}.KafkaServer 静态 JAAS 配置部分
- 静态 JAAS 配置的 KafkaServer 部分
helm chart 不支持配置此 jaas 文件的方法,因此使用此 属性 似乎是所需的方法,我只是对配置不正确感到困惑。
注意:如果我禁用所有 SASL 并仅使用纯文本,集群工作正常,但在真实环境中效果不佳。
我们定义了 2 个侦听器:PLAINTEXT
和 EXTERNAL
。您已将两者都映射到 SASL_PLAINTEXT
.
这真的是你想做的吗?还是您希望 PLAINTEXT
不需要 SASL 而只是纯文本?
如果你真的想让两者都是SASL,那么它们都需要一个JAAS配置。在您的问题中,我只看到 EXTERNAL 的 JAAS 配置:
listener.name.EXTERNAL.scram-sha-256.sasl.jaas.config: org.apache.kafka.common.security.scram.ScramLoginModule required username="user" password="password";
由于您已将
PLAINTEXT
映射到 SASL_PLAINTEXT,它还需要 JAAS 配置。您可以指定它,例如:listener.name.PLAINTEXT.scram-sha-256.sasl.jaas.config: org.apache.kafka.common.security.scram.ScramLoginModule required username="user" password="password";
如果您希望
PLAINTEXT
侦听器实际上是没有 SASL 的纯文本,那么您需要更新侦听器映射:listener.security.protocol.map: |- PLAINTEXT:PLAINTEXT,EXTERNAL:SASL_PLAINTEXT