1) Set up a KDC using Apache Kerby
A github project that uses Apache Kerby to start up a KDC is available here:
- bigdata-kerberos-deployment: This project contains some tests which can be used to test kerberos with various big data deployments, such as Apache Hadoop etc.
- zookeeper/localhost@kafka.apache.org
- kafka/localhost@kafka.apache.org
- client@kafka.apache.org
2) Configure Apache Zookeeper
Download Apache Kafka and extract it (0.10.2.1 was used for the purposes of this tutorial). Edit 'config/zookeeper.properties' and add the following properties:
- authProvider.1=org.apache.zookeeper.server.auth.SASLAuthenticationProvider
- requireClientAuthScheme=sasl
- jaasLoginRenew=3600000
Server {
com.sun.security.auth.module.Krb5LoginModule required refreshKrb5Config=true useKeyTab=true keyTab="/path.to.kerby.project/target/zookeeper.keytab" storeKey=true principal="zookeeper/localhost";
};
Before launching Zookeeper, we need to point to the JAAS configuration file above and also to the krb5.conf file generated in the Kerby test-case above. This can be done by setting the "KAFKA_OPTS" system property with the JVM arguments:
- -Djava.security.auth.login.config=/path.to.zookeeper/config/zookeeper.jaas
- -Djava.security.krb5.conf=/path.to.kerby.project/target/krb5.conf
- bin/zookeeper-server-start.sh config/zookeeper.properties
Create 'config/kafka.jaas' with the content:
KafkaServer {
com.sun.security.auth.module.Krb5LoginModule required refreshKrb5Config=true useKeyTab=true keyTab="/path.to.kerby.project/target/kafka.keytab" storeKey=true principal="kafka/localhost";
};
Client {
com.sun.security.auth.module.Krb5LoginModule required refreshKrb5Config=true useKeyTab=true keyTab="/path.to.kerby.project/target/kafka.keytab" storeKey=true principal="kafka/localhost";
};
The "Client" section is used to talk to Zookeeper. Now edit 'config/server.properties' and add the following properties:
- listeners=SASL_PLAINTEXT://localhost:9092
- security.inter.broker.protocol=SASL_PLAINTEXT
- sasl.mechanism.inter.broker.protocol=GSSAPI
- sasl.enabled.mechanisms=GSSAPI
- sasl.kerberos.service.name=kafka
- -Djava.security.auth.login.config=/path.to.kafka/config/kafka.jaas
- -Djava.security.krb5.conf=/path.to.kerby.project/target/krb5.conf
- bin/kafka-server-start.sh config/server.properties
- bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
To make the test-case simpler we added a single principal "client" in the KDC for both the producer and consumer. Create a file called "config/client.jaas" with the content:
KafkaClient {
com.sun.security.auth.module.Krb5LoginModule required refreshKrb5Config=true useKeyTab=true keyTab="/path.to.kerby.project/target/client.keytab" storeKey=true principal="client";
};
Edit *both* 'config/producer.properties' and 'config/consumer.properties' and add:
- security.protocol=SASL_PLAINTEXT
- sasl.mechanism=GSSAPI
- sasl.kerberos.service.name=kafka
- -Djava.security.auth.login.config=/path.to.kafka/config/client.jaas
- -Djava.security.krb5.conf=/path.to.kerby.project/target/krb5.conf
- 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
No comments:
Post a Comment