1) Build the Apache Sentry distribution
First we will build and install the Apache Sentry distribution. Download Apache Sentry (1.7.0 was used for the purposes of this tutorial). Verify that the signature is valid and that the message digests match. Now extract and build the source and copy the distribution to a location where you wish to install it:
- tar zxvf apache-sentry-1.7.0-src.tar.gz
- cd apache-sentry-1.7.0-src
- mvn clean install -DskipTests
- cp -r sentry-dist/target/apache-sentry-1.7.0-bin ${sentry.home}
2) Configure authorization in the broker
Configure Apache Kafka as per the first tutorial. 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.file.SimpleFileProviderBackend</value> | |
</property> | |
<property> | |
<name>sentry.kafka.provider.resource</name> | |
<value>file:/home/colm/dist/apache/kafka_2.11-0.10.0.1/config/sentry.ini</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
[groups] | |
admin = admin_role | |
producer = describe_role, read_role, write_role | |
consumer = describe_role, read_role, describe_consumer_group_role, read_consumer_group_role | |
[roles] | |
admin_role = Host=*->Cluster=kafka-cluster->action=ALL | |
describe_role = Host=*->Topic=test->action=describe | |
read_role = Host=*->Topic=test->action=read | |
write_role = Host=*->Topic=test->action=write | |
describe_consumer_group_role = Host=*->ConsumerGroup=test-consumer-group->action=describe | |
read_consumer_group_role = Host=*->ConsumerGroup=test-consumer-group->action=read | |
[users] | |
Broker = admin | |
Service = producer | |
Client = consumer |
- bin/kafka-server-start.sh config/server.properties
Now lets test the authorization logic. Start the producer:
- 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