Files
ad_testbed/docs/active-directory-sync.md
2026-11-11 17:15:37 +00:00

2.9 KiB

Active Directory sync

Laravel reads Samba Active Directory over verified LDAPS and matches accounts by objectGUID. The search base is OU=LaravelSync,DC=ad,DC=test. Users in that OU need a valid, unique mail address. The local Docker container publishes LDAPS on 127.0.0.1:1636; LDAP_TLS_CA_CERT points to the local Samba CA. Keep the bind credentials in .env.

Run the migrations on the configured database before enabling the page. Set AD_SYNC_ADMIN_ID to the ID of an existing local Laravel account. The default value of zero grants nobody access. The authorised account sees Directory sync in the sidebar. The page displays the latest live success and failure, counts, and disabled users. It flags the sync as stale after 30 minutes without a successful full live run.

With AD_SYNC_SCHEDULED=true, Laravel schedules ad:sync every ten minutes. The local macOS cron entry invokes artisan schedule:run every minute while the Mac is awake. Check the schedule with php artisan schedule:list and the audit trail in storage/logs/laravel.log.

A disabled AD account sets both ad_disabled_at and deleted_at. Re-enabling it clears both on the next successful sync. For missing users, use Preview missing users on the admin page, review the list, then select Deactivate reviewed users. The preview expires after ten minutes. The app checks a fresh LDAP snapshot before applying and rejects the review if the candidate list changed. Scheduled runs only deactivate accounts explicitly disabled in AD. The deactivation cap still applies to reviewed changes.

Local walkthrough

Run these commands from the Laravel project. Use a fresh username and mail address for each walkthrough.

docker exec samba-ad samba-tool user create sync-demo --random-password \
  --userou='OU=LaravelSync' --mail-address=[email protected] \
  --given-name=Sync --surname=Demo
php artisan ad:sync --dry-run
php artisan ad:sync

docker exec samba-ad samba-tool user disable sync-demo
php artisan ad:sync
docker exec samba-ad samba-tool user enable sync-demo
php artisan ad:sync

Inspect the directory entry with docker exec samba-ad samba-tool user show sync-demo. To inspect its schema, run docker exec samba-ad samba-tool schema objectclass show user or docker exec samba-ad samba-tool schema attribute show userAccountControl.