1) Configure authorization in the broker
Firstly download and configure Apache Kafka using SSL as per this tutorial, except use Kafka 0.11.0.2. To enable authorization using Apache Sentry we also need to follow these steps. First edit 'config/server.properties' and add:
- authorizer.class.name=org.apache.sentry.kafka.authorizer.SentryKafkaAuthorizer
- sentry.kafka.site.url=file:./config/sentry-site.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?> | |
<configuration> | |
<property> | |
<name>sentry.service.security.mode</name> | |
<value>none</value> | |
</property> | |
<property> | |
<name>sentry.kafka.provider</name> | |
<value>org.apache.sentry.provider.file.LocalGroupResourceAuthorizationProvider</value> | |
</property> | |
<property> | |
<name>sentry.kafka.provider.backend</name> | |
<value>org.apache.sentry.provider.db.generic.SentryGenericProviderBackend</value> | |
</property> | |
<property> | |
<name>sentry.kafka.provider.resource</name> | |
<value>file:/home/colm/dist/apache/kafka_2.11-0.11.0.2/config/sentry.ini</value> | |
</property> | |
<property> | |
<name>sentry.service.client.server.rpc-addresses</name> | |
<value>0.0.0.0</value> | |
</property> | |
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[users] | |
Broker = admin | |
Service = producer | |
Client = consumer |
2) Configure the Apache Sentry security service
Follow the first tutorial to install the Apache Sentry security service. Now we need to create the authorization privileges for our Apache Kafka test scenario as per the second tutorial. Start the 'sentryCli" in the Apache Sentry distribution.
Create the roles:
- t kafka
- cr admin_role
- cr describe_role
- cr read_role
- cr write_role
- cr describe_consumer_group_role
- cr read_consumer_group_role
- gp admin_role "Host=*->Cluster=kafka-cluster->action=ALL"
- gp describe_role "Host=*->Topic=test->action=describe"
- gp read_role "Host=*->Topic=test->action=read"
- gp write_role "Host=*->Topic=test->action=write"
- gp describe_consumer_group_role "Host=*->ConsumerGroup=test-consumer-group->action=describe"
- gp read_consumer_group_role "Host=*->ConsumerGroup=test-consumer-group->action=read"
- gr admin_role admin
- gr describe_role producer
- gr read_role producer
- gr write_role producer
- gr read_role consumer
- gr describe_role consumer
- gr describe_consumer_group_role consumer
- gr read_consumer_group_role consumer
Now start the broker (after starting Zookeeper):
- bin/kafka-server-start.sh config/server.properties
- bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test --producer.config config/producer.properties
- bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning --consumer.config config/consumer.properties --new-consumer