Kafka client configuration reference
This topic collects the minimum configuration required for enable the supported authentication mechanisms. You may need to update the client configuration file and the JAAS, depending on the desired authentication mechanism.
Client configuration file
You need to configure at least the following properties in the client.configuration file to enable the authentication mechanisms supported by Kafka.
-
security.protocol=[***SECURITY PROTOCOL***] sasl.mechanism=OAUTHBEARER sasl.login.callback.handler.class=org.apache.kafka.common.security.oauthbearer.secured.OAuthBearerLoginCallbackHandler sasl.oauthbearer.token.endpoint.url=http://[***OAUTH SERVER***]/[***TOKEN ENDPOINT***]Replace [***SECURITY PROTOCOL***] with either
SASL_SSLorSASL_PLAINTEXT. The security protocol you specify depends on whether TLS/SSL encryption is enabled on the broker.The following properties are only required if TLS/SSL is enabled on the broker.
ssl.truststore.location= [***PATH TO CLIENT TRUSTSTORE***] ssl.truststore.password=[***PASSWORD***]This example contains the minimum required TLS/SSL properties. Depending on your requirements and how TLS/SSL is configured on the broker, other properties might be required. For more information regarding TLS/SSL configuration, see Channel Encryption.
-
sasl.mechanism=PLAINThe following properties are used for configuring the security protocol.
You can either useSASL_SSLorSASL_PLAINTEXT. Which security protocol you use will depend on whether or not SSL encryption is enabled on the broker. Add one of the following properties to theclient.propertiesfile.- If encryption is enabled, use
SASL_SSL:security.protocol=SASL_SSL - If encryption is not enabled, use
SASL_PLAINTEXT:security.protocol=SASL_PLAINTEXT
- If encryption is enabled, use
-
sasl.mechanism=PLAINThe following properties are used for configuring the security protocol.
You can either useSASL_SSLorSASL_PLAINTEXT. Which security protocol you use will depend on whether or not SSL encryption is enabled on the broker. Add one of the following properties to theclient.propertiesfile.- If encryption is enabled, use
SASL_SSL:security.protocol=SASL_SSL - If encryption is not enabled, use
SASL_PLAINTEXT:security.protocol=SASL_PLAINTEXT
- If encryption is enabled, use
-
security.protocol=SSL ssl.truststore.location=[***PATH TO CLIENT TRUSTSTORE***] ssl.truststore.password=[***PASSWORD***] ssl.keystore.location=[***PATH TO CLIENT KEYSTORE***] ssl.keystore.password=[***PASSWORD***] ssl.key.password=[***PASSWORD***]Depending on your requirements and broker configuration, other configuration properties might also be needed. The following are some of the most commonly used optional properties:ssl.providerss.cipher.suitesssl.enabled.protocolsssl.truststore.typessl.keystore.type
-
security.protocol=SASL_PLAINTEXT sasl.kerberos.service.name=kafka
- This authentication method is not configured using the client.configuration file.
JAAS configuration
You need to configure at least the following properties in the JAAS to enable the authentication mechanisms supported by Kafka.
- You have two options when configuring the JAAS. You can either embed the full JAAS
configuration in the client.properties file or use a separate JAAS configuration file.
- Embed the required properties in the
client.propertiesfile with thesasl.jaas.configproperty.sasl.jaas.config=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required clientId="[***CLIENT ID***]" clientSecret="[***CLIENT SECRET***]" scope="[***SCOPE***]"; - Use a separate JAAS configuration file:
- Add a
KafkaCliententry with a login module item to your JAAS configuration file.You can also create a new JAAS configuration file if you do not have an existing one available.
KafkaClient { org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required clientId="[***CLIENT ID***]" clientSecret="[***CLIENT SECRET***]" scope="[***SCOPE***]"; }; - Pass the location of your JAAS configuration file as a JVM parameter through a command
line
interface.
export KAFKA_OPTS="-Djava.security.auth.login.config=[***PATH TO JAAS.CONF***]"
- Add a
- Embed the required properties in the
- You have two options when configuring the JAAS. You can either embed the full JAAS
configuration in the client.properties file or use a separate JAAS configuration file.
- Embed the required properties in the
client.propertiesfile with thesasl.jaas.configproperty.
Replace [LDAP_USERNAME] and [LDAP_PASSWORD] with a valid LDAP username and password.sasl.jaas.config= \ org.apache.kafka.common.security.plain.PlainLoginModule required \ username="[***LDAP USERNAME***]" \ password="[***LDAP PASSWORD***]"; - Use a separate JAAS configuration file:
- Add a
KafkaCliententry with a login module item to your JAAS configuration file.You can also create a new JAAS configuration file if you do not have an existing one available.
Example configuration:
Replace [LDAP_USERNAME] and [LDAP_PASSWORD] with a valid LDAP username and password.KafkaClient { org.apache.kafka.common.security.plain.PlainLoginModule required username="[***LDAP USERNAME***]" password="[***LDAP PASSWORD***]"; }; - Pass the location of your JAAS configuration file as a JVM parameter through a command
line interface.
Replace [***PATH TO JAAS.CONF***] with the location of the JAAS configuration file you created.export KAFKA_OPTS="-Djava.security.auth.login.config=[***PATH TO JAAS.CONF***]"
- Add a
- Embed the required properties in the
- You have two options when configuring the JAAS. You can either embed the full JAAS
configuration in the client.properties file or use a separate JAAS configuration file.
- Embed the required properties in the
client.propertiesfile with thesasl.jaas.configproperty.
Replace [USERNAME] and [PASSWORD] with a valid username and password.sasl.jaas.config= \ org.apache.kafka.common.security.plain.PlainLoginModule required \ username="[USERNAME]" \ password="[PASSWORD]"; - Use a separate JAAS configuration file:
- Add a
KafkaCliententry with a login module item to your JAAS configuration file.You can also create a new JAAS configuration file if you do not have an existing one available.
Example configuration:
Replace [USERNAME] and [PASSWORD] with a valid username and password.KafkaClient { org.apache.kafka.common.security.plain.PlainLoginModule required username="[USERNAME]" password="[PASSWORD]"; }; - Pass the location of your JAAS configuration file as a JVM parameter through a command
line interface.
Replace [PATH_TO_JAAS.CONF] with the location of the JAAS configuration file you created.export KAFKA_OPTS="-Djava.security.auth.login.config=[PATH_TO_JAAS.CONF]"
- Add a
- Embed the required properties in the
- This step is not applicable for TLS/SSL authentication.
- Create a
jaas.conffile with either cached credentials or keytabs.-
To use cached Kerberos credentials, where you use
kinitfirst, use this configuration:KafkaClient { com.sun.security.auth.module.Krb5LoginModule required useTicketCache=true; }; -
If you use a keytab, use this configuration:
KafkaClient { com.sun.security.auth.module.Krb5LoginModule required useKeyTab=true keyTab="/etc/security/keytabs/mykafkaclient.keytab" principal="mykafkaclient/clients.hostname.com@EXAMPLE.COM"; };
-
- You have two options when configuring the JAAS. You can either embed the full JAAS
configuration in the client.properties file or use a separate JAAS configuration file.
- Embed the required properties in the
client.propertiesfile with thesasl.jaas.configproperty.Example Configuration:
Within the JAAS configuration, there are three options that need to be specified. These are thesasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required \ username="tokenID" \ password="lAYYSFmLs4bTjf+lTZ1LCHR/ZZFNA==" \ tokenauth="true"; security.protocol=SASL_SSL sasl.mechanism=SCRAM-SHA-256username,passwordandtokenauthoptions. Theusernameandpasswordoptions specify the token ID and token HMAC. Thetokenauthoption expresses the intent to use token authentication to the server. - Use a separate JAAS configuration file:
- Add a
KafkaCliententry with a login module item to your JAAS configuration file.You can also create a new JAAS configuration file if you do not have an existing one available.
The module has to specify theusername,passwordandtokenauthoptions. The configuration is similar to the following example:
TheKafkaClient { org.apache.kafka.common.security.scram.ScramLoginModule required username="tokenID" password="lAYYSFmLs4bTjf+lTZ1LCHR/ZZFNA==" tokenauth="true"; }usernameandpasswordoptions specify the token ID and token HMAC. Thetokenauthoption expresses the intent to use token authentication to the server. - Configure the following properties for your
clients.These properties are added to producer.properties or consumer.properties file that the client uses.
security.protocol=SASL_SSL sasl.mechanism=SCRAM-SHA-256 - Pass the location of your JAAS configuration file as a JVM parameter through a command
line interface.This sets the JAAS configuration on the Java process level.
export KAFKA_OPTS="-Djava.security.auth.login.config=[PATH_TO_JAAS.CONF]"
- Add a
- Embed the required properties in the
