Access bitnami kafka broker only with user password

30 Views Asked by At

I have deployed bitnami kafka/zookeeper with docker-compose but want to enable authentication to access only with user/password. How can i do that?

version: '3'

services:
  zookeeper:
    image: bitnami/zookeeper:latest
    container_name: zookeeper
    environment:
      - ALLOW_ANONYMOUS_LOGIN=no
      - ZOO_ENABLE_AUTH=yes
      - ZOOKEEPER_USERNAME=myuser
      - ZOOKEEPER_PASSWORD=mypassword
    ports:
      - "2181:2181"

  kafka:
    image: bitnami/kafka:latest
    container_name: kafka
    hostname: kafka
    environment:
      - KAFKA_ZOOKEEPER_PROTOCOL=SASL
      - KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
      - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,PLAINTEXT_HOST://:29092
      - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092
      - KAFKA_CFG_INTER_BROKER_LISTENER_NAME=PLAINTEXT
      - KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=true
      - KAFKA_USERNAME=myuser
      - KAFKA_PASSWORD=mypassword
    ports:
      - "9092:9092"
      - "29092:29092"
    depends_on:
      - zookeeper

kafka client can create/list topics without user/pass

docker run -it --network kafka_default  --rm  bitnami/kafka:latest kafka-topics.sh --create --bootstrap-server kafka:9092 --replication-factor 1 --partitions 1 --topic replicated-kafkatopi
kafka 06:54:26.98 INFO  ==> 
kafka 06:54:26.98 INFO  ==> Welcome to the Bitnami kafka container
kafka 06:54:26.98 INFO  ==> Subscribe to project updates by watching https://github.com/bitnami/containers
kafka 06:54:26.98 INFO  ==> Submit issues and feature requests at https://github.com/bitnami/containers/issues
kafka 06:54:26.99 INFO  ==> 

Created topic replicated-kafkatopi.
0

There are 0 best solutions below