SASL authentication in Kafka - Commands & Configuration
listeners=SASL_PLAINTEXT://:9092 advertised.listeners=SASL_PLAINTEXT://localhost:9092 sasl.enabled.mechanisms=PLAIN sasl.mechanism.inter.broker.protocol=PLAIN security.inter.broker.protocol=SASL_PLAINTEXT listener.name.sasl_plaintext.plain.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="admin" password="admin-secret";
This configuration file sets Kafka to use SASL with the PLAIN mechanism over plaintext connections.
listeners: Defines Kafka to listen for SASL_PLAINTEXT connections on port 9092.
advertised.listeners: Tells clients how to connect to Kafka.
sasl.enabled.mechanisms: Enables the PLAIN SASL mechanism.
sasl.mechanism.inter.broker.protocol: Sets the mechanism brokers use to talk to each other.
security.inter.broker.protocol: Uses SASL_PLAINTEXT for broker communication.
listener.name.sasl_plaintext.plain.sasl.jaas.config: Provides the username and password for authentication.
kafka-server-start.sh server.properties
kafka-console-producer.sh --broker-list localhost:9092 --topic test-topic --producer-property sasl.mechanism=PLAIN --producer-property security.protocol=SASL_PLAINTEXT --producer-property sasl.jaas.config='org.apache.kafka.common.security.plain.PlainLoginModule required username="admin" password="admin-secret";'
--producer-property sasl.mechanism=PLAIN - Specifies the SASL mechanism to use.--producer-property security.protocol=SASL_PLAINTEXT - Specifies the security protocol for the connection.--producer-property sasl.jaas.config='org.apache.kafka.common.security.plain.PlainLoginModule required username="admin" password="admin-secret";' - Provides the username and password for authentication.kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test-topic --from-beginning --consumer-property sasl.mechanism=PLAIN --consumer-property security.protocol=SASL_PLAINTEXT --consumer-property sasl.jaas.config='org.apache.kafka.common.security.plain.PlainLoginModule required username="admin" password="admin-secret";'
--consumer-property sasl.mechanism=PLAIN - Specifies the SASL mechanism to use.--consumer-property security.protocol=SASL_PLAINTEXT - Specifies the security protocol for the connection.--consumer-property sasl.jaas.config='org.apache.kafka.common.security.plain.PlainLoginModule required username="admin" password="admin-secret";' - Provides the username and password for authentication.If you remember nothing else from this pattern, remember: SASL authentication requires both Kafka server and clients to be configured with matching security settings and credentials.