From aa57ea9ee120eb7db6ac90ba822e0fe76bf7808d Mon Sep 17 00:00:00 2001 From: Kjell Winblad Date: Wed, 8 Mar 2023 18:06:36 +0100 Subject: [PATCH] fix: mongodb authz crash This fixes a crash with an error in the log file (see below) that happened when the MongoDB authorization module queried the database. The reason is that the collection name that was sent to the mongodb connection was an atom. This is fixed by making sure it is not an atom. 2023-03-08T17:16:34.215523+01:00 [error] msg: query_mongo_error, mfa: emqx_authz_mongodb:authorize/4, line: 95, peername: 127.0.0.1:53212, clientid: client123, collection: mqtt_acl, filter: #{username => <<"emqx_u">>}, reason: {resource_error,#{msg => #{error => {error,{error_cannot_parse_response,{op_msg_response,#{<<"code">> => 73,<<"codeName">> => <<"InvalidNamespace">>,<<"errmsg">> => <<"Failed to parse namespace element">>,<<"ok">> => 0.0}}}},id => <<"emqx_authz_mongodb:3">>,name => call_query,request => {find,mqtt_acl,#{username => <<"emqx_u">>},#{}},stacktrace => [{mc_connection_man,reply,1,[{file,"mc_connection_man.erl"},{line,123}], ...]}, reason => exception}}, resource_id: <<"emqx_authz_mongodb:3">> Fixes: https://github.com/emqx/emqx/issues/9783 --- apps/emqx_authz/src/emqx_authz_schema.erl | 2 +- changes/ce/fix-10098.en.md | 1 + changes/ce/fix-10098.zh.md | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changes/ce/fix-10098.en.md create mode 100644 changes/ce/fix-10098.zh.md diff --git a/apps/emqx_authz/src/emqx_authz_schema.erl b/apps/emqx_authz/src/emqx_authz_schema.erl index e68ab3a50..b15d4abd4 100644 --- a/apps/emqx_authz/src/emqx_authz_schema.erl +++ b/apps/emqx_authz/src/emqx_authz_schema.erl @@ -240,7 +240,7 @@ http_common_fields() -> mongo_common_fields() -> [ {collection, - ?HOCON(atom(), #{ + ?HOCON(binary(), #{ required => true, desc => ?DESC(collection) })}, diff --git a/changes/ce/fix-10098.en.md b/changes/ce/fix-10098.en.md new file mode 100644 index 000000000..61058da0a --- /dev/null +++ b/changes/ce/fix-10098.en.md @@ -0,0 +1 @@ +A crash with an error in the log file that happened when the MongoDB authorization module queried the database has been fixed. diff --git a/changes/ce/fix-10098.zh.md b/changes/ce/fix-10098.zh.md new file mode 100644 index 000000000..6b6d86159 --- /dev/null +++ b/changes/ce/fix-10098.zh.md @@ -0,0 +1 @@ +当MongoDB授权模块查询数据库时,在日志文件中发生的崩溃与错误已经被修复。