Moodle LDAP enrolment by directory group: when your directory should decide course membership
If your university or company already manages students, staff or contractors in Active Directory or OpenLDAP, the LDAP enrolment plugin lets Moodle assign course membership from directory groups instead of from manual clicks. The plugin, which Moodle documents as an enrolment method, reads a group attribute from the directory for each course and enrols or unenrols users with a Moodle role that you map to that group. Choose it when course membership already follows a directory decision, such as a department, a programme cohort or a contractor group, and when someone must be removed from a course automatically once they leave that group. Manual enrolment remains the better choice for small, one-off courses, for external guests who are not in your directory, and for courses where a tutor adds people by hand.
Before you configure anything, confirm three things with your directory team. First, which attribute holds group membership in your directory, and whether groups are nested, because the plugin's handling of nested membership depends on how your directory exposes it and on how you query it. Second, whether the bind account can read those groups over LDAPS and whether the group names are stable enough to use as course keys. Third, who owns each mapping from a directory group to a Moodle course role, since a wrong mapping silently gives students teacher rights. Also check the Moodle version you run and its LDAP documentation for the exact settings present in that release, because option names and defaults change between versions. Plan a test course and a test group first, and confirm that removing a user from the group unenrols them as expected before you point the plugin at live courses.
Configuration options and when each fits
This table compares the main design choices for driving Moodle enrolments from directory groups: direct LDAP enrolment, cohort sync, nested group handling, role mapping and sync frequency. Read each row against your directory structure and how often course membership changes. The main takeaway is that the enrolment method and the group structure should be decided together, before any mapping is built.
| Option | What it controls | When it fits |
|---|---|---|
| Direct LDAP group enrolment | Enrols users straight into courses from a directory group, with the mapped Moodle role applied at each course | Courses map cleanly to existing directory groups and course staff and students are already maintained in AD or LDAP |
| Cohort sync from LDAP | Populates a Moodle cohort from a directory group, then enrols that cohort into one or more courses | Many courses need the same membership, or you want one place in Moodle to see and manage who belongs to a group |
| Direct versus cohort membership | Direct sync ties each course to the directory; cohort sync adds a Moodle-side layer between directory and courses | Choose cohorts when the same population feeds several courses or when administrators need to inspect membership inside Moodle |
| Flat group structure | One directory group maps to one course role, with no inheritance from parent groups | Your directory uses a small number of purpose-built course groups that do not need to be nested |
| Nested group handling | Whether memberships from child groups are counted when a parent group is used; confirm how your Moodle version treats nested membership | Your directory already organizes people in hierarchies, such as departments containing teams, and you need to test whether nesting carries through |
| Role assignment per group | The Moodle course role (for example student or teacher) given to members of each mapped group | Different groups need different permissions, such as a teaching group separate from a learner group, and the mapping must be reviewed against your role policy |
| Sync frequency via scheduled tasks | How often the enrolment and cohort sync tasks run, which sets how quickly joiners, leavers and role changes appear | Membership changes are frequent and access must follow quickly, or changes are infrequent and a longer interval reduces load on the directory |
| Unenrolment behaviour | Whether users removed from a group are unenrolled or left in place when the group no longer matches | Access must be removed promptly for leavers, so confirm the removal setting and test it against a test group before go-live |
Direct LDAP enrolment or cohort sync from LDAP
When each directory group corresponds to exactly one course, direct LDAP enrolment is usually the simpler design. The enrolment plugin reads the membership of a group for each course you configure and assigns the Moodle role you map to it. There is no intermediate object to maintain, so administrators can see the link between the directory group and the course in one place. The trade-off is that every course carries its own mapping, so a change to the pattern means editing each course's configuration.
- Clear ownership: the directory group name and the course enrolment instance sit side by side, which makes audits straightforward.
- Role mapping per course: map the group to a student or teacher role in each course, and confirm that the mapping survives course copies.
- Fewer moving parts: there is no cohort layer to keep in step with the directory.
- Scaling cost: each new course needs its own enrolment instance, which adds administration as the catalogue grows.
- Nested groups: confirm how your Moodle version and the LDAP plugin handle nested membership before you rely on it.
Before you commit, test one course end to end, including an unenrolment, to confirm the removal behaviour matches your policy.
When one directory group feeds many courses, or a site-wide population such as all first-year students needs to appear in several places, a cohort layer is often the better fit. You populate a site cohort from LDAP once, then use cohort sync to enrol that cohort into any course. Membership is maintained in a single place, and new courses inherit the population by adding one enrolment method rather than repeating the LDAP mapping.
- One source of membership: the cohort is the shared list, so a fix made once applies to every course that uses it.
- Reusable across groups: cohorts can combine populations from several directory groups or categories.
- Cohort-based roles: assign the role at the cohort sync step so the same population can be teachers in one course and students in another.
- Extra layer to monitor: you must check both the cohort sync task and the course enrolments that depend on it.
- Cohort size: very large cohorts increase sync time, so ask the implementation team to test realistic volumes.
Check which cohorts feed which courses and document the dependency, so a change to one cohort does not unenrol students from courses nobody expected.
Some environments need course teams to add a learner, or a visiting tutor, without raising a directory ticket. Direct LDAP enrolment treats the directory as the owner of membership, so a manual change in Moodle may be overwritten on the next sync. Cohort sync gives you a middle path: the directory feeds a cohort, while staff can add or remove members of the same cohort or enrol others manually into the course. Decide the ownership rule before rollout, because the answer determines which method you configure.
- Clear ownership rules: write down which records the directory controls and which Moodle users may change.
- Manual enrolment alongside sync: confirm that manual enrolments are not removed by the sync method you choose.
- Permissions for editors: restrict who can manage cohorts, since cohort edits affect every linked course.
- Audit trail: check which changes Moodle logs and whether the logs identify the user or the sync job.
- Unenrolment behaviour: test what happens to manually added users when a directory group changes.
Ask your implementation team to demonstrate an override and a directory removal in a test course before any staff are given editing rights.
Setup sequence for LDAP group enrolment in Moodle
This sequence takes a Moodle site from a working LDAP connection to a scheduled group enrolment sync that has been tested on a pilot group. Each step closes with a check so that removals, role mapping and logging are confirmed before the sync runs unattended.
Confirm the LDAP authentication connection
Before any enrolment work, the LDAP authentication plugin must bind to the directory and find test users. A Moodle administrator configures the server host, LDAPS or StartTLS setting, the bind account and the user contexts under Site administration, then runs the connection test. Use a read-only bind account scoped to the directory branch that holds users and groups. The step is done when a known test user can sign in and the connection test reports success.
Decide the group naming convention
Agree how directory groups map to courses and roles before anything is configured. Settle on a pattern for group names, such as a course code prefix plus a role suffix, and confirm whether group membership is direct only or includes nested groups. Ask the directory team who owns the groups and how they are created. The output is a written naming table that one person can check against the directory, and the step is complete when a sample of real group names matches the table.
Configure the enrolment plugin and role mapping
Enable the LDAP enrolment plugin in Moodle, set the group membership attribute and the course identifier source, and map each directory group pattern to a Moodle course role such as student or teacher. Keep the role list short and document every mapping. Confirm the unenrolment setting so that a user removed from the group is handled as the site intends. The step closes when a dry run or manual test lists the expected enrolments for one course without changing any account.
Test with a pilot course and group
Create one test course and one small directory group with two or three accounts, including one account with a teacher role and one with a student role. Run the enrolment sync manually and check that each account lands in the correct role. Then remove one test account from the directory group, run the sync again, and confirm that the account is unenrolled from the course as configured. Repeat for a nested group if your design uses nesting. The step is done when both the addition and removal behave as the naming table predicts.
Review the enrolment log and fix mismatches
Open the enrolment and task logs after each test run and read every entry for the pilot course. Look for skipped users, unmatched group names, role conflicts and accounts that were suspended rather than unenrolled. Correct the mapping or directory structure, then rerun the test until the log shows only expected actions. Record the findings so that the site team can explain any later change. The step is complete when a rerun produces a clean log for the pilot course.
Schedule the sync task and set its frequency
Once the pilot passes, add the enrolment sync to the scheduled task list and choose a frequency that matches how often the directory changes and how quickly the business needs changes to take effect. Confirm the cron job runs on the server and that a failure sends an alert to the administrator. Ask the directory owner how often group membership changes so the schedule fits real demand. The step is done when a scheduled run completes and its log matches the manual test results.
Roll out in stages and monitor
Extend the mapping from the pilot course to more courses in batches, checking the log after each batch. Watch for accounts that unexpectedly lose access, especially at term boundaries or when directory groups are reorganized. Keep the pilot course and its test group in place as a regression check for future upgrades and configuration changes. The rollout is complete when every planned course is covered and the monitoring routine is documented and assigned to a named owner.
Sync frequency, removals and how unenrolment is handled
Sync frequency is a design decision, not a default to accept. How often Moodle reads LDAP or Active Directory group membership sets the load on your directory servers, how quickly a new hire or a change of role gets course access, and how far behind the directory Moodle's enrolments can drift. Each of those matters to a different owner: the directory team cares about query load from the sync, the faculty or training lead cares about access timing before a course opens, and the auditor cares about whether a course enrolment can be traced to a directory state at a known point in time. Set the interval against all three, and write the reasoning down so the choice can be defended later. Confirm the available schedule options and the sync task settings in the Moodle version you will run, since the exact configuration screens and their defaults change between releases.
Removals are where enrolment syncs cause harm. When a user leaves a directory group, the LDAP enrolment plugin's behavior depends on its configuration. Depending on the settings, Moodle may unenrol the user from the course, suspend the enrolment, or leave the enrolment in place. Leaving it in place is sometimes intended, for example for learners who should keep read access to a completed course, but it is a common source of surprise when a former contractor still sees course materials. Also check how the plugin treats a user whose group membership is temporarily missing because of a directory replication fault or an LDAP query error, since a broad removal triggered by a bad read can unenrol a whole cohort at once. Ask the plugin's documentation for the current removal options and whether any of them are safe against a failed or empty directory response.
Test removal behavior before go-live, using a controlled group. Create a test group in a non-production directory or a dedicated OU, enrol a small set of test accounts through it, run the sync, then remove one account from the group and run the sync again. Record what happens to the course enrolment, the role assignment, any group membership inside the course, and the grade history. Repeat the test with the group emptied, since that is the case most likely to cause mass unenrolment. Confirm which events are written to the Moodle logs so the change can be evidenced to an auditor. Treat the results as the input to your sync frequency and removal settings, and rerun the test after any change to either.
Security and operational risks of directory-driven enrolment
Directory-driven enrolment gives a directory group the power to grant or remove course access in Moodle. The cards below cover the controls that keep that power bounded: the account Moodle uses to read the directory, how credentials travel, who can change the groups, what gets logged, how broad groups can end up with teacher roles, and what to re-test after each upgrade.
Bind account privilege
The bind account is the credential Moodle uses to search the directory for users and groups. It should have read access to only the organizational units that hold the users and groups named in the enrolment settings, and no write permissions. Ask the directory team to confirm the account cannot modify group membership, and rotate its password under a documented schedule. Test the account with a search that returns only the expected objects.
LDAPS for credentials in transit
Moodle sends the bind account password and each user's password during sign-in checks over the connection it opens to the directory. Without LDAPS, those credentials can cross the network in a form that exposes them to anyone able to observe the traffic. Confirm that the LDAP host setting uses an LDAPS endpoint, that the certificate chain is trusted by the Moodle server, and that plain LDAP is blocked at the network layer between Moodle and the directory.
Control of directory group changes
In this design, adding someone to a directory group adds them to a course in Moodle, so the people who manage those groups effectively manage course access. Identify who can add members to each enrolment group, whether that includes helpdesk staff or delegated administrators, and whether changes need approval. Record the owner of each group that maps to a course role so that access reviews have a named person to ask.
Audit trail for enrolments
Moodle writes enrolment and role assignment events to its logs, but those records only explain a change if the directory side also keeps a record of who changed each group and when. Confirm that directory change auditing is on for the groups used in enrolment, and that the two logs can be matched by user and timestamp. Decide how long each log is kept and where it is stored, so that a question about a past enrolment can still be answered.
Nested and broad groups granting teacher roles
Nested groups can pull members of a parent group into a course through a child group the mapping owner did not expect. A broad group such as all staff or a department with many members, mapped to the teacher role, can give large numbers of people editing rights across many courses. Map only narrow, purpose-built groups to teacher or manager roles, and check the effective membership of each mapped group, including nested members, before the mapping goes live.
Review after Moodle upgrades
An upgrade can change how the LDAP enrolment plugin reads group attributes, how the sync task handles removed members, or which role settings are applied. Test a sample of mapped courses against a staging copy of the directory before each upgrade, and compare role assignments before and after. Repeat the check after plugin updates, since enrolment plugins are maintained separately from core and can change independently of the Moodle version.
How a directory group change reaches a Moodle course
The change starts in the directory, where a user is added to or removed from a group. Nothing reaches Moodle until the scheduled enrolment sync task runs, so the sync interval sets the delay. The task reads group membership over the LDAP connection, matches each group to a course and role mapping in Moodle, then writes or removes the enrolment record. Check the trust boundary: Moodle holds only the read-only bind it was given, and every enrolment it creates or removes is driven by a mapping an administrator configured.
Directory group changes flow through the scheduled sync into Moodle enrolment records.
Limits to confirm in your environment before you commit
LDAP group enrolment depends on details that vary by Moodle release, plugin version and directory layout. The cards below list what to test on your own directory and Moodle version before you commit to a design.
Nested group support
Confirm whether your enrolment plugin version resolves groups nested inside other groups, and how deep it goes. A group that appears to work in a flat test can silently miss members who sit one level down in a real directory. Build a test tenant with a nested group three levels deep and confirm which accounts are enrolled after a sync run.
Core auth pluginsGroup size and sync duration
Measure how long a full sync takes against a group of your largest expected size, not against a small pilot group. Sync time grows with membership count and the number of courses each group touches, and it determines how often you can safely schedule the task. Ask for the timing on a copy of production data before you set the cron frequency.
Identifier matching
Confirm which LDAP attribute the plugin uses to match directory users to Moodle accounts, such as the username or an email attribute, and what happens when two records share a value. A mismatch can enrol the wrong person or create duplicate accounts. Test with users whose display names collide and with accounts that changed their login name.
Behavior on group renames
Renaming a directory group can break the mapping if the plugin keys on the group name rather than its distinguished name or an immutable identifier. Test a rename in the test directory and check whether members are unenrolled, duplicated or left untouched. Record the result so your change process includes a mapping update step.
Release and plugin support status
Check that the enrolment plugin version you intend to run is supported on your Moodle release, and whether the plugin's maintenance status covers the security support window you plan to use. Moodle's own support dates differ by release, so confirm both against the plugin's documentation rather than assuming they match.
Moodle releasesDirectory schema in use
Confirm the schema your directory actually runs, including how group membership is stored (member, memberOf or a custom attribute) and whether your domain uses the same structure in every organizational unit. Schema differences between Active Directory and OpenLDAP environments often explain why a configuration works in one place and fails in another.
Questions buyers ask before enrolling Moodle courses from directory groups
Can our own team set up LDAP group enrolment in Moodle without a partner?
Yes, a team with Moodle administration experience and directory access can do it, but the work is more than a settings page. The enrolment plugin is configured in Moodle's site administration, while the group design, role mapping and test accounts depend on how your directory is built. Teams that have not run an LDAP enrolment before usually spend most of their effort on the directory questions, not on Moodle itself. Ask whether your admins have time to write a mapping document, run a test course and review sync logs for several cycles before enabling it for real students.
What drives the cost and effort of directory group enrolment?
Effort rises with how messy the source groups are. The main drivers are the shape of the directory (one domain or several, OUs versus flat groups), the number of courses and roles that need mapping, whether groups are nested and how deep, and how many test cycles are needed before go-live. Each course that maps to a group adds review work, and every mapping rule needs testing for edge cases such as users in two groups or users who leave a group mid-term. Ask any provider to price the directory review, the mapping design, the test plan and the handover separately, so you can see which items are one-time and which need ongoing review.
How do nested groups change the design?
Nested groups need an explicit decision on whether child membership should grant course access. The LDAP enrolment plugin reads group membership through the directory's attributes, and nesting can mean a user gets enrolled through a parent group they did not expect. Before building, list every nested group that feeds a course and confirm which membership attribute your directory returns for each user. Test one user in each nesting level, and check that removing someone from a child group removes the enrolment as expected.
How long does a pilot take, and what sets its length?
Pilot length depends on scope, not on a fixed template. A pilot covering a few courses, one or two group mappings and a test OU usually needs less time than one covering every faculty or department, because each mapping requires a test course, a test user set and sign-off from the course owner. The schedule also depends on how quickly your directory team can confirm group structure and service account rights. Ask a provider to show the pilot's exit criteria in writing, such as which sync results and test cases must pass before production, and whether the timeline is agreed before work starts.
What do we need from our directory and Moodle administrators?
You need a directory administrator who can confirm the group structure, the attributes that identify membership, and a read-only bind account for Moodle. Your Moodle administrator needs to own the course-to-group mapping, the role assignments and the decision on what happens when a user leaves a group. Both teams should agree who approves changes to mappings, because a single renamed group can silently remove students from live courses. Plan time for both teams to review the sync logs together during the pilot.
Is a cohort sync or a web services feed a better route?
Cohort sync is often the better route when the directory groups already match the population you want in courses and the course structure is stable. It keeps the membership logic in Moodle's cohorts, which administrators can inspect without touching the directory. A web services feed suits cases where membership comes from an HR or identity system that needs richer rules, error handling and scheduled reconciliation. Direct LDAP enrolment fits when a small number of courses follow directory groups closely. Compare the options against who owns each group, how often membership changes and how much audit detail your compliance team expects.
What should we confirm about sync frequency and removed users before enabling it?
Confirm how often the enrolment task runs, what happens to enrolments when a group member disappears from the directory, and whether removed users are unenrolled, suspended or left alone. These settings decide whether a directory error can remove students from courses in the middle of a term. Check the current Moodle release notes and plugin documentation for your version, because options and defaults can change between releases. Run the sync in a test environment through at least one removal event before you accept the behavior.
How DeployOpen scopes and delivers LDAP enrolment for Moodle
Every LDAP enrolment engagement starts with a written scope. Before any work begins, DeployOpen agrees the scope, deliverables and timeline in writing. For this topic, that means naming the directory (Active Directory or OpenLDAP), the groups that will drive enrolment, the course roles each group maps to, which courses are in scope, the sync frequency, and what happens to enrolments when a user leaves the group. The written scope also records what is out of scope, such as account creation in the directory, group ownership changes, or changes to the identity provider used for sign-in. A quote follows from that scope, so the more precise the list of groups and courses, the more precise the estimate.
The first working phase is a directory mapping review. DeployOpen works with your directory administrators to inspect the group structure: whether nested group membership is used and how deep it goes, whether group names are stable, which groups are security groups and which are distribution lists, and whether any group is maintained by hand in a way that would surprise an automated sync. The review confirms the Moodle settings that will carry the design, including the LDAP enrolment plugin's group and role mapping fields, the sync schedule under scheduled tasks, and whether a cohort-based design fits better for any population. Confirm with your directory team how often group membership changes, because that drives the sync frequency you can justify.
Delivery then moves to a pilot with dedicated test groups in a non-production Moodle site, followed by a controlled promotion to production. The pilot checks role assignments, unenrolment behavior when a user is removed from a group, and the effect of a deliberately broken or empty group, which should not silently unenrol a whole course. DeployOpen delivers configuration documentation and a handover covering the mappings, the scheduled tasks to monitor, and the runbook for adding a course or group. Ongoing upgrades, changes to Moodle versions and periodic checks of the sync can be covered by an optional retainer, which is priced separately from the fixed-scope work.

