Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mysql plugin auth error #564

Closed
foolbear opened this issue May 24, 2016 · 10 comments
Closed

mysql plugin auth error #564

foolbear opened this issue May 24, 2016 · 10 comments
Assignees
Labels
Milestone

Comments

@foolbear
Copy link

foolbear commented May 24, 2016

11:10:00.176 <0.18327.0> [info] Client(CocoaMQTT-Sheep-1374-83@101.231.197.86:61741): RECV CONNECT(Q0, R0, D0, ClientId=CocoaMQTT-Sheep-1374-83, ProtoName=MQTT, ProtoVsn=4, CleanSess=true, KeepAlive=90, Username=foolbear, Password=******, Will(Q1, R0, Topic=/will, Msg=dieout))
11:10:00.176 <0.13355.0> [error] gen_server <0.13355.0> terminated with reason: no case clause matching {error,closed} in mysql_protocol:fetch_response/5 line 307
11:10:00.177 <0.13355.0> [error] CRASH REPORT Process <0.13355.0> with 0 neighbours exited with reason: no case clause matching {error,closed} in mysql_protocol:fetch_response/5 line 307 in gen_server:terminate/7 line 826
11:10:00.177 <0.18327.0> [error] Client(CocoaMQTT-Sheep-1374-83@101.231.197.86:61741): Username 'foolbear' login failed for {{{case_clause,{error,closed}},[{mysql_protocol,fetch_response,5,[{file,"src/mysql_protocol.erl"},{line,307}]},{mysql,handle_call,3,[{file,"src/mysql.erl"},{line,556}]},{gen_server,try_handle_call,4,[{file,"gen_server.erl"},{line,629}]},{gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,661}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,240}]}]},{gen_server,call,[<0.13355.0>,{query,"select password from mqtt_user where username = 'foolbear' limit 1"},infinity]}}
11:10:00.178 <0.18327.0> [info] Client(CocoaMQTT-Sheep-1374-83@101.231.197.86:61741): SEND CONNACK(Q0, R0, D0, AckFlags=0, RetainCode=4)
@emqplus
Copy link
Contributor

emqplus commented May 25, 2016

hi @foolbear, did you configure the mysql parameters in plugins/emqttd_plugin_mysql/etc/plugin.config?

@emqplus emqplus self-assigned this May 25, 2016
@emqplus emqplus added this to the 1.2 milestone May 25, 2016
@foolbear
Copy link
Author

foolbear commented May 26, 2016

this is my config file:

[root@iZ25ziwfw0bZ foolbear]# less emqttd/plugins/emqttd_plugin_mysql/etc/plugin.config
[

  {emqttd_plugin_mysql, [

    {mysql_pool, [
        %% ecpool options
        {pool_size, 8},
        {auto_reconnect, 3},

        %% mysql options
        {host,     "localhost"},
        {port,     3306},
        {user,     "root"},
        {password, "VeryComplex99"},
        {database, "emqtt"},
        {encoding, utf8}
    ]},

    %% select password only
    {authquery, "select password from mqtt_user where username = '%u' limit 1"},

    %% hash algorithm: plain, md5, sha, sha256, pbkdf2?
    {password_hash, sha256},

    %% select password with salt
    %% {authquery, "select password, salt from mqtt_user where username = '%u'"},

    %% sha256 with salt prefix
    %% {password_hash, {salt, sha256}},

    %% sha256 with salt suffix
    %% {password_hash, {sha256, salt}},

    %% comment this query, the acl will be disabled
    {aclquery, "select allow, ipaddr, username, clientid, access, topic from mqtt_acl where ipaddr = '%a' or username = '%u' or username = '$all' or clientid = '%c'"},

    %% If no rules matched, return...
    {acl_nomatch, allow}

  ]}

].

@kenpeter
Copy link

select password from mqtt_user where username = '%u' limit 1, is the password in sha256?

@foolbear
Copy link
Author

Yes, password field in mysql table mqtt_user is encoded by sha256.
Error occurs only occasionally, in most cases it works correctly.
For example, error almost occurs every-time when the first client connect to broker.
If auth mod changed from mysql to redis, error never happened.

@emqplus
Copy link
Contributor

emqplus commented May 31, 2016

hi @huangdan, please check the issue.

@foolbear
Copy link
Author

foolbear commented Jun 1, 2016

thanks, @emqplus @huangdan

@huangdan
Copy link
Contributor

@foolbear fix the bug in the next version

@foolbear
Copy link
Author

@huangdan thanks!

@emqplus
Copy link
Contributor

emqplus commented Jun 18, 2016

@foolbear, @kenpeter, the mysql driver has been upgraded to 1.2.0, please pull the last master branch and build.

@emqplus emqplus closed this as completed Jun 18, 2016
@emqplus emqplus modified the milestones: 1.1.2, 1.2 Jun 18, 2016
@foolbear
Copy link
Author

@emqplus @kenpeter thanks!

sufish pushed a commit to sufish/emqttd-didikon that referenced this issue Jul 1, 2016
* upstream/master: (22 commits)
  WSLOG
  rm 'Guide'
  upgrade guide
  upgrade dashboard plugin
  upgrade plugins to 1.1.2
  update docs for emqx/emqx-auth-mysql#13
  1.1.2 - changelog
  fix issue emqx#561 - websocket client's process may leak when no mqtt packets received
  Add emqttd_ws_client_sup
  {simple_one_for_one, 0, 1}
  Add MQTT specs. etc/vm.args: -env ERL_CRASH_DUMP log/emqttd_crash.dump
  typos
  enhance emqttd_client ratelimit handling
  ensure the mqtt listener is started successfully
  Fix issue#599 - Reject empty clientId with non-clean session
  session expired_after 2880 minutes
  Upgrade dashboard plugin
  1.1.2
  upgrade mysql-otp driver to 1.2.0 and fix issue emqx#586, emqx#564, emqx#523, emqx#596
  1.1.2
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants