[Bug] LDAP / Active Directory Role Mapping not assigning proper role
Hey there! 👋 Thanks for taking the time to report this bug — we appreciate it!
Please keep in mind: PegaProx is developed and maintained entirely by volunteers in our free time. We do our best, but we can't work magic 🪄 — please be patient, we'll get to your issue as soon as we can.
Want to help keep PegaProx alive?
- ⭐ Star the project — it's free and helps a lot!
- 💖 Become a Sponsor — helps us dedicate more time to development
- 🤝 Contributing code or docs is always welcome too!
Describe the bug
Created 2 group role mappings. (See attached screenshot) 1st role, if the AD account belongs to the Built-in Administrators group, set Pegaprox role as Admin. <-- This works 2nd role, if the AD account belongs to the Built-in Users Group, set Pegaprox role as User. <-- Does not work, only assigns these users as Viewer
Steps to Reproduce
- Log in with AD account belonging to the Users grup
- Role assigned is Viewer
- An administrator needs to manually assign the User role
Expected behavior
Accounts in the AD group Uservs should receive the User role
Environment
- PegaProx Version: 0.98.1
- Installation Method: Downloaded Pre-built Image from Pegaprox
- OS: As included in Pre-built image
- Browser: Firefox 150, Chrome 147
- Behind Reverse Proxy? No
- UI? Corporate
Logs
No logs
Screenshots
Checklist
- [ X ] I have searched existing issues to make sure this is not a duplicate
- [ X ] I am using the latest version of PegaProx
Hi @LowAir2000, the role-mapping flow does built-in groups (admin_group / user_group / viewer_group) first with admin > user > viewer priority, and then iterates over your custom Group Mappings, with each match overriding. So if a user-group mapping is configured but never fires, it's almost always a DN format mismatch — AD will sometimes return memberOf as full DNs (CN=Users,CN=Builtin,DC=example,DC=com) and sometimes as just sAMAccountNames depending on which attribute / lookup mode you have set, and our match is exact (case-insensitive but otherwise literal).
To narrow it down, could you grab a few things:
- The full LDAP log section for one failing login —
grep -i ldap /var/log/pegaprox/pegaprox.log | tail -100. The line you're looking for is[LDAP] User 'X' authenticated successfully (role=Y, groups=Z). Ifrole=viewerand you've got aCustom group mapping matchedline above it pointing at the User group, the overwrite is failing further down. If you don't see the matched line at all, the DN comparison didn't fire. - The exact group-DN string you put into the second mapping (sanitized — domain bits are fine to redact, just preserve format).
- Output of one quick
ldapsearchagainst the same user from the PegaProx host:ldapsearch -x -H ldap://your-dc -D 'bind-user' -W -b 'user-base-dn' '(sAMAccountName=affected-user)' memberOf— that tells us exactly what shape of strings AD is handing us for that user's groups.
Also worth noting: 0.98.1 in the bug report — I assume that's 0.9.8.1. Would be good to retry once on 0.9.9 (released a couple of days back) so we're chasing current code.
Self-assigning while we wait. PegaProx is donation-funded, https://opencollective.com/pegaprox — appreciated if it helps anyone reading along.
— Marcus
I think that you mentioned something that is missing in the docs.. "...and then iterates over your custom Group Mappings, with each match overriding.".
I was having the same problem, where I had my Admin roles as the first rule, and viewer roles second, and all users would keep matching the viewer roles. The more specific matches need to be on the bottom, vs being on the top. Once I changed that, my users that are admins got the admin roles.
Nice catch @jthoel — that's the assist that saves the next person from a debug session. You're reading the code right: utils/ldap.py walks the custom group-mappings list top-to-bottom, and every match calls back into the same role/tenant/permissions slots. There's no priority field, so last match wins by virtue of being the last write. Built-in admin/user/viewer groups (the three named slots) get evaluated first as a separate pass, but custom mappings then override on top — so a viewer-mapping placed after an admin-mapping in the list would clobber the earlier admin assignment for any user that happens to match both groups.
@LowAir2000 — could you check whether your two custom mappings are in the order "User group → User role" first and "Built-in Admin → Admin role" second? If yes, swapping them so the admin rule lands further down (or just placing the more-specific group first and the catch-all-broader group last) should fix the symptom you described. If reordering does it, we'll close this one out as the resolution.
Worth flagging on our side: the fact that this trips up two different people inside the same week tells us the order semantics aren't communicated anywhere — neither in the UI (the mapping list looks like an unordered set) nor in the docs. Going to queue a small UI hint plus a doc paragraph explaining the precedence model. Won't promise a date but it's on the list now.
If PegaProx has been useful, https://opencollective.com/pegaprox is where backers underwrite the kind of incremental polish this project needs.
Cheers, Marcus
Shipped in v0.9.9.1: nested-group expansion via LDAP_MATCHING_RULE_IN_CHAIN (OID 1.2.840.113556.1.4.1941). Built-in Users / Domain Users style mappings now resolve to the right role instead of falling back to Viewer.
https://github.com/PegaProx/project-pegaprox/releases/tag/v0.9.9.3
Thanks @LowAir2000 for the report and @jthoel for the code-walk that pinned where the loop stopped early — that saved a debug session.
https://opencollective.com/pegaprox
— Marcus