emqx
emqx copied to clipboard
authn plugin always show me cannot get cannot_get_variable username
What happened?
as title, using 5.03 version
2022-07-29T14:16:02.827000+08:00 [warning] authenticator: <<"password_based:postgresql">>, clientid: client1, exception: error, line: 660, mfa: emqx_authentication:do_authenticate/3, msg: unexpected_error_in_authentication, peername: 127.0.0.1:65125, reason: {cannot_get_variable,<<"username">>}, stacktrace: [{emqx_authn_utils,handle_sql_var,2,[{file,"emqx_authn_utils.erl"},{line,214}]},{lists,map,2,[{file,"lists.erl"},{line,1243}]},{emqx_authn_pgsql,authenticate,2,[{file,"emqx_authn_pgsql.erl"},{line,118}]},{emqx_authentication,do_authenticate,3,[{file,"emqx_authentication.erl"},{line,633}]},{emqx_authentication,authenticate,2,[{file,"emqx_authentication.erl"},{line,228}]},{emqx_hooks,safe_execute,2,[{file,"emqx_hooks.erl"},{line,200}]},{emqx_hooks,do_run_fold,3,[{file,"emqx_hooks.erl"},{line,180}]},{emqx_access_control,authenticate,1,[{file,"emqx_access_control.erl"},{line,81}]},{emqx_channel,do_authenticate,2,[{file,"emqx_channel.erl"},{line,1697}]},{emqx_channel,handle_in,2,[{file,"emqx_channel.erl"},{line,355}]},{emqx_ws_connection,with_channel,3,[{file,"emqx_ws_connection.erl"},{line,738}]},{cowboy_websocket,handler_call,6,[{file,"cowboy_websocket.erl"},{line,487}]},{proc_lib,wake_up,3,[{file,"proc_lib.erl"},{line,236}]}] this is the error log .use mqttbox and mqtt.js test
What did you expect to happen?
How can we reproduce it (as minimally and precisely as possible)?
No response
Anything else we need to know?
No response
EMQX version
$ ./bin/emqx_ctl broker
# paste output here
OS version
# On Linux:
$ cat /etc/os-release
# paste output here
$ uname -a
# paste output here
# On Windows:
C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture
# paste output here
Log files
authentication { auto_reconnect = true backend = "postgresql" database = "xxx" enable = true mechanism = "password_based" password = "xxx" password_hash_algorithm { dk_length = 16 iterations = 10000 mac_fun = "sha512" name = "pbkdf2" } pool_size = 8 query = "SELECT password_hash FROM rfm.mqtt_users where user_name = ${username} LIMIT 1" server = "127.0.0.1:5432" ssl { ciphers = ["TLS_AES_256_GCM_SHA384", "TLS_AES_128_GCM_SHA256", "TLS_CHACHA20_POLY1305_SHA256", "TLS_AES_128_CCM_SHA256", "TLS_AES_128_CCM_8_SHA256", "ECDHE-ECDSA-AES256-GCM-SHA384", "ECDHE-RSA-AES256-GCM-SHA384", "ECDHE-ECDSA-AES256-SHA384", "ECDHE-RSA-AES256-SHA384", "ECDH-ECDSA-AES256-GCM-SHA384", "ECDH-RSA-AES256-GCM-SHA384", "ECDH-ECDSA-AES256-SHA384", "ECDH-RSA-AES256-SHA384", "DHE-DSS-AES256-GCM-SHA384", "DHE-DSS-AES256-SHA256", "AES256-GCM-SHA384", "AES256-SHA256", "ECDHE-ECDSA-AES128-GCM-SHA256", "ECDHE-RSA-AES128-GCM-SHA256", "ECDHE-ECDSA-AES128-SHA256", "ECDHE-RSA-AES128-SHA256", "ECDH-ECDSA-AES128-GCM-SHA256", "ECDH-RSA-AES128-GCM-SHA256", "ECDH-ECDSA-AES128-SHA256", "ECDH-RSA-AES128-SHA256", "DHE-DSS-AES128-GCM-SHA256", "DHE-DSS-AES128-SHA256", "AES128-GCM-SHA256", "AES128-SHA256", "ECDHE-ECDSA-AES256-SHA", "ECDHE-RSA-AES256-SHA", "DHE-DSS-AES256-SHA", "ECDH-ECDSA-AES256-SHA", "ECDH-RSA-AES256-SHA", "ECDHE-ECDSA-AES128-SHA", "ECDHE-RSA-AES128-SHA", "DHE-DSS-AES128-SHA", "ECDH-ECDSA-AES128-SHA", "ECDH-RSA-AES128-SHA", "RSA-PSK-AES256-GCM-SHA384", "RSA-PSK-AES256-CBC-SHA384", "RSA-PSK-AES128-GCM-SHA256", "RSA-PSK-AES128-CBC-SHA256", "RSA-PSK-AES256-CBC-SHA", "RSA-PSK-AES128-CBC-SHA"] depth = 10 enable = false reuse_sessions = true secure_renegotiate = true user_lookup_fun = "emqx_tls_psk:lookup" verify = "verify_none" versions = ["tlsv1.3", "tlsv1.2", "tlsv1.1", "tlsv1"] } username = "xxx" } config file
Hello,
Maybe the client is anonymous and it doesn't have the username? I am not sure how the template engine handles this case, maybe @savonarola can help?
Hello! I will investgate this.
I tried to improve error messages in #8635.
@shanjunmei do the clients send username field on connect? Looks like clientid and password are only set.
I tried to improve error messages in #8635.
@shanjunmei do the clients send
usernamefield on connect? Looks likeclientidandpasswordare only set.
i can confirm send username & password
@shanjunmei could you please anyhow provide the used MQTT client configuration? For example, client code using mqtt.js or mqttbox screenshots? So that I could reproduce the issue.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.