【问题标题】:Kafka authorization failed only on port 9092Kafka 授权仅在端口 9092 上失败
【发布时间】:2021-10-08 07:53:16
【问题描述】:

我使用 confluent kafka docker 镜像,并通过以下配置启用了身份验证和授权。 KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://:9092,SASL_SSL://:9093

=> 9093 SASL_SSL
=> 9092 明文

这是我的配置的一部分:
容器环境变量

  - KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND=false
  - KAFKA_SSL_CLIENT_AUTH=required
  - KAFKA_SECURITY_INTER_BROKER_PROTOCOL=SASL_SSL
  - KAFKA_SASL_MECHANISM_INTER_BROKER_PROTOCOL=PLAIN
  - KAFKA_SASL_ENABLED_MECHANISMS=PLAIN
  - KAFKA_AUTHORIZER_CLASS_NAME=kafka.security.authorizer.AclAuthorizer
  - KAFKA_SUPER_USERS="User:admin"
  - KAFKA_OPTS=-Djava.security.auth.login.config={{ kafka_secrets_dir }}/kafka_jaas.conf

kafka_jaas.conf

KafkaServer {
org.apache.kafka.common.security.plain.PlainLoginModule required
  username="admin"
  password="admin"
  user_admin="admin"
  user_second_user="read_user";
};

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

配置消费者 ACL

bin/kafka-acls --authorizer-properties zookeeper.connect=my.host1:2181,host2:2181,host3:2181 --add --allow-principal User:second_user --consumer --topic '*' --group '*'

配置生产者 ACL

kafka-acls --authorizer-properties zookeeper.connect=my.host1:2181,host2:2181,host3:2181 --add --allow-principal User:second_user --producer --topic '*'

我想在两个端口上使用 kafka。 9093 具有 SSL 加密和 9092 没有。因此我用一个简单的控制台消费者/生产者对其进行了测试。端口 9093 工作正常,我可以消费和产生消息。问题是它在端口 9092 上不起作用。我总是收到身份验证错误TopicAuthorizationException: Not authorized to access topics: [test_topic]。我使用“second_user”甚至超级用户“admin”对其进行了测试。为什么它只适用于安全端口?我错过了任何配置吗?

控制台通过端口 9093 消费(工作)

#consumer.properties

ssl.endpoint.identification.algorithm=
ssl.enabled.protocols=TLSv1.2,TLSv1.1,TLSv1
ssl.truststore.location=/home/vagrant/kafka-2.8.0/ssl/kafka.truststore.jks
ssl.truststore.password=changeme
ssl.protocol=TLS
security.protocol=SASL_SSL
sasl.mechanism=PLAIN
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required \
    username="admin" \
    password="admin";


# create consumer => This is working!
/bin/kafka-console-consumer.sh --bootstrap-server host1:9093,host2:9093,host3:9093 --topic test_topic --from-beginning --consumer.config consumer.properties

控制台通过端口 9092 消费(不工作

#consumer.properties
security.protocol=PLAINTEXT
sasl.mechanism=PLAIN
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required \
    username="admin" \
    password="admin";

#create consumer
kafka-console-consumer.sh --bootstrap-server host1:9092,host2:9092,host3:9092 --topic test_topic --from-beginning --consumer.config consumer.properties

=>TopicAuthorizationException: Not authorized to access topics: [test_topic]

我还使用 python 和 confluent-kafka-python 包对其进行了测试(不工作)。
test.py

self.consumer = Consumer({
            'bootstrap.servers': "host1:9092,host2:9092,host3:9092",
            'group.id': f"test",
            'security.protocol': "PLAINTEXT",
            'sasl.mechanism': 'PLAIN',
            'sasl.username': 'admin',
            'sasl.password': "admin"
        })
=> FindCoordinator response error: Group authorization failed

【问题讨论】:

    标签: apache-kafka acl


    【解决方案1】:

    您没有在端口 9092 上启用身份验证,

    结合 KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND

    ,您遇到授权失败,

    要修复它,您应该更改为 SASL_PLAINTEXT 以允许在没有 TLS 加密的情况下进行 SASL 身份验证

    PLAINTEXT://:9092 -> SASL_PLAINTEXT://:9092

    【讨论】:

      猜你喜欢
      • 2021-10-09
      • 2016-08-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-15
      • 2020-04-03
      • 2021-06-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多