簡體   English   中英

mqtt 代理 - aclfile

[英]mqtt broker - aclfile

我在 Debian 9 上安裝了 mosquitto

apt-get install mosquitto mosquitto-clients

做了一個 Re-Start 服務 mosquitto restart

測試了

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_file 的路徑插入此文件

nano /etc/mosquitto/mosquitto.conf

acl_file /etc/mosquitto/aclfile
password_file /etc/mosquitto/passwd

所以計划是用戶“myUsername”可以在“myTopic”中發布,而包括來賓在內的所有其他用戶只能閱讀。

我已經在另一台服務器上運行了此配置,但在這種情況下出現問題我第一次測試時忘記將 password_file 路徑添加到 mosquitto.conf 並收到錯誤:如果我想要連接被拒絕,如果我想要也發布只訂閱

好的,我解決了這個問題,但現在我可以在沒有用戶名/密碼的情況下發布

和 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"

但關於谷歌,這應該已經在去年修復了

我正在使用 mosquitto 版本 1.4.10

當不允許用戶發布到主題時,發布只會默默地失敗。 這是為 MQTT 設計的(至少在 MQTT v3.x 中)。

如果您想阻止不傳遞用戶名/密碼的客戶端,您可能還需要添加allow_anonymous false

要獲取最新版本的 mosquitto,請按照https://mosquitto.org/download/上的說明安裝正確的 ppa

遇到同樣的問題,並發現它是關於/的用戶名/客戶端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.

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM