LDAP
LDAP authentication uses an external LDAP server as the authentication data source, which can store a large amount of data and facilitate integration with external device management systems.
Plugin:
emqx_auth_ldap
TIP
The emqx_auth_ldap plugin also includes ACL feature, which can be disabled via comments. The current version only supports openldap and does not support Microsoft active directory.
LDAP Configuration
To enable LDAP authentication, you need to configure the following in etc/plugins/emqx_auth_ldap.conf:
# etc/plugins/emqx_auth_ldap.confauth.ldap.servers = 127.0.0.1auth.ldap.port = 389auth.ldap.pool = 8## ldap's Binding Distinguished Name (DN)auth.ldap.bind_dn = cn=root,dc=emqx,dc=io## ldap's Binding passwordauth.ldap.bind_password = public## ldap's query timeoutauth.ldap.timeout = 30s## ldap's device distinguished nameauth.ldap.device_dn = ou=device,dc=emqx,dc=io## ldap's matching object classauth.ldap.match_objectclass = mqttUser## ldap's username attribute typeauth.ldap.username.attributetype = uid## ldap's password attribute typeauth.ldap.password.attributetype = userPassword## TLS Configuration item## auth.ldap.ssl.certfile = etc/certs/cert.pem## auth.ldap.ssl.keyfile = etc/certs/key.pem## auth.ldap.ssl.cacertfile = etc/certs/cacert.pem## auth.ldap.ssl.verify = verify_peer## auth.ldap.ssl.fail_if_no_peer_cert = true
LDAP Schema
The data model needs to be configured in the LDAP schema directory. By default, the data model is as follows:
/etc/openldap/schema/emqx.schema
attributetype ( 1.3.6.1.4.1.11.2.53.2.2.3.1.2.3.1.3 NAME 'isEnabled'EQUALITY booleanMatchSYNTAX 1.3.6.1.4.1.1466.115.121.1.7SINGLE-VALUEUSAGE userApplications )attributetype ( 1.3.6.1.4.1.11.2.53.2.2.3.1.2.3.4.1 NAME ( 'mqttPublishTopic' 'mpt' )EQUALITY caseIgnoreMatchSUBSTR caseIgnoreSubstringsMatchSYNTAX 1.3.6.1.4.1.1466.115.121.1.15USAGE userApplications )attributetype ( 1.3.6.1.4.1.11.2.53.2.2.3.1.2.3.4.2 NAME ( 'mqttSubscriptionTopic' 'mst' )EQUALITY caseIgnoreMatchSUBSTR caseIgnoreSubstringsMatchSYNTAX 1.3.6.1.4.1.1466.115.121.1.15USAGE userApplications )attributetype ( 1.3.6.1.4.1.11.2.53.2.2.3.1.2.3.4.3 NAME ( 'mqttPubSubTopic' 'mpst' )EQUALITY caseIgnoreMatchSUBSTR caseIgnoreSubstringsMatchSYNTAX 1.3.6.1.4.1.1466.115.121.1.15USAGE userApplications )objectclass ( 1.3.6.1.4.1.11.2.53.2.2.3.1.2.3.4 NAME 'mqttUser'AUXILIARYMAY ( mqttPublishTopic $ mqttSubscriptionTopic $ mqttPubSubTopic) )objectclass ( 1.3.6.1.4.1.11.2.53.2.2.3.1.2.3.2 NAME 'mqttDevice'SUP topSTRUCTURALMUST ( uid )MAY ( isEnabled ) )objectclass ( 1.3.6.1.4.1.11.2.53.2.2.3.1.2.3.3 NAME 'mqttSecurity'SUP topAUXILIARYMAY ( userPassword $ userPKCS12 $ pwdAttribute $ pwdLockout ) )
The configuration file slapd.conf was edited with reference of Schema:
/etc/openldap/slapd.conf
include /etc/openldap/schema/core.schemainclude /etc/openldap/schema/cosine.schemainclude /etc/openldap/schema/inetorgperson.schemainclude /etc/openldap/schema/ppolicy.schemainclude /etc/openldap/schema/emqx.schemadatabase bdbsuffix "dc=emqx,dc=io"rootdn "cn=root,dc=emqx,dc=io"rootpw {SSHA}eoF7NhNrejVYYyGHqnt+MdKNBh4r1w3Wdirectory /etc/openldap/data
