Client authentication configuration in Kafka - Commands & Configuration
listeners=SASL_PLAINTEXT://:9092 advertised.listeners=SASL_PLAINTEXT://localhost:9092 security.inter.broker.protocol=SASL_PLAINTEXT sasl.enabled.mechanisms=PLAIN sasl.mechanism.inter.broker.protocol=PLAIN listener.name.sasl_plaintext.plain.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="admin" password="admin-secret";
listeners: Defines the protocol and port Kafka listens on with SASL_PLAINTEXT for authentication without encryption.
advertised.listeners: The address clients use to connect to Kafka.
security.inter.broker.protocol: Protocol used between Kafka brokers, here also SASL_PLAINTEXT.
sasl.enabled.mechanisms: Enables the PLAIN mechanism for username/password authentication.
sasl.mechanism.inter.broker.protocol: Mechanism used between brokers.
listener.name.sasl_plaintext.plain.sasl.jaas.config: Configures the JAAS login module with 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 for authentication.--producer-property security.protocol=SASL_PLAINTEXT - Defines the security protocol to use SASL without encryption.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 for authentication.--consumer-property security.protocol=SASL_PLAINTEXT - Defines the security protocol to use SASL without encryption.If you remember nothing else from this pattern, remember: client authentication in Kafka uses SASL mechanisms configured on both broker and client sides to verify identities before allowing access.
Practice
Solution
Step 1: Understand client authentication
Client authentication is about confirming who is connecting to Kafka to ensure security.Step 2: Identify the purpose in Kafka context
Kafka uses client authentication to verify client identity before allowing access.Final Answer:
To verify the identity of clients connecting to the Kafka broker -> Option AQuick Check:
Client authentication = verify identity [OK]
- Confusing authentication with message compression
- Thinking authentication speeds up delivery
- Mixing authentication with data storage
Solution
Step 1: Recall Kafka SSL config property
The correct property to enable SSL is 'security.protocol' set to 'SSL'.Step 2: Check other options for correctness
Other options are not valid Kafka config keys for SSL authentication.Final Answer:
security.protocol=SSL -> Option CQuick Check:
SSL enabled by security.protocol=SSL [OK]
- Using non-existent properties like ssl.enabled
- Confusing property names with auth.method
- Adding extra words like enable.ssl.auth
security.protocol=SASL_SSL sasl.mechanism=PLAIN sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="user" password="pass";
What type of client authentication is configured?
Solution
Step 1: Analyze security.protocol and sasl.mechanism
security.protocol=SASL_SSL means SASL authentication over SSL. sasl.mechanism=PLAIN means using PLAIN SASL mechanism.Step 2: Confirm authentication type
The config uses SASL PLAIN mechanism secured by SSL transport.Final Answer:
SASL with PLAIN mechanism over SSL -> Option BQuick Check:
SASL_SSL + PLAIN = SASL PLAIN over SSL [OK]
- Ignoring sasl.mechanism and assuming only SSL
- Confusing PLAIN with SCRAM mechanism
- Thinking no authentication is set
security.protocol=SSL ssl.keystore.location=/path/to/keystore ssl.keystore.password=wrongpass
The client fails to authenticate. What is the most likely cause?
Solution
Step 1: Check SSL keystore config
The keystore password is set to 'wrongpass', which likely does not match the actual password.Step 2: Evaluate other options
Missing sasl.mechanism is irrelevant for SSL-only config. PLAINTEXT disables security. Keystore location is required.Final Answer:
Incorrect keystore password -> Option AQuick Check:
Wrong password causes SSL auth failure [OK]
- Assuming sasl.mechanism is needed for SSL-only
- Changing security.protocol to PLAINTEXT by mistake
- Ignoring keystore location requirement
Solution
Step 1: Identify correct security.protocol for SASL SCRAM over SSL
It must be 'SASL_SSL' to use SASL authentication over SSL.Step 2: Match sasl.mechanism and jaas config
For SCRAM-SHA-512, sasl.mechanism must be 'SCRAM-SHA-512' and jaas config must use ScramLoginModule.Step 3: Verify options
security.protocol=SASL_SSL sasl.mechanism=SCRAM-SHA-512 sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="user" password="pass"; matches all requirements. security.protocol=SSL sasl.mechanism=SCRAM-SHA-512 sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="user" password="pass"; misses SASL in protocol. security.protocol=SASL_PLAINTEXT sasl.mechanism=SCRAM-SHA-512 sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="user" password="pass"; uses PLAINTEXT transport. security.protocol=SASL_SSL sasl.mechanism=PLAIN sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="user" password="pass"; uses PLAIN mechanism, not SCRAM.Final Answer:
security.protocol=SASL_SSL sasl.mechanism=SCRAM-SHA-512 sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="user" password="pass"; -> Option DQuick Check:
SASL_SSL + SCRAM-SHA-512 + ScramLoginModule = security.protocol=SASL_SSL sasl.mechanism=SCRAM-SHA-512 sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="user" password="pass"; [OK]
- Using SSL without SASL for SCRAM
- Mixing PLAIN mechanism with SCRAM config
- Setting security.protocol to PLAINTEXT
Ready to prove it?
Pass the test and this pattern moves unknown
