📖 Scenario: You are setting up a Kafka cluster for a company that handles sensitive customer data. To protect this data, you need to apply security best practices in Kafka configuration.
🎯 Goal: Configure Kafka with basic security settings including authentication and authorization to secure the data flow.
📋 What You'll Learn
Create a Kafka server properties dictionary with default settings
Add a security protocol configuration variable
Apply SASL authentication and ACL authorization settings
Print the final Kafka security configuration
💡 Why This Matters
🌍 Real World
Kafka is widely used for real-time data streaming in industries like finance, healthcare, and e-commerce where data security is critical.
💼 Career
Understanding Kafka security best practices is essential for roles like DevOps engineers, data engineers, and system administrators to protect sensitive data and comply with regulations.
Progress0 / 4 steps
1
Create Kafka server properties dictionary
Create a dictionary called kafka_config with these exact entries: 'broker.id': '1', 'log.dirs': '/tmp/kafka-logs', and 'zookeeper.connect': 'localhost:2181'.
Kafka
Hint
Use curly braces to create a dictionary and include the exact keys and values as strings.
2
Add security protocol configuration
Add a new entry to the kafka_config dictionary with key 'security.protocol' and value 'SASL_PLAINTEXT'.
Kafka
Hint
Add the key and value inside the existing dictionary with a comma separating entries.
3
Apply SASL authentication and ACL authorization settings
Add these exact entries to kafka_config: 'sasl.mechanism.inter.broker.protocol': 'PLAIN' and 'authorizer.class.name': 'kafka.security.auth.SimpleAclAuthorizer'.
Kafka
Hint
Add both entries separated by commas inside the dictionary.
4
Print the final Kafka security configuration
Write a print statement to display the kafka_config dictionary.
Kafka
Hint
Use print(kafka_config) to show the dictionary.
Practice
(1/5)
1. Which of the following is the primary purpose of using SSL/TLS in Kafka security?
easy
A. To manage access permissions with ACLs
B. To authenticate users with usernames and passwords
C. To encrypt data transmitted between Kafka clients and brokers
D. To compress messages for faster transmission
Solution
Step 1: Understand SSL/TLS role in Kafka
SSL/TLS is used to encrypt data sent over the network to protect it from eavesdropping.
Step 2: Differentiate from other security features
Authentication uses SASL, and ACLs manage permissions, not encryption.
Final Answer:
To encrypt data transmitted between Kafka clients and brokers -> Option C
Quick Check:
SSL/TLS = Encryption [OK]
Hint: SSL/TLS encrypts data in transit, not authentication or permissions [OK]
Common Mistakes:
Confusing SSL/TLS with authentication methods
Thinking ACLs handle encryption
Assuming SSL/TLS compresses data
2. Which of the following is the correct way to enable SASL authentication in Kafka's server.properties file?
easy
A. acl.enable=true
B. security.protocol=PLAINTEXT
C. ssl.enabled=true
D. sasl.enabled.mechanisms=PLAIN
Solution
Step 1: Identify SASL configuration property
The property sasl.enabled.mechanisms specifies which SASL mechanisms Kafka accepts.
Step 2: Check other options for correctness
security.protocol=PLAINTEXT disables security, ssl.enabled is not a valid property, and acl.enable is unrelated to SASL.
Final Answer:
sasl.enabled.mechanisms=PLAIN -> Option D
Quick Check:
SASL config uses sasl.enabled.mechanisms [OK]
Hint: SASL uses sasl.enabled.mechanisms property in server.properties [OK]
Common Mistakes:
Using PLAINTEXT disables security
Confusing SSL properties with SASL
Assuming acl.enable controls authentication
3. Given the following ACL command, what permission does it grant?
A. security.protocol should be SASL_SSL to enable encryption
B. The property should be sasl.mechanism instead of sasl.mechanisms
C. SCRAM-SHA-256 is not a valid SASL mechanism
D. No error, configuration is correct
Solution
Step 1: Check security.protocol value
SASL_PLAINTEXT enables SASL but does not encrypt traffic, which is insecure for sensitive data.
Step 2: Recommend secure protocol
Using SASL_SSL enables SASL authentication with SSL encryption, which is a best practice.
Final Answer:
security.protocol should be SASL_SSL to enable encryption -> Option A
Quick Check:
Use SASL_SSL for encrypted SASL connections [OK]
Hint: SASL_PLAINTEXT lacks encryption; use SASL_SSL for security [OK]
Common Mistakes:
Thinking SASL_PLAINTEXT encrypts data
Confusing sasl.mechanism property name
Believing SCRAM-SHA-256 is invalid
5. You want to secure a Kafka cluster so that only authenticated users can produce or consume messages, and all traffic is encrypted. Which combination of settings achieves this best?
hard
A. Use PLAINTEXT protocol with ACLs to restrict access, no encryption needed
B. Enable SSL encryption with security.protocol=SASL_SSL, configure SASL authentication, and set ACLs for user permissions
C. Enable SASL_PLAINTEXT for authentication and rely on network firewall for encryption
D. Use SSL only without SASL or ACLs to simplify configuration
Solution
Step 1: Ensure encryption and authentication
Using security.protocol=SASL_SSL enables both encryption (SSL) and authentication (SASL).
Step 2: Control access with ACLs
ACLs restrict which authenticated users can produce or consume messages, enforcing permissions.
Final Answer:
Enable SSL encryption with security.protocol=SASL_SSL, configure SASL authentication, and set ACLs for user permissions -> Option B