0

I've been trying to set up authentication in kafka but I keep getting stuck, not sure what I am missing but this is my docker-compose (running version 3.7 of docker-compose) snippet

services:

  zookeeper:
    image: confluentinc/cp-zookeeper:5.5.3
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
      KAFKA_OPTS: -Djava.security.auth.login.config=/etc/kafka/zookeeper_server_jaas.conf
                  -Dzookeeper.authProvider.1=org.apache.zookeeper.server.auth.SASLAuthenticationProvider
                  -Dzookeeper.allowSaslFailedClients=false
                  -Dzookeeper.requireClientAuthScheme=sasl
    

  kafka:
    image: confluentinc/cp-enterprise-kafka:5.5.3
    depends_on: [zookeeper]
    environment:
      KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_PLAINTEXT_HOST:SASL_PLAINTEXT
      KAFKA_ADVERTISED_LISTENERS: SASL_PLAINTEXT://kafka:29092,SASL_PLAINTEXT_HOST://localhost:9092
      KAFKA_OPTS: -Djava.security.auth.login.config=/etc/kafka/kafka_server_jaas.conf
      KAFKA_INTER_BROKER_LISTENER_NAME: SASL_PLAINTEXT
      KAFKA_SASL_ENABLED_MECHANISMS: PLAIN
      KAFKA_SECURITY_PROTOCOL: SASL_PLAINTEXT
      KAFKA_SASL_MECHANISM_INTER_BROKER_PROTOCOL: PLAIN
      KAFKA_BROKER_ID: 1
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
      KAFKA_JMX_PORT: 9991
    ports:
    - 9092:9092
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./kafka_server_jaas.conf:/etc/kafka/kafka_server_jaas.conf
    
      
  schema-registry:
    image: confluentinc/cp-schema-registry:5.5.3
    environment:
     SCHEMA_REGISTRY_KAFKASTORE_CONNECTION_URL: zookeeper:2181
     SCHEMA_REGISTRY_HOST_NAME: schema-registry
     SCHEMA_REGISTRY_LISTENERS: http://schema-registry:8081,http://localhost:8081
     SCHEMA_REGISTRY_KAFKASTORE_SECURITY_PROTOCOL: SASL_PLAINTEXT
     SCHEMA_REGISTRY_KAFKASTORE_SASL_MECHANISM: PLAIN
     SCHEMA_REGISTRY_KAFKASTORE_SASL_JAAS_CONFIG: "org.apache.kafka.common.security.plain.PlainLoginModule required \
                username=\"username\" \
                password=\"password\";"

An error log snippet:

INFO [SocketServer brokerId=1] Failed authentication with /172.18.0.8 (Unexpected Kafka request of type METADATA during SASL handshake.) (org.apache.kafhe.kafka.common.network.Selector)
clifford_owino
  • 462
  • 1
  • 6
  • 24
  • I've already tried https://stackoverflow.com/questions/61520274/unexpected-kafka-request-of-type-metadata-during-sasl-handshake but that seems to not be the case – clifford_owino Jan 09 '22 at 20:11
  • Your schema registry Kafka store config should actually be Kafka container. It also doesn't need a localhost listener – OneCricketeer Jan 10 '22 at 15:02

0 Answers0