Skip to content

Commit

Permalink
auth: Fix LDAP RO group handling
Browse files Browse the repository at this point in the history
Make sure the LDAP RO group name is encoded before validating whether
the user is member of it or not.
  • Loading branch information
garberg committed Nov 4, 2024
1 parent ce08819 commit 18d3ccd
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion nipap/nipap/authlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@ def authenticate(self):
['cn', 'memberOf'],
)

self._logger.debug("User %s is member of groups: %s", self.username, res[0][1].get('memberOf', []))

# Data received from LDAP is bytes, make sure to decode/encode
# accordingly before using it
if res[0][1]['cn'][0] is not None:
Expand All @@ -569,7 +571,7 @@ def authenticate(self):
# if ro_group is configured, and the user is a member of
# neither the ro_group nor the rw_group, fail authentication.
if self._ldap_ro_group:
if self._ldap_ro_group not in res[0][1].get('memberOf', []):
if self._ldap_ro_group.encode('utf-8') not in res[0][1].get('memberOf', []):
self._authenticated = False
return self._authenticated
else:
Expand Down

0 comments on commit 18d3ccd

Please sign in to comment.