代码之家  ›  专栏  ›  技术社区  ›  Karan Sharma

如何使用redis作为Mosquetto ACL的后端

  •  -1
  • Karan Sharma  · 技术社区  · 8 年前

    我正在开发Mosquetto,并计划使用Redis作为后端来处理用户名/密码对身份验证和ACL。我正在使用JPmens的身份验证插件来实现这一点。

    莫斯奎托形态:

    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
    

    以下是莫斯奎托的日志:

    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-
    

    因此,每当我尝试发布/订阅Mosquit以验证用户,但不允许发布和断开用户连接时。

    测试使用:

    mosquitto_pub -p 1884 -t "test" -m "demo" -u user1 -P xyz 
    

    对于sub:

    mosquitto_sub -p 1884 -t "test" -u user1 -P xyz
    
    1 回复  |  直到 8 年前
        1
  •  0
  •   hardillb    8 年前

    好的,我已经解决了。

    您提供的日志中缺少一个重要的部分。您应该包括以下行:

    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\u sub和mosquitto\u pub的客户端id,例如:

    mosquitto_pub -p 1884 -t "test" -m "demo" -u user1 -P xyz -i publisher