![](/img/trans.png)
[英]How to use Redis as back end for mosquitto ACL (JPmens plugin is used)?
[英]How to use redis as a backend for mosquitto ACL
我正在研究 Mosquitto,并计划使用 Redis 作为后端来处理用户名/密码对身份验证和 ACL。 我正在使用 JPmens 的身份验证插件来执行此操作。
蚊子conf:
auth_opt_backends redis
auth_plugin /etc/mosquitto/auth-plug.so
auth_opt_redis_host 127.0.0.1
auth_opt_redis_port 6379
auth_opt_redis_userquery GET %s
auth_opt_redis_aclquery GET %s-%s
以下名称/密码对适用于身份验证
SET user1 PBKDF2$sha256$901$Qh18ysY4wstXoHhk$g8d2aDzbz3rYztvJiO3dsV698jzECxSg
以下设置不适用于 ACL:
SET user1-test 2
以下是 mosquitto 的日志:
1507037072: Denied PUBLISH from mosqpub/3838-ip-172-31- (d0, q0, r0, m0, 'user1-test', ... (4 bytes))
1507037072: Received DISCONNECT from mosqpub/3838-ip-172-31-
因此,每当我尝试发布/订阅 mosquitto 验证用户但不允许发布和断开用户连接时。
测试:
mosquitto_pub -p 1884 -t "test" -m "demo" -u user1 -P xyz
对于子:
mosquitto_sub -p 1884 -t "test" -u user1 -P xyz
好的,我已经解决了这个问题。
您提供的日志中缺少重要的一点。 您应该包含以下行:
1507135115: ACL denying access to client with dangerous client id "mosqpub/2232-tiefighter"
问题是插件被阻塞,因为客户端 ID 包含一个“/”
以下部分在代码中:
/* We are using pattern based acls. Check whether the username or
* client id contains a +, # or / and if so deny access.
*
* Without this, a malicious client may configure its username/client
* id to bypass ACL checks (or have a username/client id that cannot
* publish or receive messages to its own place in the hierarchy).
*/
解决方案是使用 -i 选项为 mosquitto_sub 和 mosquitto_pub 设置客户端 ID,例如:
mosquitto_pub -p 1884 -t "test" -m "demo" -u user1 -P xyz -i publisher
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.