无法使用具有动态安全性的 mosquitto_pub 创建新用户

unable to use mosquitto_pub with dynamic security to create new users

我的问题是为什么我不能使用 mosquitto_pub 创建新用户?

我似乎无法根据此自述文件给出的说明使用 mosquitto_pub 命令在动态安全中创建新用户:

https://github.com/eclipse/mosquitto/blob/master/plugins/dynamic-security/README.md

就我的尝试而言,我首先使用 mosquitto_ctrl 命令成功创建了一个新用户和角色,以确保动态安全性正常工作。然后我尝试了 mosquitto_pub 命令,但失败了。让我在下面提供 mosquitto_ctrl 和 mosquitto_pub 场景的详细信息。

成功:使用mosquitto_ctrl

我创建了一个这样的角色:

mosquitto_ctrl -u steve -P Pass1234 dynsec createRole role0
mosquitto_ctrl -u steve -P Pass1234 dynsec addRoleACL role0 publishClientSend pizza allow
mosquitto_ctrl -u steve -P Pass1234 dynsec addRoleACL role0 subscribeLiteral pizza allow

然后我做了一个这样的用户:

mosquitto_ctrl -u steve -P Pass1234 dynsec createClient user0
mosquitto_ctrl -u steve -P Pass1234 dynsec addClientRole user0 role0 1

我打开一个终端并输入这个命令:

mosquitto_sub -u user0 -P Pass1234 -t chocolate

我打开第二个终端 window 并输入以下命令:

mosquitto_pub -u user0 -P Pass1234 -t chocolate -m 'I love chocolate'

结果是第一个终端窗口打印 'I love chocolate'.

失败:使用mosquitto_pub

由于 role0 已经存在,我想我可以创建一个新用户并将 role0 分配给该用户。 我 运行 这个命令:

mosquitto_pub -u steve -P Pass1234 -t '$CONTROL/dynamic-security/v1' -m '{"command": "createClient", "username":"user1", "password":"Pass1234", "roles":[{"rolename":"role0", "priority":1}]}';

然后我试试这个命令

mosquitto_sub -u user1 -P Pass1234 -t chocolate

结果是 Connection error: Connection Refused: not authorised. 如果我执行 systemctl restart mosquitto.serviceuser0user1 都会得到相同的连接未授权错误。在以上所有实验中,/etc/mosquitto/dynamic-security.json 仅显示客户端 steve 和我在全新安装 mosquitto 2.0 后最初手动设置的 admin 角色。

我明白了。此命令有效:

mosquitto_pub -u steve -P Pass1234 -t '$CONTROL/dynamic-security/v1' -m '{"commands":[{"command": "createClient", "username":"user0", "password":"Pass1234", "roles":[{"rolename":"role0", "priority":1}]}]}';

基本上我需要用 {"commands": ... } 包装我的命令。

而且我还必须确保我在这里纠正了这种情况: