As a pre-requisite to this article, please follow the previous blog post to set up Apache Kafka using kerberos, and test that the Camel route can retrieve from the topic we created successfully.
1) Configuring the Kerberos JAAS Login Module in Karaf
Download and extract the latest version of the Apache Karaf runtime (4.2.3 was used in this post). Before starting Karaf, we need to pass through a system property pointing to the krb5.conf file created in our Kerby KDC. This step is not necessary if you are using the standard location in the filesystem for krb5.conf. Open 'bin/karaf' and add the following to the list of system properties:
- -Djava.security.krb5.conf=/path.to.kerby.project/target/krb5.conf \
Recall that our Camel route needs to configure a JAAS LoginModule for Kerberos. In the example given in the previous post, this was configured by setting the Java System property "java.security.auth.login.config" to point to the JAAS configuration file. We don't want to do that with Karaf, as otherwise we will end up overriding the other JAAS LoginModules that are installed.
Instead, we will take advantage of Karaf's "hot deploy" feature to add the Kerberos Login Module we need to Karaf. Drop the following blueprint XML file into Karaf's deploy directory, changing the keytab location with the correct path to the keytab file:
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
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0" | |
xmlns:jaas="http://karaf.apache.org/xmlns/jaas/v1.0.0" | |
xsi:schemaLocation=" | |
http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd | |
"> | |
<jaas:config name="KafkaClient" rank="2"> | |
<jaas:module className="com.sun.security.auth.module.Krb5LoginModule" flags="required"> | |
refreshKrb5Config=true | |
useKeyTab=true | |
keyTab=/home/coheig/src/testcases/apache/bigdata/kerberos/target/client.keytab | |
storeKey=true | |
principal=client | |
</jaas:module> | |
</jaas:config> | |
</blueprint> |
2) Configuring the Camel route in Karaf
Next we will hot deploy our Camel route as a blueprint file in Karaf. Copy the following file into the deploy directory:
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
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0" | |
xmlns:camel="http://camel.apache.org/schema/blueprint" | |
xmlns:jaas="http://karaf.apache.org/xmlns/jaas/v1.0.0" | |
xsi:schemaLocation=" | |
http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd | |
"> | |
<camelContext xmlns="http://camel.apache.org/schema/blueprint"> | |
<route> | |
<from uri="kafka:test?brokers=localhost:9092&groupId=test-consumer-group&seekTo=beginning&autoCommitEnable=true&sessionTimeoutMs=30000&autoCommitIntervalMs=1000&saslKerberosServiceName=kafka&securityProtocol=SASL_PLAINTEXT"/> | |
<log message="Received: $simple{body}" loggingLevel="INFO"/> | |
<log message="Headers: $simple{headers}" loggingLevel="INFO"/> | |
<convertBodyTo type="java.lang.String"/> | |
<to uri="file:target/results"/> | |
</route> | |
</camelContext> | |
</blueprint> |