emqx / emqx-auth-mongo

EMQX Authentication/ACL with MongoDB
https://emqx.io/
Apache License 2.0
21 stars 26 forks source link

[Hooks] Failed to execute fun emqx_auth_mongo:check/3 #237

Open Gengxin-Zhang opened 3 years ago

Gengxin-Zhang commented 3 years ago

i am trying to setup an emqx cluster by docker, I've configured my EMQX docker container as follows:

EMQX_AUTH__MONGO__AUTH_QUERY__COLLECTION: 'devices'
EMQX_AUTH__MONGO__AUTH_QUERY__PASSWORD_FIELD: 'secret'
EMQX_AUTH__MONGO__AUTH_QUERY__PASSWORD_HASH: 'plain'
EMQX_AUTH__MONGO__AUTH_QUERY__SELECTOR: 'broker_username=%u'

when I use right username and password to connect emqx, i got this error:

(929bf93a4f9c@172.21.0.4)1> 2020-10-12 03:04:31.734 [error] <<"mqttx_19d22a83">>@172.21.0.1:54300 [Hooks] Failed to execute {fun emqx_auth_mongo:check/3,[#{authquery => {authquery,<<"devices">>,[<<"secret">>],plain,[{<<"broker_username">>,<<"%u">>}]},pool => emqx_auth_mongo,superquery => {superquery,<<"mqtt_user">>,<<"is_superuser">>,[{<<"username">>,<<"%u">>}]}}]}: {{badmap,undefined},[{maps,get,[<<"is_superuser">>,undefined,false],[{file,"maps.erl"},{line,187}]},{emqx_auth_mongo,is_superuser,3,[{file,"/emqx-rel/_checkouts/emqx_auth_mongo/src/emqx_auth_mongo.erl"},{line,91}]},{emqx_auth_mongo,check,3,[{file,"/emqx-rel/_checkouts/emqx_auth_mongo/src/emqx_auth_mongo.erl"},{line,64}]},{emqx_hooks,safe_execute,2,[{file,"/emqx-rel/_checkouts/emqx/src/emqx_hooks.erl"},{line,164}]},{emqx_hooks,do_run_fold,3,[{file,"/emqx-rel/_checkouts/emqx/src/emqx_hooks.erl"},{line,143}]},{emqx_access_control,authenticate,1,[{file,"/emqx-rel/_checkouts/emqx/src/emqx_access_control.erl"},{line,77}]},{emqx_channel,auth_connect,2,[{file,"/emqx-rel/_checkouts/emqx/src/emqx_channel.erl"},{line,1172}]},{emqx_misc,pipeline,3,[{file,"/emqx-rel/_checkouts/emqx/src/emqx_misc.erl"},{line,107}]}]}
(929bf93a4f9c@172.21.0.4)1> 2020-10-12 03:04:31.736 [warning] <<"mqttx_19d22a83">>@172.21.0.1:54300 [Channel] Client mqttx_19d22a83 (Username: 'test') login failed for not_authorized

Is this a bug or am i having a configuration error? I also checked the other issues on that, but their solutions didnt work for me...

Thanks a lot!

wwhai commented 3 years ago

i am trying to setup an emqx cluster by docker, I've configured my EMQX docker container as follows:

EMQX_AUTH__MONGO__AUTH_QUERY__COLLECTION: 'devices'
EMQX_AUTH__MONGO__AUTH_QUERY__PASSWORD_FIELD: 'secret'
EMQX_AUTH__MONGO__AUTH_QUERY__PASSWORD_HASH: 'plain'
EMQX_AUTH__MONGO__AUTH_QUERY__SELECTOR: 'broker_username=%u'

when I use right username and password to connect emqx, i got this error:

(929bf93a4f9c@172.21.0.4)1> 2020-10-12 03:04:31.734 [error] <<"mqttx_19d22a83">>@172.21.0.1:54300 [Hooks] Failed to execute {fun emqx_auth_mongo:check/3,[#{authquery => {authquery,<<"devices">>,[<<"secret">>],plain,[{<<"broker_username">>,<<"%u">>}]},pool => emqx_auth_mongo,superquery => {superquery,<<"mqtt_user">>,<<"is_superuser">>,[{<<"username">>,<<"%u">>}]}}]}: {{badmap,undefined},[{maps,get,[<<"is_superuser">>,undefined,false],[{file,"maps.erl"},{line,187}]},{emqx_auth_mongo,is_superuser,3,[{file,"/emqx-rel/_checkouts/emqx_auth_mongo/src/emqx_auth_mongo.erl"},{line,91}]},{emqx_auth_mongo,check,3,[{file,"/emqx-rel/_checkouts/emqx_auth_mongo/src/emqx_auth_mongo.erl"},{line,64}]},{emqx_hooks,safe_execute,2,[{file,"/emqx-rel/_checkouts/emqx/src/emqx_hooks.erl"},{line,164}]},{emqx_hooks,do_run_fold,3,[{file,"/emqx-rel/_checkouts/emqx/src/emqx_hooks.erl"},{line,143}]},{emqx_access_control,authenticate,1,[{file,"/emqx-rel/_checkouts/emqx/src/emqx_access_control.erl"},{line,77}]},{emqx_channel,auth_connect,2,[{file,"/emqx-rel/_checkouts/emqx/src/emqx_channel.erl"},{line,1172}]},{emqx_misc,pipeline,3,[{file,"/emqx-rel/_checkouts/emqx/src/emqx_misc.erl"},{line,107}]}]}
(929bf93a4f9c@172.21.0.4)1> 2020-10-12 03:04:31.736 [warning] <<"mqttx_19d22a83">>@172.21.0.1:54300 [Channel] Client mqttx_19d22a83 (Username: 'test') login failed for not_authorized

Is this a bug or am i having a configuration error? I also checked the other issues on that, but their solutions didnt work for me...

Thanks a lot!

Did your resolved yet?

chenquan commented 3 years ago

@Gengxin-Zhang I met too. Have you solved it?

HJianBo commented 3 years ago

It is a BUG actually. We will try to fix it in the later version.

In 4.2.3, you can disable the supuser query with:

EMQX_AUTH__MONGO__SUPER_QUERY__COLLECTION: ''