Search code examples
docker-composeapache-apisix

Docker compose for apisix, etcd, apisix-dashbaord


I am trying to create a simple docker-compose setup for apisix, apisix-dashboard and etcd. It's purpose is just to spin up a simple setup for playing around and testing locally. Unfortunately, the apisix examples in the apisix-docker Github repo are not working and the docs are incomplete.

So far, I managed to spin up the three containers, but when I try to login to apisix-dashboard, I get an error "Request Error Code: 10000 username or password error", but there is no corresponding log message. What is going wrong?

This is my compose.yaml:

services:
  # etcd for APISIX configuration storage
  etcd:
    image: bitnami/etcd:3.5.17
    container_name: etcd
    environment:
      ALLOW_NONE_AUTHENTICATION: yes
      ETCD_ADVERTISE_CLIENT_URLS: http://etcd:2379
      ETCD_LISTEN_CLIENT_URLS: http://0.0.0.0:2379
    ports:
      - "2379:2379"

  # APISIX instance
  apisix:
    image: apache/apisix:3.11.0-debian
    container_name: apisix
    restart: always
    depends_on:
      - etcd
    volumes:
      - ./apisix_conf/config.yaml:/usr/local/apisix/conf/config.yaml:ro
    ports:
      - "9080:9080"
      - "9443:9443"
      # - "9091:9091" # APISIX Admin API port (default is 9091)

  # APISIX Dashboard
  apisix-dashboard:
    image: apache/apisix-dashboard:3.0.1-alpine
    container_name: apisix-dashboard
    restart: always
    depends_on:
      - apisix
      - etcd
    volumes:
      - ./dashboard_conf/conf.yaml:/usr/local/apisix-dashboard/conf/conf.yaml:ro
    ports:
      - "9000:9000"

apisix_conf/config.yaml:

apisix:
  node_listen: 9080          # APISIX listening port for HTTP
  
deployment:
  admin:
    allow_admin:
      - 0.0.0.0/0
    admin_key:
      - name: "admin"
        key: edd1c9f034335f136f87ad84b625c8f1
        role: admin
  etcd:
    host:
      - http://etcd:2379
    prefix: "/apisix"
    timeout: 30

dashboard_conf/conf.yaml:

conf:
  listen:
    port: 9000

  etcd:
    endpoints:
      - etcd:2379
      
authentication:
  secret: secret
  users:
    - username: admin
    - password: admin

Solution

  • The error is in the file dashboard_conf/conf.yaml, specifically in this snippet:

      users:
        - username: admin
        - password: admin
    

    Appearently, this results in an empty list of users, because you're defining 2 wrong users: one without the password field, and the other without the username field.

    That's why you are not be able to log in. It should instead be:

      users:
        - username: admin
          password: admin
    

    For reference, see the APISIX configuration parser apache/apisix-dashboard/api/internal/conf/conf.go, specifically lines L129-L132:

    type User struct {
        Username string
        Password string
    }
    

    And lines L300-L311:

    func initAuthentication(conf Authentication) {
        AuthConf = conf
        if AuthConf.Secret == "secret" {
            AuthConf.Secret = utils.GetFlakeUidStr()
        }
    
        userList := conf.Users
        // create user list
        for _, item := range userList {
            UserList[item.Username] = item
        }
    }