provectus / kafka-ui

Open-Source Web UI for Apache Kafka Management
Apache License 2.0
9.88k stars 1.19k forks source link

Login into kafka server with username and password failed. #4372

Open nhatthanh020996 opened 9 months ago

nhatthanh020996 commented 9 months ago

Issue submitter TODO list

Is your proposal related to a problem?

This is my docker compose file that helps me to create my kafka server.

version: '2'
services:
  zookeeper:
    image: wurstmeister/zookeeper
    ports:
      - "2181:2181"
    restart: unless-stopped

  kafka:
    image: wurstmeister/kafka
    depends_on:
    - zookeeper
    ports:
      - "9092:9092"
    environment:
      KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
      KAFKA_LISTENERS: SASL_PLAINTEXT://:9092
      KAFKA_ADVERTISED_LISTENERS: SASL_PLAINTEXT://localhost:9092
      KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'true'
      ALLOW_PLAINTEXT_LISTENER: 'yes'
      KAFKA_OPTS: "-Djava.security.auth.login.config=/etc/kafka/kafka_server_jaas.conf"
      KAFKA_AUTHORIZER_CLASS_NAME: kafka.security.auth.SimpleAclAuthorizer
      KAFKA_INTER_BROKER_LISTENER_NAME: SASL_PLAINTEXT
      KAFKA_SASL_ENABLED_MECHANISMS: PLAIN
      KAFKA_SASL_MECHANISM_INTER_BROKER_PROTOCOL: PLAIN
      KAFKA_SECURITY_PROTOCOL: SASL_PLAINTEXT
      KAFKA_SUPER_USERS: User:admin,User:enzo
      KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: 'true'
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./kafka_server_jaas.conf:/etc/kafka/kafka_server_jaas.conf

    restart: unless-stopped

kafka_server_jaas.conf

 KafkaServer {
org.apache.kafka.common.security.plain.PlainLoginModule required
username="admin"
password="admin-secret"
user_admin="admin-secret"
user_enzo="cisternino";
};

KafkaClient {
org.apache.kafka.common.security.plain.PlainLoginModule required
user_admin="admin-secret";
};

Client {};

This is my docker for creating kafka-ui

version: '2'
services:
  kafka-ui:
    image: provectuslabs/kafka-ui
    container_name: kafka-ui
    ports:
    - "8080:8080"
    environment:
      KAFKA_CLUSTERS_0_NAME: 'local'
      KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: 'localhost:9092'
      KAFKA_CLUSTERS_0_ZOOKEEPER: 'zookeeper:2181'
      KAFKA_CLUSTERS_0_PROPERTIES_SECURITY_PROTOCOL: SASL_PLAINTEXT
      KAFKA_CLUSTERS_0_PROPERTIES_SASL_MECHANISM: PLAIN
      KAFKA_CLUSTERS_0_PROPERTIES_SASL_JAAS_CONFIG: 'org.apache.kafka.common.security.plain.PlainLoginModule required username="admin" password="admin-secret";'

I get the following error after runing kafka-ui docker:

AdminClient clientId=kafka-ui-admin-1707208145-7] Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.

Describe the feature you're interested in

I want to log into the kafka server successfully.

Describe alternatives you've considered

I did read this issue, however the issue still remain. https://github.com/provectus/kafka-ui/issues/573

Version you're running

the latest version

Additional context

No response

github-actions[bot] commented 9 months ago

Hello there nhatthanh020996! πŸ‘‹

Thank you and congratulations πŸŽ‰ for opening your very first issue in this project! πŸ’–

In case you want to claim this issue, please comment down below! We will try to get back to you as soon as we can. πŸ‘€

rgdev commented 9 months ago

KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: 'localhost:9092'

If you point to localhost within a container it will send requests to the container's loopback interface and since Kafka lives in another container this cannot work.

Instead put kafka ui and kafka on the same docker network and resolve using the container name like so :

KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: 'kafka:9092'

NZenitram commented 3 months ago

I have this configured appropriately:

    environment:
      DYNAMIC_CONFIG_ENABLED: 'true'
      KAFKA_CLUSTERS_0_NAME: relay-cluster
      KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:9092

And I am still getting this error in the logs:

kafka-ui | 2024-08-24 15:50:31,526 WARN [kafka-admin-client-thread | kafka-ui-admin-1724514626-3] o.a.k.c.NetworkClient: [AdminClient clientId=kafka-ui-admin-1724514626-3] Connection to node 1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.

pbozzoli commented 4 days ago

Same problem here, I'm trying with kafka local (docker.io/confluentinc/confluent-local image). I tried both configuration with environment variables:

nerdctl run -d --name kafka-ui -p 8080:8080 -e "KAFKA_CLUSTERS_0_NAME=local0" -e "KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS=kafka:9092" provectuslabs/kafka-ui

and with dynamic_config.yaml:

auth:
  type: DISABLED
kafka:
  clusters:
  - bootstrapServers: kafka:9092
    name: local-cluster
    properties:
      security.protocol: PLAINTEXT
    readOnly: false
rbac:
  roles: []
webclient: {}

nerdctl run -d --name kafka-ui -p 8080:8080 -e DYNAMIC_CONFIG_ENABLED=true -e LOGGING_LEVEL_ROOT=DEBUG -v "C:\PSI\LIM\dynamic_config.yaml:/etc/kafkaui/dynamic_config.yaml" provectuslabs/kafka-ui

But I have the same problem:

2024-11-22 11:44:36,908 WARN  [kafka-admin-client-thread | kafka-ui-admin-1732275876-27] o.a.k.c.NetworkClient: [AdminClient clientId=kafka-ui-admin-1732275876-27] Connection to node 1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.

Then some debug log:

2024-11-22 11:44:37,003 DEBUG [kafka-admin-client-thread | kafka-ui-admin-1732275876-27] o.a.k.c.ClientUtils: Resolved host localhost as 127.0.0.1

2024-11-22 11:44:37,003 DEBUG [kafka-admin-client-thread | kafka-ui-admin-1732275876-27] o.a.k.c.NetworkClient: [AdminClient clientId=kafka-ui-admin-1732275876-27] Initiating connection to node localhost:9092 (id: 1 rack: null) using address localhost/127.0.0.1

2024-11-22 11:44:37,003 DEBUG [kafka-admin-client-thread | kafka-ui-admin-1732275876-27] o.a.k.c.n.Selector: [AdminClient clientId=kafka-ui-admin-1732275876-27] Connection with localhost/127.0.0.1 (channelId=1) disconnected

If I try to change the port to 9094, it seems to convert the host name Kafka to the correct ip address:

2024-11-22 11:44:37,770 DEBUG [kafka-admin-client-thread | kafka-ui-admin-1732275471-20] o.a.k.c.NetworkClient: [AdminClient clientId=kafka-ui-admin-1732275471-20] Initiating connection to node kafka:9094 (id: -1 rack: null) using address kafka/10.4.0.113

Why does it try to connect in localhost if I use port 9092?