我正在研究Mosquitto并计划使用Redis作为后端来处理用户名/密码对身份验证和ACL。我正在使用JPmens'身份验证插件来执行此操作。
mosquitto 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-
因此,每当我尝试pub / sub mosquitto验证用户但不允许发布和断开用户时。
测试:
mosquitto_pub -p 1884 -t "test" -m "demo" -u user1 -P xyz
对于sub:
mosquitto_sub -p 1884 -t "test" -u user1 -P xyz
答案 0 :(得分:0)
好的,我已经解决了这个问题。
您提供的日志中缺少重要信息。您应该包含以下行:
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