代码之家  ›  专栏  ›  技术社区  ›  Nisbo

mqtt代理-aclfile

  •  2
  • Nisbo  · 技术社区  · 7 年前

    我在Debian 9上安装了Mosquetto

    apt-get install mosquitto mosquitto-clients
    

    重新启动 服务mosquitto重新启动

    测试了它

    mosquitto_pub -d -t My/Topic2 -m "Hello MQTT"
    

    无错误消息

    创建了密码

    mosquitto_passwd -c /etc/mosquitto/passwd myUsername
    

    创建了ACL文件

    touch /etc/mosquitto/aclfile
    nano /etc/mosquitto/aclfile
    

    使用此内容:

    # This affects access control for clients with no username.
    topic read myTopic/#
    
    # This only affects clients with username "myUsername".
    user myUsername
    topic myTopic/#
    
    # This affects all clients.
    pattern write $SYS/broker/connection/%c/state
    

    将acl\u文件的路径插入到此文件

    nano /etc/mosquitto/mosquitto.conf
    
    acl_file /etc/mosquitto/aclfile
    password_file /etc/mosquitto/passwd
    

    因此,计划是用户“myUsername”可以在“myTopic”中发布,而所有其他用户(包括来宾)只能阅读。

    我已经在其他服务器上运行了此配置,但在这种情况下出现了问题 第一次测试时,我忘记将password\u文件路径添加到mosquitto。形态 并得到错误:如果我想发布,连接被拒绝 如果我只想订阅

    好的,我解决了这个问题,但现在我可以不使用用户名/密码发布

    对于corse,我重新启动了:

    service mosquitto restart
    

    所以如果我发送

    mosquitto_pub -d -t myTopic/test -m "Access denied is expected"
    

    我没有发现错误,看起来消息发布了

    如果我打开第二个shell(也从远程机器打开) 我可以订阅

    mosquitto_sub -d -t myTopic/test
    

    但是,如果我将某个内容发布到此主题,则不会收到任何内容(Ping正在工作)

    对我的两个问题有什么想法吗?

    PS:我不是Linux专业人士 因此,如果您需要更多信息,请向我提供正确的信息如何获取这些信息

    编辑:如果我使用

    ps -efc 
    

    这是mosquitto的唯一入口

    mosquit+ 736 1 TS 19 21:36 ? 00:00:02 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
    

    在日志中

    nano /var/log/mosquitto/mosquitto.log
    

    我明白了

    ACL denying access to client with dangerous client id "mosqpub/7977-Debian-93-"
    ACL denying access to client with dangerous client id "mosqpub/356-h2700629"
    

    但对于谷歌来说,这应该已经在去年解决了

    我正在使用Mosquetto版本1.4.10

    2 回复  |  直到 7 年前
        1
  •  1
  •   hardillb    7 年前

    当不允许用户发布到主题时,发布将自动失败。这是为MQTT设计的(至少是MQTT v3.x)。

    您可能还需要添加 allow_anonymous false 如果要阻止未传递用户名/密码的客户端。

    要获取mosquitto的最新版本,请按照上的说明操作 https://mosquitto.org/download/ 安装正确的ppa

        2
  •  0
  •   Christian Fritz    4 年前

    遇到同样的问题,发现是关于 / 在用户名/客户端id中。来自 https://github.com/eclipse/mosquitto/blob/5c45bc4e8407d94d29b39152b580d2b4cc8082e9/src/security.c#L609-L610 :

    /* Check whether the client id or username contains a +, # or / and if
     * so deny access.
    

    删除“/”使其再次工作。

    推荐文章
    Nisbo  ·  mqtt代理-aclfile
    7 年前
    Jono  ·  Go例程及其并发问题
    10 年前