project-pegaprox icon indicating copy to clipboard operation
project-pegaprox copied to clipboard

[Bug] LDAP group grants on resource pools never match

Open MrMasterbay opened this issue 2 months ago • 5 comments

Describe the bug

Pool permissions granted to an LDAP group have no effect. The user logs in, is in the group, and still sees nothing from the pool.

An LDAP login stores the group memberships as full DNs, while the pool permission dialog asks for a "Group Name" as free text. The lookup compares the whole string, so the two never match.

Steps to Reproduce

  1. Configure LDAP/AD authentication and log in once with a directory user so the group memberships are picked up.
  2. Go to a resource pool, add a permission, choose subject type "group" and enter the group name, e.g. PVE-Admins.
  3. Log in as the directory user.
  4. The pool and its VMs are not visible; the grant is ignored.
  5. Entering the full DN instead (CN=PVE-Admins,OU=Groups,DC=corp,DC=local) makes it work.

Expected behavior

Entering the group name works, or the dialog says that a DN is expected.

Environment

  • PegaProx Version: 1.2.0
  • Installation Method: Docker
  • OS: Debian 13
  • Browser: Chrome latest
  • Behind Reverse Proxy? No
  • UI? Corporate

Logs

n/a - no error is raised, the grant simply does not match

Screenshots

n/a

Checklist

  • [x] I have searched existing issues to make sure this is not a duplicate
  • [x] I am using the latest version of PegaProx
  • [x] I have put enough in here that someone can start on it without asking me three questions first
  • [x] I understand PegaProx is maintained by volunteers in their free time

Cause:

  • pegaprox/utils/ldap.py stores "groups": member_of, and member_of holds DNs (str(g) for g in user_entry["memberOf"], plus entry_dn from the nested-group expansion).
  • pegaprox/core/db.py, get_user_pool_permissions, matches LOWER(subject_id) = LOWER(?) over the whole value.
  • web/src/settings_modal.js labels the field groupName / "Group Name" and it is free text.

Note the comment above that query: the same spot was already touched for #555, but only for case sensitivity. The DN-versus-name half was not part of it.

Suggested fix: match the stored value against the full group string and against its leading RDN value, still case-insensitively, and say in the dialog which form is expected.

MrMasterbay avatar Sep 21 '26 11:09 MrMasterbay

Workaround until this is fixed

Two options, both work on 1.2.0.

1. Put the full DN in the "Group Name" field. The value PegaProx compares against is what the directory hands back as the group membership, and that is always a distinguished name — so CN=PVE-Admins,OU=Groups,DC=corp,DC=local works today. Case does not matter here, the group lookup is case-insensitive.

To get the exact string, ask the directory rather than typing the DN by hand:

# AD / PowerShell — returns literally what gets stored for that user
Get-ADUser <login> -Properties memberOf | Select -ExpandProperty memberOf

# OpenLDAP
ldapsearch -x -b "<group_base_dn>" "(cn=PVE-Admins)" dn

Paste a line in verbatim. Nested groups work too, they get expanded to DNs the same way.

2. Or grant on the user directly. Subject type "user", subject id = the login name exactly as typed at sign-in. This one is case-sensitive. Good enough to unblock a couple of people, does not scale to a team.

One thing worth knowing while you test: PegaProx only logs how many groups it found, never their values, so there is currently no way to see from our side what it is matching against. That is part of why this is awkward to spot, and it gets addressed along with the fix.

MrMasterbay avatar Sep 21 '26 11:09 MrMasterbay

Hey ;)

Just testing your workaround.

I also used the full DN in my tests but the pool was still empty. (I double checked the DN)

Maybe i am doing it wrong: My user gets a base role with some permissions and gets a pool permission on top.

How would i need to "design" my base role so that a user can only see VMs of a ressource pool but not all VMs from all clusters? As soon as i allow "vm.view, cluster.view, pool.view" in the base role the user sees every vm in all cluster and ressource pools or without "vm.view" he sees no VMs and only empty pools.

txev avatar Sep 22 '26 09:09 txev

Fixed on Testing (8176603).

Your read was right. The thing that makes it nasty is that it's two dialogs disagreeing about one stored value: the LDAP role/tenant mapping asks for group_dn and compares whole strings, which is consistent with what it asks. The pool permission dialog labels the same field "Group Name" in three different files, and compared the typed name against a DN. So the operator did exactly what the form asked and got nothing — with no error, which is why nobody reported it earlier. A grant that silently does nothing looks identical to one that hasn't been made.

Both lookups needed it, not just the obvious one: get_user_pool_permissions decides what they may do, get_user_pool_clusters decides whether the cluster shows up at all. Fixing only the first would've left them staring at an empty list.

A grant entered as a full DN still matches only that DN — deliberate, if someone typed the whole thing they meant that group. The other direction is what's new. Side effect you should know about: two groups in different OUs sharing a CN will both match a bare-name grant. That's inherent to typing a bare name; the DN is there for anyone who needs them separated.

— MK

mkellermann97 avatar Sep 22 '26 09:09 mkellermann97

Hey, thank you very much for your efforts. I got now curious and gave Testing (docker sha-ea2296c) a testrun.

I still cannot see VMs limited to the Pool i give permissions to :/ If i give vm.view to the base role i see all vms. If i remove vm.view, i see no vms.

I tried setting the pool permissions via full DN and without. Maybe i am not doing it right?

Image

txev avatar Oct 01 '26 09:10 txev

A pool grant on a group now matches an LDAP membership by its bare name as well as by the full DN. Sign-in now also stores the user's directory groups, which was the missing piece behind the empty pool on the earlier Testing build. After their next sign-in, a user in that group sees the pool's guests without vm.view in the base role, and vm.view in the base role no longer shows them every guest. This ships in 1.3.0.

Marcus

mkellermann97 avatar Oct 07 '26 04:10 mkellermann97