Apache Kafka
This page describes connecting the Lenses Agent to Apache Kafka.
A Kafka connection is required for the agent to start. You can connect to Kafka via:
Plaintext (no credentials an unencrypted)
SSL (no credentials an encrypted)
SASL Plaintext and SASL SSL
Only one Kafka connection is allowed.
The name must be kafka.
See JSON schema for support.
Environment variables are supported; escape the dollar sign
sslKeystorePassword:
value: "\${ENV_VAR_NAME}"
Plaintext
With PLAINTEXT, there's no encryption and no authentication when connecting to Kafka.
The only required fields are:
kafkaBootstrapServers - a list of bootstrap servers (brokers). It is recommended to add as many brokers (if available) as convenient to this list for fault tolerance.
protocol - depending on the protocol, other fields might be necessary (see examples for other protocols)
In following example JMX metrics for Kafka Brokers are configured too, assuming that all brokers expose their JMX metrics using the same port (9581), without SSL and authentication.
kafka:
- name: kafka
version: 1
tags: [my-tag]
configuration:
kafkaBootstrapServers:
value:
- PLAINTEXT://your.kafka.broker.0:9092
- PLAINTEXT://your.kafka.broker.1:9092
protocol:
value: PLAINTEXT
# all metrics properties are optional
metricsPort:
value: 9581
metricsType:
value: JMX
metricsSsl:
value: false
SSL
With SSL the connection to Kafka is encrypted. You can also uses SSL and certificates to authenticate users against Kafka.
A truststore (with password) might need to be set explicitly if the global truststore of the Agent does not include the Certificate Authority (CA) of the brokers.
If TLS is used for authentication to the brokers in addition to encryption-in-transit, a key store (with passwords) is required.
kafka:
- name: kafka
version: 1
tags: [my-tag]
configuration:
kafkaBootstrapServers:
value:
- SSL://your.kafka.broker.0:9092
- SSL://your.kafka.broker.1:9092
protocol:
value: SSL
sslTruststore:
file: /path/to/truststore.jks
sslTruststorePassword:
value: truststorePassword
sslKeystore:
file: /path/to/keystore.jks
sslKeyPassword:
value: keyPassword
sslKeystorePassword:
value: keystorePassword
SASL Plaintext vs SASL SSL
There are 2 SASL-based protocols to access Kafka Brokers: SASL_SSL
and SASL_PLAINTEXT
. They both require SASL mechanism and JAAS Configuration values. What is different is:
The transport layer is encyrpted (SSL)
The SASL mechanism for authentication (PLAIN, AWS_MSK_IAM, GSSAPI).
In addition to this, there might be a keytab file required, depending on the SASL mechanism (for example when using GSSAPI mechanism, most often used for Kerberos).
To use Kerberos authentication, a Kerberos _Connection_ should be created beforehand.
When encryption-in-transit is used (with SASL_SSL), a trust store might need to be set explicitly if the global trust store of Lenses does not include the CA of the brokers.
SASL SSL
Mechanism PLAIN
Encrypted communication and basic username and password for authentication.
kafka:
- name: kafka
version: 1
tags: [my-tag]
configuration:
kafkaBootstrapServers:
value:
- SASL_SSL://your.kafka.broker.0:9092
- SASL_SSL://your.kafka.broker.1:9092
protocol:
value: SASL_SSL
sslTruststore:
file: /path/to/truststore.jks
sslTruststorePassword:
value: truststorePassword
sslKeystore:
file: /path/to/keystore.jks
sslKeyPassword:
value: keyPassword
sslKeystorePassword:
value: keystorePassword
saslMechanism:
value: PLAIN
saslJaasConfig:
value: |
org.apache.kafka.common.security.plain.PlainLoginModule required
username="your-username"
password="your-password";
Mechanism GSSAPI
In order to use Kerberos authentication, a Kerberos Connection should be created beforehand.
kafka:
- name: kafka
version: 1
tags: [my-tag]
configuration:
kafkaBootstrapServers:
value:
- SASL_SSL://your.kafka.broker.0:9092
- SASL_SSL://your.kafka.broker.1:9092
protocol:
value: SASL_SSL
sslTruststore:
file: /path/to/truststore.jks
sslTruststorePassword:
value: truststorePassword
sslKeystore:
file: /path/to/keystore.jks
sslKeyPassword:
value: keyPassword
sslKeystorePassword:
value: keystorePassword
saslMechanism:
value: GSSAPI
saslJaasConfig:
value: |
com.sun.security.auth.module.Krb5LoginModule required
useKeyTab=true
storeKey=true
useTicketCache=false
serviceName=kafka
principal="[email protected]";
keytab:
file: /path/to/kafka-keytab.keytab
SASL Plaintext
No SSL encrypted of communication, credentials communicated to Kafka in clear text.
Mechanism SCRAM-SHA-256
kafka:
- name: kafka
version: 1
tags: [my-tag]
configuration:
kafkaBootstrapServers:
value:
- SASL_PLAINTEXT://your.kafka.broker.0:9092
- SASL_PLAINTEXT://your.kafka.broker.1:9092
protocol:
value: SASL_PLAINTEXT
saslMechanism:
value: SCRAM-SHA-256
saslJaasConfig:
value: |
org.apache.kafka.common.security.scram.ScramLoginModule required
username="your-username"
password="your-password";
Mechanism SCRAM-SHA-512
kafka:
- name: kafka
version: 1
tags: [my-tag]
configuration:
kafkaBootstrapServers:
value:
- SASL_PLAINTEXT://your.kafka.broker.0:9092
- SASL_PLAINTEXT://your.kafka.broker.1:9092
protocol:
value: SASL_PLAINTEXT
saslMechanism:
value: SCRAM-SHA-512
saslJaasConfig:
value: |
org.apache.kafka.common.security.scram.ScramLoginModule required
username="your-username"
password="your-password";
Last updated
Was this helpful?