MunkiWebAdmin2 - Setting up Active Directory

Heads up: this post is from 2016. The tools and versions it covers may have changed since.

Greg Neagle has released early builds of MunkiWebAdmin2 which you can check out here.  MWA2 forgoes reporting and sticks strictly to managing your Munki repository by providing the ability to edit Manifests and pkginfo files through the web.  For reporting, it is highly recommended that you either use Sal or MunkiReport-PHP (both of which are excellent).  In this post however I'm going to highlight setting up Active Directory authentication in MunkiWebAdmin2.  Check below for the process.

To setup Active Directory in MunkiWebAdmin2 we are going to use Greg's start code in the settings.py file and make some modifications. We are also going to add some additional pieces so that the administration site is automatically setup for your groups.

# django ldap auth
USE_LDAP = True
# LDAP authentication support
if USE_LDAP:

    import ldap
    from django_auth_ldap.config import LDAPSearch, ActiveDirectoryGroupType

    # LDAP settings
    AUTH_LDAP_SERVER_URI = 'Your AD Server here using ldaps'
    AUTH_LDAP_PORT = 636 (Default Port for SSL)
    AUTH_LDAP_BIND_DN = 'CN=Account Name,OU=What OU this account is in,DC=domain,DC=local'
    AUTH_LDAP_BIND_PASSWORD = 'password for your bind account'
    AUTH_LDAP_USER_SEARCH = LDAPSearch(
        'OU=OU to search for users in,DC=domain,DC=local',
        ldap.SCOPE_SUBTREE, '(sAMAccountName=%(user)s)')
    AUTH_LDAP_GROUP_SEARCH = LDAPSearch(
        'OU=OU to search for groups in,DC=domain,DC=local',
        ldap.SCOPE_SUBTREE, '(objectClass=*)')
    AUTH_LDAP_GROUP_TYPE = ActiveDirectoryGroupType()
    AUTH_LDAP_FIND_GROUP_PERMS = True
    AUTH_LDAP_GLOBAL_OPTIONS = {
        ldap.OPT_X_TLS_REQUIRE_CERT: False,
        ldap.OPT_REFERRALS: False, }
    AUTH_LDAP_REQUIRE_GROUP = 'CN=Name of Group,OU=OU Group is in,DC=domain,DC=local'
    AUTH_LDAP_ALWAYS_UPDATE_USER = True
    # Cache group memberships for an hour to minimize LDAP traffic
    AUTH_LDAP_CACHE_GROUPS = True
    AUTH_LDAP_GROUP_CACHE_TIMEOUT = 3600
    AUTH_LDAP_USER_ATTR_MAP = {'first_name': 'givenName',
                               'last_name': 'sn',
                               'email': 'mail'}
    AUTH_LDAP_USER_FLAGS_BY_GROUP = {
    'is_active': 'CN=Group for Active,OU=Location of Group,DC=domain,DC=local',
    'is_staff': 'CN=Group for Staff,OU=Location of Group,DC=domain,DC=local',
    'is_superuser': 'CN=Group for Superuser,OU=Location of Group,DC=domain,DC=local'
    }

Now let's talk about this code. First of all you want to make sure you are searching for the correct users and groups. Secondly, you want to make sure that you require a certain group membership so not just anyone can log into MunkiWebAdmin. Lastly, The piece at the bottom, we can define who can access what part of administrative console. I like to provide AD integration for the admin console but you can of course use a local account in the Django database as well. In our environment, we actually do not utilize the "is staff" portion and only utilize "is active" and "is superuser" since we are a smaller unit. Now, since "is active" does not have any permissions to start you will want to log into the console with one of your superuser account and provide permissions for those users that login or you can create a local group in Django with the permissions you want and add them to that group.

Also when running MunkiWebAdmin2 with Greg's instructions to use runwsgiserver pay close attention to the logging in the command line as it will provide useful information if your directory authentication is not working. Currently, I am using runwsgiserver as a production way of running MunkiWebAdmin2 since this site is only available internally to 4 people. You can of course specify an SSL certificate and private key to put the site in HTTPS mode which is great. Here is the command to perform that.

python manage.py runwsgiserver host=0.0.0.0 port=8000 ssl_certificate='location of certificate file' ssl_private_key='location of private key file'

So far testing of MunkiWebAdmin2 has been very positive and the ability to edit pkginfo files within the website is great. Also you can now see conditionals when editing manifests. If you have questions or comments please let me know.