📖 Scenario: You are setting up a Kafka client to securely connect to a Kafka broker. To do this, you need to configure client authentication using SASL/PLAIN mechanism.
🎯 Goal: Configure a Kafka client with SASL/PLAIN authentication by creating the necessary configuration properties step-by-step.
📋 What You'll Learn
Create a dictionary called client_config with basic Kafka client settings
Add a configuration variable sasl_mechanism set to PLAIN
Add SASL authentication settings to client_config using the sasl_mechanism and given credentials
Print the final client_config dictionary
💡 Why This Matters
🌍 Real World
Kafka clients often need secure authentication to connect to brokers in production environments. Configuring SASL/PLAIN is a common way to authenticate users.
💼 Career
Understanding how to configure Kafka client authentication is important for roles like backend developers, DevOps engineers, and data engineers working with Kafka clusters.
Progress0 / 4 steps
1
Create initial Kafka client configuration
Create a dictionary called client_config with these exact entries: 'bootstrap.servers': 'localhost:9092' and 'security.protocol': 'SASL_PLAINTEXT'.
Kafka
Hint
Use a Python dictionary with the exact keys and values as shown.
2
Add SASL mechanism configuration
Create a variable called sasl_mechanism and set it to the string 'PLAIN'.
Kafka
Hint
Assign the string 'PLAIN' to the variable sasl_mechanism.
3
Add SASL authentication details to client configuration
Add these exact entries to the client_config dictionary: 'sasl.mechanism' set to sasl_mechanism, 'sasl.username' set to 'user1', and 'sasl.password' set to 'pass123'.
Kafka
Hint
Use dictionary key assignment to add the new entries.
4
Print the final client configuration
Write a print statement to display the client_config dictionary.
Kafka
Hint
Use print(client_config) to show the dictionary.
Practice
(1/5)
1. What is the main purpose of client authentication in Kafka?
easy
A. To verify the identity of clients connecting to the Kafka broker
B. To increase the speed of message delivery
C. To compress messages before sending
D. To store messages permanently on the client side
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 A
Quick Check:
Client authentication = verify identity [OK]
Hint: Authentication means verifying who you are [OK]
Common Mistakes:
Confusing authentication with message compression
Thinking authentication speeds up delivery
Mixing authentication with data storage
2. Which Kafka client configuration property is used to enable SSL authentication?
easy
A. enable.ssl.auth=true
B. ssl.enabled=true
C. security.protocol=SSL
D. auth.method=ssl
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 C
Quick Check:
SSL enabled by security.protocol=SSL [OK]
Hint: Use security.protocol=SSL to enable SSL [OK]