0
0
Kafkadevops~30 mins

SASL authentication in Kafka - Mini Project: Build & Apply

Choose your learning style9 modes available
SASL Authentication Setup for Kafka Client
📖 Scenario: You are setting up a Kafka client that needs to connect securely to a Kafka broker using SASL authentication. SASL helps verify the client's identity before allowing access.
🎯 Goal: Configure a Kafka client with SASL authentication using the PLAIN mechanism to connect to a Kafka broker.
📋 What You'll Learn
Create a Kafka client configuration dictionary with bootstrap servers
Add SASL authentication configuration with mechanism and credentials
Use the configuration to create a Kafka consumer
Print the SASL mechanism used to confirm setup
💡 Why This Matters
🌍 Real World
Kafka clients often need SASL authentication to securely connect to brokers in real-world applications like messaging systems and data pipelines.
💼 Career
Understanding SASL authentication setup is important for roles involving Kafka administration, backend development, and secure data streaming.
Progress0 / 4 steps
1
Create Kafka client configuration
Create a dictionary called config with the key 'bootstrap.servers' set to 'localhost:9092'.
Kafka
Need a hint?

The bootstrap.servers key tells the client where the Kafka broker is located.

2
Add SASL authentication configuration
Add the following keys to the config dictionary: 'security.protocol' set to 'SASL_PLAINTEXT', 'sasl.mechanism' set to 'PLAIN', 'sasl.username' set to 'user1', and 'sasl.password' set to 'pass123'.
Kafka
Need a hint?

These keys configure the client to use SASL with the PLAIN mechanism and provide the username and password.

3
Create Kafka consumer with SASL config
Import KafkaConsumer from kafka and create a consumer called consumer using the config dictionary.
Kafka
Need a hint?

Use the KafkaConsumer constructor with the SASL config keys as parameters.

4
Print SASL mechanism used
Print the string 'SASL mechanism used: ' followed by the value of config['sasl.mechanism'].
Kafka
Need a hint?

Use a print statement with an f-string to show the SASL mechanism.