
本镜像为集成了mosquitto-go-auth插件的Mosquitto MQTT broker。mosquitto-go-auth是一个用Go语言编写的认证与授权插件,通过cgo与Mosquitto交互,支持多种后端存储,为MQTT broker提供用户认证、超级用户检查和访问控制列表(ACL)验证功能。插件兼容Mosquitto 2.0及以上版本,适用于需要灵活认证授权机制的MQTT部署场景。
插件实现了以下后端,每个后端均支持用户认证、超级用户检查和ACL验证,并包含完整测试:
prefix_username),指定特定后端处理认证请求镜像启动需挂载Mosquitto配置文件(通常为mosquitto.conf),并在配置中指定插件路径及后端。示例配置片段:
conf# 加载插件 auth_plugin /etc/mosquitto/go-auth.so # 启用的后端(按优先级排序) auth_opt_backends files,postgres,jwt # 通用缓存配置 auth_opt_cache true auth_opt_cache_type redis auth_opt_auth_cache_seconds 30 auth_opt_acl_cache_seconds 30 # 哈希算法配置(全局) auth_opt_hasher bcrypt auth_opt_hasher_cost 10
缓存配置
| 选项 | 说明 | 默认值 |
|---|---|---|
auth_opt_cache | 是否启用缓存 | false |
auth_opt_cache_type | 缓存类型(go-cache/redis) | go-cache |
auth_opt_auth_cache_seconds | 认证缓存过期时间(秒) | - |
auth_opt_acl_cache_seconds | ACL缓存过期时间(秒) | - |
auth_opt_cache_refresh | 缓存命中时刷新过期时间 | false |
auth_opt_cache_reset | 启动时重置缓存 | false |
哈希配置
支持PBKDF2、Bcrypt、Argon2ID,以Bcrypt为例:
confauth_opt_hasher bcrypt auth_opt_hasher_cost 12 # 计算强度(4-31)
日志配置
confauth_opt_log_level info # 日志级别:debug/info/warn/error/fatal/panic auth_opt_log_dest file # 输出目标:stderr/stdout/file auth_opt_log_file /var/log/mosquitto/auth.log # 文件路径(仅file模式)
Files后端
通过静态文件实现认证与授权:
confauth_opt_files_password_path /etc/mosquitto/passwords.txt # 密码文件路径 auth_opt_files_acl_path /etc/mosquitto/acls.txt # ACL文件路径
密码文件格式(PBKDF2哈希示例):
user1:PBKDF2$sha512$100000$salt$hash user2:PBKDF2$sha512$100000$salt$hash
ACL文件格式(遵循Mosquitto语法):
user user1 topic write sensor/temp topic read sensor/humidity user user2 topic read sensor/#
PostgreSQL后端
通过数据库查询实现认证:
confauth_opt_pg_host postgres auth_opt_pg_port 5432 auth_opt_pg_user dbuser auth_opt_pg_password dbpass auth_opt_pg_dbname mqtt_auth auth_opt_pg_userquery "SELECT password FROM users WHERE username = $1" # 用户查询 auth_opt_pg_aclquery "SELECT topic FROM acls WHERE username = $1 AND access = $2" # ACL查询
单容器部署
bashdocker run -d \ --name mosquitto-go-auth \ -p 1883:1883 \ # MQTT端口 -v $(pwd)/mosquitto.conf:/etc/mosquitto/mosquitto.conf \ -v $(pwd)/passwords.txt:/etc/mosquitto/passwords.txt \ -v $(pwd)/acls.txt:/etc/mosquitto/acls.txt \ eclipse-mosquitto:2.0 # 假设基础镜像为eclipse-mosquitto:2.0,需预安装插件
Docker Compose(含PostgreSQL后端)
yamlversion: '3' services: mosquitto: image: eclipse-mosquitto:2.0 ports: - "1883:1883" volumes: - ./mosquitto.conf:/etc/mosquitto/mosquitto.conf depends_on: - postgres environment: - AUTH_PLUGIN_PATH=/etc/mosquitto/go-auth.so postgres: image: postgres:13 environment: - POSTGRES_USER=dbuser - POSTGRES_PASSWORD=dbpass - POSTGRES_DB=mqtt_auth volumes: - postgres_data:/var/lib/postgresql/data volumes: postgres_data:
debug日志级别会泄露敏感信息(如密码、哈希),生产环境必须使用info及以上级别。cache_refresh可能导致权限撤销延迟,建议结合cache_seconds合理设置过期时间。auth_opt_backends配置顺序依次检查,首个通过验证的后端生效。插件遵循MIT许可证,Mosquitto遵循EPL/EDL许可证。详细信息参见https://github.com/iegomez/mosquitto-go-auth%E3%80%82
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。



探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录认证访问私有仓库
无需登录使用专属域名
Kubernetes 集群配置 Containerd
K3s 轻量级 Kubernetes 镜像加速
VS Code Dev Containers 配置
Podman 容器引擎配置
HPC 科学计算容器配置
ghcr、Quay、nvcr 等镜像仓库
Harbor Proxy Repository 对接专属域名
Portainer Registries 加速拉取
Nexus3 Docker Proxy 内网缓存
需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单
docker search 限制
站内搜不到镜像
离线 save/load
插件要用 plugin install
WSL 拉取慢
安全与 digest
新手拉取配置
镜像合规机制
manifest unknown
no matching manifest(架构)
invalid tar header(解压)
TLS 证书失败
DNS 超时
域名连通性排查
410 Gone 排查
402 与流量用尽
401 认证失败
429 限流
D-Bus 凭证提示
413 与超大单层
来自真实用户的反馈,见证轩辕镜像的优质服务