简体   繁体   English

Kafka制作人/ consuper主题未经授权

[英]Kafka producer/consuper Topic not authorized

Whenever I try to connect to kafka to producer/consume I get "Not authorized for topics [test2]" 每当我尝试将kafka连接到生产者/消费者时,都会收到“未经授权的主题[test2]”

If I turn off the authorization I get authenticated successfully, so the authentication works and only the authorization doesn't. 如果我关闭授权,则可以成功通过身份验证,因此身份验证有效,只有授权不起作用。

ACL authorization with kafka.security.auth.SimpleAclAuthorizer not working. 使用kafka.security.auth.SimpleAclAuthorizer的ACL授权不起作用。

config/server.properties config / server.properties

authorizer.class.name=kafka.security.auth.SimpleAclAuthorizer
listeners=SASL_PLAINTEXT://kafka3:9092
security.inter.broker.protocol= SASL_PLAINTEXT
sasl.mechanism.inter.broker.protocol=PLAIN
sasl.enabled.mechanisms=PLAIN
delete.topic.enable=false

logs/kafka-authorizer 日志/ kafka授权者

[2019-04-06 13:24:05,693] DEBUG No acl found for resource Topic:LITERAL:test2, authorized = false (kafka.authorizer.logger) [2019-04-06 13:24:05,695] INFO Principal = User:alice is Denied Operation = Describe from host = 10.0.9.20 on resource = Topic:LITERAL:test2(kafka.authorizer.logger)uper.users=User:admin

server's jaas file: 服务器的jaas文件:

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

bin/kafka-server-start.sh bin / kafka-server-start.sh

$base_dir/kafka-run-class.sh $EXTRA_ARGS -Djava.security.auth.login.config=$base_dir/../config/jaas-kafka-server.conf kafka.Kafka "$@"

acl output: ACL输出:

Current ACLs for resource `Topic:LITERAL:test2`:
    User:alice has Allow permission for operations: Write from hosts: *

User alice is currently only authorized to Write to that topic. 用户alice当前仅被授权Write该主题。 You would also likely want to add the ACLs Describe and Read to be able to properly produce and consume to your existing topic. 您可能还希望添加“ DescribeRead ” ACL,以便能够正确地产生和使用现有主题。

The kafka-acls tool provides convenience options --consumer and --producer when adding ACLs to a topic. 在将ACL添加到主题时, kafka-acls工具提供了方便的选项--consumer--producer Otherwise, you can use --operation to add specific operations such as Describe . 否则,您可以使用--operation添加诸如Describe特定操作。 By adding Describe , you'd remove the log you're currently seeing in logs/kafka-authorizer . 通过添加Describe ,您将删除在logs/kafka-authorizer当前看到的logs/kafka-authorizer

As you would like consume and produce message from a particular topic with turning on ACL, then you need to apply ACL on the topic to consume and produce message to it. 由于您希望通过打开ACL来消费和产生来自特定主题的消息,因此您需要在该主题上应用ACL来消费和产生对其的消息。 You need to do it through a super user like kafka. 您需要通过像kafka这样的超级用户来执行此操作。

Login to a kafka broker then use below command : 登录到kafka经纪人,然后使用以下命令:

sudo su - kafka 苏多苏-卡夫卡

kinit -kt /path/to/keytabs/kafka.service.keytab kafka/serviceprincipal name@domain name (you can get it from kafka jaas file) kinit -kt /path/to/keytabs/kafka.service.keytab kafka / serviceprincipal name @域名(可以从kafka jaas文件中获取)

Then from kafka directory execute these command : 然后从kafka目录执行以下命令:

bin/kafka-acls --add --allow-principal User:* --consumer --topic test2 --authorizer-properties zookeeper.connect=:2181 --group * bin / kafka-acls --add --allow-principal用户:* --consumer --topic test2 --authorizer-properties zookeeper.connect =:2181 --group *

Similarly for producer to push message to topics : 同样,制作人可以将消息推送到主题:

bin/kafka-acls.sh --add --allow-principal User:* --producer --topic test2 --authorizer-properties zookeeper.connect=:2181 bin / kafka-acls.sh --add --allow-principal用户:* --producer --topic test2 --authorizer-properties zookeeper.connect =:2181

Above command will apply ACLs to all users . 上面的命令将ACL应用于所有用户。 You can restrict it by specifying individual user name instead of '*' in the command. 您可以通过在命令中指定单个用户名而不是'*'来限制它。

** Remember you should not have any text file or any other file other than kafka installed file/directory in the bin directory as part of kafka installation. **请记住,在kafka安装过程中,bin目录中除kafka安装的文件/目录外,您不应有任何文本文件或其他文件。

To get more info on ACL(addind/removing,listing) go to below link: 要获取有关ACL(添加/删除,列出)的更多信息,请访问以下链接:

https://docs.confluent.io/current/kafka/authorization.html https://docs.confluent.io/current/kafka/authorization.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM