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:

  1. 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:

  1. # etc/plugins/emqx_auth_ldap.conf
  2. auth.ldap.servers = 127.0.0.1
  3. auth.ldap.port = 389
  4. auth.ldap.pool = 8
  5. ## ldap's Binding Distinguished Name (DN)
  6. auth.ldap.bind_dn = cn=root,dc=emqx,dc=io
  7. ## ldap's Binding password
  8. auth.ldap.bind_password = public
  9. ## ldap's query timeout
  10. auth.ldap.timeout = 30s
  11. ## ldap's device distinguished name
  12. auth.ldap.device_dn = ou=device,dc=emqx,dc=io
  13. ## ldap's matching object class
  14. auth.ldap.match_objectclass = mqttUser
  15. ## ldap's username attribute type
  16. auth.ldap.username.attributetype = uid
  17. ## ldap's password attribute type
  18. auth.ldap.password.attributetype = userPassword
  19. ## TLS Configuration item
  20. ## auth.ldap.ssl.certfile = etc/certs/cert.pem
  21. ## auth.ldap.ssl.keyfile = etc/certs/key.pem
  22. ## auth.ldap.ssl.cacertfile = etc/certs/cacert.pem
  23. ## auth.ldap.ssl.verify = verify_peer
  24. ## 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

  1. attributetype ( 1.3.6.1.4.1.11.2.53.2.2.3.1.2.3.1.3 NAME 'isEnabled'
  2. EQUALITY booleanMatch
  3. SYNTAX 1.3.6.1.4.1.1466.115.121.1.7
  4. SINGLE-VALUE
  5. USAGE userApplications )
  6. attributetype ( 1.3.6.1.4.1.11.2.53.2.2.3.1.2.3.4.1 NAME ( 'mqttPublishTopic' 'mpt' )
  7. EQUALITY caseIgnoreMatch
  8. SUBSTR caseIgnoreSubstringsMatch
  9. SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
  10. USAGE userApplications )
  11. attributetype ( 1.3.6.1.4.1.11.2.53.2.2.3.1.2.3.4.2 NAME ( 'mqttSubscriptionTopic' 'mst' )
  12. EQUALITY caseIgnoreMatch
  13. SUBSTR caseIgnoreSubstringsMatch
  14. SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
  15. USAGE userApplications )
  16. attributetype ( 1.3.6.1.4.1.11.2.53.2.2.3.1.2.3.4.3 NAME ( 'mqttPubSubTopic' 'mpst' )
  17. EQUALITY caseIgnoreMatch
  18. SUBSTR caseIgnoreSubstringsMatch
  19. SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
  20. USAGE userApplications )
  21. objectclass ( 1.3.6.1.4.1.11.2.53.2.2.3.1.2.3.4 NAME 'mqttUser'
  22. AUXILIARY
  23. MAY ( mqttPublishTopic $ mqttSubscriptionTopic $ mqttPubSubTopic) )
  24. objectclass ( 1.3.6.1.4.1.11.2.53.2.2.3.1.2.3.2 NAME 'mqttDevice'
  25. SUP top
  26. STRUCTURAL
  27. MUST ( uid )
  28. MAY ( isEnabled ) )
  29. objectclass ( 1.3.6.1.4.1.11.2.53.2.2.3.1.2.3.3 NAME 'mqttSecurity'
  30. SUP top
  31. AUXILIARY
  32. MAY ( userPassword $ userPKCS12 $ pwdAttribute $ pwdLockout ) )

The configuration file slapd.conf was edited with reference of Schema:

/etc/openldap/slapd.conf

  1. include /etc/openldap/schema/core.schema
  2. include /etc/openldap/schema/cosine.schema
  3. include /etc/openldap/schema/inetorgperson.schema
  4. include /etc/openldap/schema/ppolicy.schema
  5. include /etc/openldap/schema/emqx.schema
  6. database bdb
  7. suffix "dc=emqx,dc=io"
  8. rootdn "cn=root,dc=emqx,dc=io"
  9. rootpw {SSHA}eoF7NhNrejVYYyGHqnt+MdKNBh4r1w3W
  10. directory /etc/openldap/data