Follow these steps to quickly set up a secure Kafka environment with Docker:
Edit the docker-compose.yml file if you want to adjust ports or other service settings.
You can automatically generate a secure .env file and JAAS config for Kafka authentication by running:
./setup-passwords.sh- This script creates strong random passwords for your admin, broker, and app users.
- It generates the required
.envfile and updatesconfig/kafka_server_jaas.confto match. - If a
.envfile already exists, you'll be asked whether you want to replace it.
Tip: Using
setup-passwords.shis the easiest and most secure way to set up your configuration. You do not need to manually edit passwords unless you have custom requirements.
Update the contents of config/kafka_server_jaas.conf with your chosen credentials:
KafkaServer {
org.apache.kafka.common.security.scram.ScramLoginModule required
username="broker"
password="YOUR_PASSWORD";
};
KafkaClient {
org.apache.kafka.common.security.scram.ScramLoginModule required
username="broker"
password="YOUR_PASSWORD";
};
Client {
org.apache.kafka.common.security.scram.ScramLoginModule required
username="broker"
password="YOUR_PASSWORD";
};
Note: Replace
"YOUR_PASSWORD"with a secure password. This should match the value forKAFKA_BROKER_PASSWORDin your.envfile.
Populate the .env file with your cluster and user credentials:
# Kafka Cluster Configuration
KAFKA_CLUSTER_ID=MkU3OEVBNTcwNTJENDM2Qk
# SASL/SCRAM Authentication
KAFKA_ADMIN_USERNAME=admin
KAFKA_ADMIN_PASSWORD=SecureAdmin123
KAFKA_BROKER_USERNAME=broker
KAFKA_BROKER_PASSWORD=SecureBroker456
KAFKA_APP_USERNAME=app_user
KAFKA_APP_PASSWORD=SecureApp789
# Kafka UI
UI_ADMIN_USERNAME=kafka-ui
UI_ADMIN_PASSWORD=SecureUI123Tip: Use strong, unique passwords. The usernames and passwords here must match those specified in your JAAS config and Docker Compose.
Start the Kafka services and apply your configuration by running:
./SETUP.shYou should now have a running Kafka environment with authentication set up. For most users, ./setup-passwords.sh provides a simple, secure starting point!