有没有办法可以在 Mosquitto MQTT 服务器中拥有匿名用户和经过身份验证的用户?

问题描述 投票:0回答:1

我想做的是

allow_anonymous true
并阻止未经身份验证的用户访问某些主题。

我已经尝试了以下方法,但它似乎不起作用,因为匿名客户端仍然可以连接。

# anonymous users
topic deny /my/topic
# other topics should be fine...

user special
topic readwrite /my/topic
mqtt mosquitto
1个回答
0
投票

以下示例按预期工作:

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
主题

上的消息
© www.soinside.com 2019 - 2024. All rights reserved.