我想做的是
allow_anonymous true
并阻止未经身份验证的用户访问某些主题。
我已经尝试了以下方法,但它似乎不起作用,因为匿名客户端仍然可以连接。
# anonymous users
topic deny /my/topic
# other topics should be fine...
user special
topic readwrite /my/topic
以下示例按预期工作:
mosquitto.conf
allow_anonymous true
password_file passwd
acl_file acl
listener 1883 0.0.0.0
acl
topic deny foo
topic read #
user user
topic readwrite #
密码
user:$7$101$efdj3nwLSpxELFhx$wB9Hls8c26//DFQdGMxb1gQt1muwNmdCMsbb1EZZjOV7Nc+fpTPVn9avsQQU2TF0gkJ3wXZjoltWrSAhSDLY2g==
匿名用户订阅了
foo
和bar
主题
mosquitto_sub -v -t foo -t bar
bar test-bar
经过身份验证的用户发布到
foo
和 bar
主题
mosquitto_pub -u user -P secret -t foo -m test-foo
mosquitto_pub -u user -P secret -t bar -m test-bar
如您所见,匿名用户只能看到
bar
主题上的消息