Open RongTsai4Git opened 2 years ago
{emqx}/etc/emqx.conf
##--------------------------------------------------------------------
## Authentication/Access Control
##--------------------------------------------------------------------
...
allow_anonymous = false
{emqx}/etc/bin/emqx_auth_pgsql.conf
auth.pgsql.server = 192.168.100.58:5432
auth.pgsql.username = postgres
auth.pgsql.password = postgres
auth.pgsql.database = postgres
auth.pgsql.password_hash = sha256
Postgres
# Create Auth table
CREATE TABLE mqtt_user (
id SERIAL primary key,
is_superuser boolean,
username character varying(100),
password character varying(100),
salt character varying(40)
)
INSERT INTO mqtt_user (username, password, salt, is_superuser) VALUES ('device1', '70a17135894291fcf2bf7dd88986cb44583fa8b224c4c9d85c071889a6164127', NULL, false), ('device2', '2490451915aafc6cebdfbe419fb3cc3e9db6bfb35e1f56847e686dae9d4cf5e4', NULL, false);
* emqx_ctl plugins load emqx_auth_pgsql
![image](https://user-images.githubusercontent.com/89722047/151113942-40f5c089-96cb-4f7f-ae40-ed91c5fd718d.png)
* reload acl
emqx_ctl acl reload
* reference
[auth-postgresql](https://www.emqx.io/docs/en/v4.3/advanced/auth-postgresql.html#default-table-structure)
## if no ACL rules matched -> deny
acl_nomatch = deny
acl_deny_action = disconnect
zone.internal.acl_deny_action = disconnect zone.external.acl_deny_action = disconnect
## 這裡的預設值要修改掉,因為會影響到在 postgre 設定的規則
%% {deny, all, subscribe, ["$SYS/#", {eq, "#"}]}.
...
%% {allow, all}.
* postgres
CREATE TABLE mqtt_acl ( id SERIAL primary key, allow integer, ipaddr character varying(60), username character varying(100), clientid character varying(100), access integer, topic character varying(100) )
INSERT INTO mqtt_acl (allow, ipaddr, username, clientid, access, topic) VALUES (1,NULL,'device1',NULL,2,'device/1/telemetry'), (1,NULL,'device2',NULL,1,'device/1/telemetry');
* 不需要重開 emqx !
* reference
[emqx_auth_pgsql](https://github.com/emqx/emqx-auth-pgsql)
直接參考這裡就可以直接架起來了
重點
Reference Configuration