Files

4.5 KiB

Microsoft Active Directory Domain Services

Use a Windows Server AD DS domain controller and a dedicated LDAP read account. The sync uses standard AD DS LDAP attributes and paged searches. This guide uses corp.example.net as an example domain.

Configure LDAP over TLS

Use a domain controller hostname that matches its certificate. The Laravel host needs DNS resolution, TCP access to port 636, the PHP LDAP extension, and trust in the issuing CA. If the CA is private, place the public CA chain in a readable PEM file and point LDAP_TLS_CA_CERT to it. Keep the bind password in the deployment secret store or the local environment.

LDAP_CONNECTION=default
LDAP_HOST=dc01.corp.example.net
LDAP_PORT=636
LDAP_TLS=true
LDAP_STARTTLS=false
LDAP_SASL=false
LDAP_USERNAME="[email protected]"
LDAP_PASSWORD="<bind password>"
LDAP_TLS_CA_CERT="/absolute/path/to/ad-ca-chain.pem"
LDAP_BASE_DN="DC=corp,DC=example,DC=net"
AD_SYNC_BASE_DN="OU=LaravelSync,DC=corp,DC=example,DC=net"
AD_SYNC_SCHEDULED=false

This example uses a simple bind inside TLS. Confirm the bind works under your organisation's LDAP policy before enabling scheduled sync. Reload Laravel's configuration cache using your normal deployment process after changing settings. Use ldp.exe to independently verify the LDAPS endpoint if needed. Microsoft LDAPS certificate setup · LDAP signing

Prepare the sync OU

Put test users in the configured OU. Give the bind account permission to read those users and their required attributes. Every returned user needs a unique, valid mail address and a usable displayName or cn. A missing or duplicate address rejects the whole snapshot. Laravel matches by objectGUID first. With --email, an existing eligible Laravel user can be linked by mail.

The LDAP filter combines objectCategory=person with objectClass=user. AD DS supplies the paged-results control used by the sync. The disabled state comes from the ACCOUNTDISABLE bit (0x0002) in userAccountControl. Use a dedicated OU on one domain controller's domain for the first run. The sync rejects incomplete pages and referrals. User search filter · AD DS LDAP controls · Account control flags

Verify against Windows AD

On a Windows admin workstation with the Active Directory PowerShell module, inspect the test account and its OU:

Get-ADUser -Identity 'sync-test' -Server 'dc01.corp.example.net' -Properties mail,userAccountControl |
    Select-Object DistinguishedName,ObjectGUID,mail,Enabled,userAccountControl

On the Laravel host, preview the same account:

php artisan ad:sync --email --dry-run -dd
php artisan ad:sync --email --dry-run -vvv --debug

Compare the GUID, mail, distinguished name, and account control with PowerShell. -dd (also --dump-ad) prints selected AD properties as returned by LDAP, with the binary GUID rendered as text. Optional fields appear only when returned by the server. --debug prints the account data Laravel uses for the sync.

For the live test, use a dedicated Laravel database and a dedicated AD test account:

  1. Create a Laravel user with the same email and run php artisan ad:sync --email. Confirm the existing row gains the AD GUID. To test importing instead, use --create-missing explicitly after reviewing a dry run.
  2. Disable the test account with Disable-ADAccount -Identity 'sync-test' -Server 'dc01.corp.example.net'. Run the email sync again. Confirm Laravel records directory_disabled and blocks login.
  3. Run Enable-ADAccount -Identity 'sync-test' -Server 'dc01.corp.example.net', then sync again. Confirm one reactivation and verify the Laravel login check.
  4. For a scope larger than 500 users, compare the -dd dry-run result count with an AD query over the same OU to verify paging under the target controller's policies.

The application tests cover the sync logic and LDAP paging with fixtures. The live integration in this project was exercised against Samba AD. Run the steps above on the target Windows domain controller to confirm its certificate, bind policy, permissions, and directory data.