Search code examples
log4japache-kafkakerberosjaaskafka-producer-api

Can you use log4j to write logs to secured Kafka with KafkaLog4jAppender


I have a requirement to write logs to a Kafka topic that is secured via Kerberos.

I am using log4j 1.2.17 and Kafka 08.2.2.

The only options supported by KafkaLog4jAppender are these

var topic: String = null
var brokerList: String = null
var compressionType: String = null
var requiredNumAcks: Int = Int.MaxValue
var syncSend: Boolean = false

which do not allow me to set any JAAS options such as

com.sun.security.auth.module.Krb5LoginModule required
useKeyTab=true
keyTab="/keytabs/kafkaclient.keytab"
storeKey=true
useTicketCache=false
serviceName="kafka"
principal="kafkaproducer/_HOST@EXAMPLE.COM";

Do i have to develop a custom KafkaLog4jAppender that accepts the JAAS details or is there a way to use KafkaLog4jAppender to write logs to a secured kafka topic?


Solution

  • Yes, if you take a look at https://github.com/apache/kafka/blob/trunk/log4j-appender/src/main/java/org/apache/kafka/log4jappender/KafkaLog4jAppender.java you will notice there are some SASL properties that you can set. Can you use those ?