Search code examples
authenticationactive-directoryldapomniauthdiscourse

ldap filter in omniauth ldap module not working in discourse


I currently try to configure Discourse to only allow users in a specific ldap group to log in. Discourse has a plugin called discourse-ldap auth ( https://github.com/jonmbake/discourse-ldap-auth ). This plugin uses the omniauth ldap module: https://github.com/omniauth/omniauth-ldap

My discourse plugin configuration (the configuration is actually used by the discourse plugin for the omniauth ldap module):

  • ldap enabled: true
  • ldap hostname: the hostname of my ldap server
  • ldap port: 389
  • ldap method: plain
  • ldap base: the base of my ldap server
  • ldap uid: userPrincipalName
  • ldap bind dn: Nothing
  • ldap password: Nothing
  • ldap filter: (&(userPrincipalName=%{username})(memberOf=cn=[the name of the required group],ou=....,[base]))

When using this configuration, nobody can log in to the forum. When I use the bind dn and password, everybody can log in. I also tried this filter without success (copied from my ldap servers filter):

  • (&(&(&(userPrincipalName=%{username})(memberOf=[dn of the group]))))

What do I have to configure, to only allow users in that specific group to log in?

I didn't found any errors or indicators in the log. Please help!

Thanks fou your help and attention!


Solution

  • You do need the "ldap dn" and "ldap password". Those are the credentials used to authenticate to LDAP so you can lookup people's accounts. Usually, that is a service account only used by your application.

    The filter should probably look something like this:

    (&(sAMAccountName=%{username})(memberOf:1.2.840.113556.1.4.1941:=[dn of the group]))
    

    Users will usually log in with the sAMAccountName, which is usually called just the "username". Whenever you see an account in the DOMAIN\username format, that username is the sAMAccountName.

    The userPrincipalName is usually in the format of [email protected]. It is sometimes the same as the email address, but it doesn't have to be.

    The crazy number I put in that query tells Active Directory to search recursively through groups. So that would allow you to put groups into your authentication group, and members of that new group would be given access to your application too. Without that, only direct members of that group will have access.