Security best practices in Kafka - Commands & Configuration
listeners=SASL_SSL://:9093 advertised.listeners=SASL_SSL://localhost:9093 security.inter.broker.protocol=SASL_SSL sasl.enabled.mechanisms=PLAIN sasl.mechanism.inter.broker.protocol=PLAIN ssl.keystore.location=/var/private/ssl/kafka.server.keystore.jks ssl.keystore.password=changeit ssl.key.password=changeit ssl.truststore.location=/var/private/ssl/kafka.server.truststore.jks ssl.truststore.password=changeit authorizer.class.name=kafka.security.auth.SimpleAclAuthorizer allow.everyone.if.no.acl.found=false super.users=User:admin
listeners: Defines how Kafka accepts connections securely using SASL_SSL.
advertised.listeners: How Kafka tells clients to connect.
security.inter.broker.protocol: Secures communication between Kafka servers.
sasl.enabled.mechanisms: Enables PLAIN authentication.
ssl.keystore.location/password: Location and password for server keys.
ssl.truststore.location/password: Location and password for trusted certificates.
authorizer.class.name: Enables access control lists (ACLs) for permissions.
allow.everyone.if.no.acl.found: Denies access if no ACL is set.
super.users: Defines admin users with full access.
kafka-acls --authorizer-properties zookeeper.connect=localhost:2181 --add --allow-principal User:alice --operation Read --topic my-topic--add - Adds a new ACL rule--allow-principal - Specifies the user allowed--operation - Defines the allowed action (Read)--topic - Specifies the topic for the ACLkafka-configs --zookeeper localhost:2181 --entity-type users --entity-name alice --alter --add-config 'sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="alice" password="alice-secret";'
--alter - Changes existing user config--add-config - Adds SASL authentication detailskafka-topics --bootstrap-server localhost:9093 --describe --topic my-topic--describe - Shows topic details--bootstrap-server - Connects to Kafka securelyIf you remember nothing else from this pattern, remember: securing Kafka means controlling who connects, encrypting data, and setting clear permissions.
Practice
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 CQuick Check:
SSL/TLS = Encryption [OK]
- Confusing SSL/TLS with authentication methods
- Thinking ACLs handle encryption
- Assuming SSL/TLS compresses data
Solution
Step 1: Identify SASL configuration property
The propertysasl.enabled.mechanismsspecifies which SASL mechanisms Kafka accepts.Step 2: Check other options for correctness
security.protocol=PLAINTEXTdisables security,ssl.enabledis not a valid property, andacl.enableis unrelated to SASL.Final Answer:
sasl.enabled.mechanisms=PLAIN -> Option DQuick Check:
SASL config uses sasl.enabled.mechanisms [OK]
- Using PLAINTEXT disables security
- Confusing SSL properties with SASL
- Assuming acl.enable controls authentication
kafka-acls --add --allow-principal User:Alice --operation Read --topic sales-data
Solution
Step 1: Analyze the ACL command parameters
The command adds an ACL allowing User:Alice the Read operation on the topic sales-data.Step 2: Understand the Read operation
Read permission allows consuming or reading messages from the topic, not writing or deleting.Final Answer:
Alice can read messages from the sales-data topic -> Option AQuick Check:
ACL Read = Permission to consume messages [OK]
- Confusing Read with Write permission
- Assuming Read allows topic deletion
- Mixing topic creation with ACL permissions
security.protocol=SASL_PLAINTEXT sasl.mechanism=SCRAM-SHA-256
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 AQuick Check:
Use SASL_SSL for encrypted SASL connections [OK]
- Thinking SASL_PLAINTEXT encrypts data
- Confusing sasl.mechanism property name
- Believing SCRAM-SHA-256 is invalid
Solution
Step 1: Ensure encryption and authentication
Usingsecurity.protocol=SASL_SSLenables 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 BQuick Check:
Encryption + Authentication + ACLs = Secure Kafka [OK]
- Using PLAINTEXT disables encryption
- Relying on firewall instead of encryption
- Skipping ACLs allows unauthorized access
Ready to prove it?
Pass the test and this pattern moves unknown
