emqx 5.2.0 社区版,不支持 Postgresql 密码认证么?

因初次接触,所以选择 emqx 5.2.0 社区版进行体验。

目标是使用 Postgresql 作为数据库实现 emqx 密码认证。按照 5.2.0 文档进行配置,数据库可以正常连接。

除了数据库连接之外,所有配置包括数据表创建脚本以及初始数据,均按照官网文档创建。

使用,mqttx 进行测试,始终出现“Error: Connection refused: Not authorized”错误。windows 版和 Docker 都试过,均是如此。我也尝试更改加密算法、修改 sql 将 password_hash 映射成 password,依如此。

在 Docker 后台,会看到错误:

2023-09-19 22:25:21 2023-09-19T14:25:21.083065+00:00 [error] msg: postgresql connector do sql query failed, mfa: emqx_connector_pgsql:on_sql_query/5, line: 255, peername: 172.18.0.1:41984, clientid: mqttx_75da319e_1695133521000, connector: <<"emqx_authn_pgsql:1">>, reason: {error,error,<<"42501">>,insufficient_privilege,<<229,175,185,232,161,168,32,109,113,116,116,95,117,115,101,114,32,230,157,131,233,153,144,228,184,141,229,164,159>>,[{file,<<"aclchk.c">>},{line,<<"3652">>},{routine,<<"aclcheck_error">>},{severity,<<233,148,153,232,175,175>>}]}, sql: <<"emqx_authn_pgsql:1">>, type: prepared_query
2023-09-19 22:25:21 2023-09-19T14:25:21.083209+00:00 [error] msg: unrecoverable_error, mfa: emqx_resource_buffer_worker:handle_query_result_pure/3, line: 890, peername: 172.18.0.1:41984, clientid: mqttx_75da319e_1695133521000, id: <<"emqx_authn_pgsql:1">>, reason: {unrecoverable_error,{error,error,<<"42501">>,insufficient_privilege,<<229,175,185,232,161,168,32,109,113,116,116,95,117,115,101,114,32,230,157,131,233,153,144,228,184,141,229,164,159>>,[{file,<<"aclchk.c">>},{line,<<"3652">>},{routine,<<"aclcheck_error">>},{severity,<<233,148,153,232,175,175>>}]}}
2023-09-19 22:25:21 2023-09-19T14:25:21.083286+00:00 [error] msg: postgresql_query_failed, mfa: emqx_authn_pgsql:authenticate/2, line: 144, peername: 172.18.0.1:41984, clientid: mqttx_75da319e_1695133521000, params: [<<"emqx_u">>], provider: emqx_authn_pgsql, reason: {unrecoverable_error,{error,error,<<"42501">>,insufficient_privilege,<<229,175,185,232,161,168,32,109,113,116,116,95,117,115,101,114,32,230,157,131,233,153,144,228,184,141,229,164,159>>,[{file,<<"aclchk.c">>},{line,<<"3652">>},{routine,<<"aclcheck_error">>},{severity,<<233,148,153,232,175,175>>}]}}, resource: <<"emqx_authn_pgsql:1">>, tag: AUTHN

ACL 表也按照官网说明,增加了相应的表和初始数据。

同样的,改用 Mysql 数据库,按照官网说明配置,就可以很顺利的认证成功。Mysql 也不需要增加 ACL 表

请问,是我在 postgresql 中操作的不对,还是说社区版就不支持 Postgresql?

MQTTX 不支持基于 hash 的盐混淆算法,如果你想要用 MQTTX 进行验证,密码算法应该选用 plain 模式

哈哈,您这个回复还真是有点敷衍。

  1. emqx 自己的用 hash 算法,增强登录的安全性,和 mqttx 有什么关系。
  2. 如果像你所说的 mqttx 不支持 hash,为什么同样配置了 hash 的mysql 可以,postgresql 就不可以?

MySQL 测试

Postgresql Hash 测试

Postgresql Plain 测试

你可以把日志等级设置为 debug, 这个日志级别下会打印出认证的详细信息,可以排查出问什么没有通过认证

行!

2023-09-20 10:35:19 2023-09-20T02:35:19.532294+00:00 [error] msg: postgresql connector do sql query failed, mfa: emqx_connector_pgsql:on_sql_query/5, line: 255, peername: 172.18.0.1:40390, clientid: mqttx_75da319e_1695177319000, connector: <<“emqx_authn_pgsql:1”>>, reason: {error,error,<<“42501”>>,insufficient_privilege,<<229,175,185,232,161,168,32,109,113,116,116,95,117,115,101,114,32,230,157,131,233,153,144,228,184,141,229,164,159>>,[{file,<<“aclchk.c”>>},{line,<<“3652”>>},{routine,<<“aclcheck_error”>>},{severity,<<233,148,153,232,175,175>>}]}, sql: <<“emqx_authn_pgsql:1”>>, type: prepared_query
2023-09-20 10:35:19 2023-09-20T02:35:19.532441+00:00 [error] msg: unrecoverable_error, mfa: emqx_resource_buffer_worker:handle_query_result_pure/3, line: 890, peername: 172.18.0.1:40390, clientid: mqttx_75da319e_1695177319000, id: <<“emqx_authn_pgsql:1”>>, reason: {unrecoverable_error,{error,error,<<“42501”>>,insufficient_privilege,<<229,175,185,232,161,168,32,109,113,116,116,95,117,115,101,114,32,230,157,131,233,153,144,228,184,141,229,164,159>>,[{file,<<“aclchk.c”>>},{line,<<“3652”>>},{routine,<<“aclcheck_error”>>},{severity,<<233,148,153,232,175,175>>}]}}
2023-09-20 10:35:19 2023-09-20T02:35:19.532532+00:00 [error] msg: postgresql_query_failed, mfa: emqx_authn_pgsql:authenticate/2, line: 144, peername: 172.18.0.1:40390, clientid: mqttx_75da319e_1695177319000, params: [<<“emqx_u”>>], provider: emqx_authn_pgsql, reason: {unrecoverable_error,{error,error,<<“42501”>>,insufficient_privilege,<<229,175,185,232,161,168,32,109,113,116,116,95,117,115,101,114,32,230,157,131,233,153,144,228,184,141,229,164,159>>,[{file,<<“aclchk.c”>>},{line,<<“3652”>>},{routine,<<“aclcheck_error”>>},{severity,<<233,148,153,232,175,175>>}]}}, resource: <<“emqx_authn_pgsql:1”>>, tag: AUTHN


这个报错是 PG 返回的,你连接 PG 的用户似乎没有权限操作这个表,操作被 PG 拒绝了