[ZBXNEXT-8573] LDAP Nested Groups Created: 2023 Jul 17  Updated: 2024 Jun 03

Status: Open
Project: ZABBIX FEATURE REQUESTS
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Change Request Priority: Low
Reporter: Dominik Bronischewski Assignee: Unassigned
Resolution: Unresolved Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate

 Description   

When using the LDAP integration of Zabbix, we noticed that nested groups are not supported when querying which group the user is in. It is clear that Nested consumes a lot of performance, so I would add a checkbox for Nested queries.



 Comments   
Comment by Jonathan Petersson [ 2024 Apr 19 ]

I've prototyped adding support for nested groups. It's a bit hacky but should give some decent guidance.

 

[root@zbx-web-01 ldap]# diff -u CLdap.php.bak  CLdap.php 
--- CLdap.php.bak	2024-04-18 10:49:45.181684322 +0000
+++ CLdap.php	2024-04-18 20:53:30.046886862 +0000
@@ -42,6 +42,7 @@
 	const DEFAULT_FILTER_USER = '(%{attr}=%{user})';
 	const DEFAULT_FILTER_GROUP = '(%{groupattr}=%{user})';
 	const DEFAULT_MEMBERSHIP_ATTRIBUTE = 'memberOf';
+        const NESTED_GROUP_FILTER = '(&(sAMAccountName=%{user})(memberOf:1.2.840.113556.1.4.1941:=%{group_dn}))';
 
 	/**
 	 * Type of binding made to LDAP server. One of static::BIND_ constant value.
@@ -375,6 +376,11 @@
 				: $results[$key][0];
 		}
 
+		$matched_groups = $this->matchNestedGroups($user['samaccountname']);
+		if(count($matched_groups) > 0) {
+			$user["memberof"] = array_merge($user["memberof"], $matched_groups);
+		}
+
 		return $user;
 	}
 
@@ -556,4 +562,19 @@
 
 		return $results;
 	}
+
+   protected function matchNestedGroups(string $user): array {
+       $matched_groups = []; // Initialize the array to avoid errors if no groups are matched
+
+       foreach ($this->cnf['provision_groups'] as $groupConfig) {
+           $placeholders = ['%{user}' => $user, '%{group_dn}' => $groupConfig['name']];
+           $group_filter = $this->makeFilter(static::NESTED_GROUP_FILTER, $placeholders, LDAP_ESCAPE_FILTER);
+           $search_result = $this->search($this->cnf['base_dn'], $group_filter, [], ['dn']);
+           if ($search_result['count'] > 0) {
+	     $matched_groups[] = $groupConfig['name'];
+           }
+       }
+       return $matched_groups;
+   }
+
 } 

In the group-mapping you'll need to submit the full DN.

Comment by Gregory Chalenko [ 2024 Jun 03 ]

Please check proposition markkrj made in comment to ZBXNEXT-276. It looks like the solution you are searching for, without any modification of Zabbix source code.

Generated at Wed Apr 30 06:56:16 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.