Use mosquitto-go-auth error in docker compose

90 Views Asked by At

I have set up mosquitto-go-auth on an ubuntu virtual system. I started trying to transfer the system I created to docker compose. I copied my file from the Ubuntu system, copied the configs.

mosquitto.conf:

persistence true
persistence_location /var/lib/mosquitto/

# log info:
log_dest file /mosquitto/log/mosquitto.log

# auth:
allow_anonymous false
listener 1883
auth_plugin /mosquitto/config/go-auth.so
auth_opt_log_level debug
require_certificate false

# postgress options:
auth_opt_backends postgres
auth_opt_pg_host postgres
auth_opt_pg_port 5432
auth_opt_pg_dbname API
auth_opt_pg_user mqtt_user
auth_opt_pg_password mqtt_pass

# hash options:
auth_opt_pg_hasher bcrypt
auth_opt_pg_hasher_salt_size 16           # salt bytes length


# ssl
auth_opt_pg_sslmode disable

# auth options
auth_opt_pg_connect_tries 5
auth_opt_pg_userquery select password from MqttUser where login = $1 limit 1
auth_opt_pg_superquery select count(*) from test_user where username = $1 and is_admin = true

Here is my docker compose:

version: "3.9"
services:
  postgres:
    container_name: postgres_container
    image: postgres:14.8-alpine3.18
    command:
      - "postgres"
      - "-c"
      - "max_connections=50"
      - "-c"
      - "shared_buffers=1GB"
      - "-c"
      - "effective_cache_size=4GB"
      - "-c"
      - "work_mem=16MB"
      - "-c"
      - "maintenance_work_mem=512MB"
      - "-c"
      - "random_page_cost=1.1"
      - "-c"
      - "temp_file_limit=10GB"
      - "-c"
      - "log_min_duration_statement=200ms"
      - "-c"
      - "idle_in_transaction_session_timeout=10s"
      - "-c"
      - "lock_timeout=1s"
      - "-c"
      - "statement_timeout=60s"
      - "-c"
      - "shared_preload_libraries=pg_stat_statements"
      - "-c"
      - "pg_stat_statements.max=10000"
      - "-c"
      - "pg_stat_statements.track=all"
    environment:
      POSTGRES_DB: ${DATABASE_NAME}
      POSTGRES_USER: ${DATABASE_USER}
      POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
      PGDATA: "/var/lib/postgresql/data/pgdata"
    volumes:
      - ./postgres-data:/var/lib/postgresql/data
      - ../2. Init Database:/docker-entrypoint-initdb.d
      - ./mosquitto/init-mqtt-auth-db.sh:/docker-entrypoint-initdb.d/init-mqtt-auth-db.sh
    ports:
      - "5432:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DATABASE_USER} -d ${DATABASE_NAME}"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 10s
    restart: unless-stopped
    deploy:
      resources:
        limits:
          cpus: '1'
          memory: 4G
    networks:
      - postgres

  pgadmin:
    container_name: pgadmin_container
    image: dpage/pgadmin4:7.2
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PG_DEFAULT_EMAIL}
      PGADMIN_DEFAULT_PASSWORD: ${PG_DEFAULT_ADMIN_PASSWORD}
      PGADMIN_CONFIG_SERVER_MODE: "False"
    volumes:
      - pgadmin-data:/var/lib/pgadmin
    ports:
      - "5050:80"
    restart: unless-stopped
    deploy:
      resources:
        limits:
          cpus: '0.5'
          memory: 1G
    networks:
      - postgres

  mqtt-broker:
    image: eclipse-mosquitto:2.0.18
    user: mosquitto
    volumes:
      - ./mosquitto/config/mosquitto.conf:/mosquitto/config/mosquitto.conf
      - ./mosquitto/config/go-auth.so:/mosquitto/config/go-auth.so
      - ./mosquitto/log/mosquitto.log:/mosquitto/log/mosquitto.log
      - data:/mosquitto/data
    ports:
      - target: 1883
        published: 1883
        protocol: tcp
        mode: host
      - target: 9001
        published: 9001
        protocol: tcp
        mode: host
    networks:
      - mqtt-net

volumes:
  postgres-data:
  pgadmin-data:
  data:
    name: "mqtt-broker-data"

networks:
  postgres:
    driver: bridge

  mqtt-net:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 172.100.10.0/24

  postgres-data:

When trying to launch docker compose up. I get this error:

Config loaded from /mosquitto/config/mosquitto.conf.
Loading plugin: /mosquitto/config/go-auth.so
Error: Unable to load auth plugin "/mosquitto/config/go-auth.so".
Load error: Error relocating /mosquitto/config/go-auth.so: __fprintf_chk: symbol not found

I think the reason is the lack of an installed golang. But I can't figure out how to install it in my docker compose.

Please help me set up the use of mosquitto-go-auth in my docker compose

1

There are 1 best solutions below

3
hardillb On

The best solution here is to replace the eclipse mosquitto container with the container from the mosquitto-go-auth plugin project.

The pre-built and any binary you build on a glibc based platform (e.g. Ubuntu) is unlikely to run on the Muscl Alpine based eclipse mosquitto container.

Be aware that some of the paths for the config file will change when updating where volumes get mounted in the Docker-compose.yml.