Password Authentication
Password authentication is the primary authentication method in current production usage.
It verifies client identity using username and password.
Configuration
Set authn_type = "password_based" and configure a storage backend in storage_config.
When using MySQL, the config should align with the MysqlConfig structure:
rust
pub struct MysqlConfig {
pub mysql_addr: String,
pub database: String,
pub username: String,
pub password: String,
pub query_user: String,
pub query_acl: String,
pub query_blacklist: String,
}Field meanings:
mysql_addr: MySQL endpoint (for example127.0.0.1:3306)database: database nameusername/password: database credentialsquery_user: SQL used to sync user data (core auth source)query_acl: SQL used to sync ACL dataquery_blacklist: SQL used to sync blacklist data
Password authentication does not require a fixed table schema.
The key requirement is that query results match the expected mapping contract.
Supported storage backends:
- Built-in data source (Meta Service)
- MySQL
- PostgreSQL
- Redis
- HTTP
See storage-specific details:
- Data Source Overview
- Built-in Data Source (Meta Service)
- MySQL Data Source
- PostgreSQL Data Source
- Redis Data Source
- HTTP Data Source
Usage
- Enable
password_basedin broker auth config. - Configure the selected backend.
- Client sends
username/passwordin CONNECT. - On success, broker proceeds to session and authorization flow.
Example
toml
[[mqtt.auth]]
authn_type = "password_based"
[mqtt.auth.config.storage_config]
storage_type = "mysql"
[mqtt.auth.config.storage_config.mysql_config]
mysql_addr = "127.0.0.1:3306"
database = "mqtt"
username = "root"
password = "123456"
query_user = "SELECT username AS username, password AS password, salt AS salt, is_superuser AS is_superuser, created AS created FROM user_table"
query_acl = "SELECT permission AS permission, ipaddr AS ipaddr, username AS username, clientid AS clientid, access AS access, topic AS topic FROM acl_table"
query_blacklist = "SELECT blacklist_type AS blacklist_type, resource_name AS resource_name, end_time AS end_time, `desc` AS `desc` FROM blacklist_table"Notes
- Disable password-free login in production.
- Keep auth cache hit rate high for better CONNECT latency.
- Ensure query result columns and types follow expected contracts.
