Skip to content

Commit 9cf31f1

Browse files
committed
[ldap] Add flag for disable nested groups search (#8414)
1 parent 8855100 commit 9cf31f1

File tree

3 files changed

+211
-11
lines changed

3 files changed

+211
-11
lines changed

ydb/core/protos/auth.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ message TLdapAuthentication {
104104
optional TCertRequire CertRequire = 3 [default = DEMAND];
105105
}
106106

107+
message TExtendedSettings {
108+
optional bool EnableNestedGroupsSearch = 1 [default = false];
109+
}
110+
107111
optional string Host = 1; // DEPRECATED: Use Hosts instead it
108112
optional uint32 Port = 2;
109113
optional string BaseDn = 3;
@@ -115,4 +119,5 @@ message TLdapAuthentication {
115119
optional string RequestedGroupAttribute = 9;
116120
repeated string Hosts = 10;
117121
optional string Scheme = 11 [default = "ldap"];
122+
optional TExtendedSettings ExtendedSettings = 12;
118123
}

ydb/core/security/ldap_auth_provider/ldap_auth_provider.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ class TLdapAuthProvider : public NActors::TActorBootstrapped<TLdapAuthProvider>
148148
NKikimrLdap::BerFree(ber, 0);
149149
}
150150
std::vector<TString> allUserGroups;
151-
if (!directUserGroups.empty()) {
151+
auto& extendedSettings = Settings.GetExtendedSettings();
152+
if (extendedSettings.GetEnableNestedGroupsSearch() && !directUserGroups.empty()) {
152153
// Active Directory has special matching rule to fetch nested groups in one request it is MatchingRuleInChain
153154
// We don`t know what is ldap server. Is it Active Directory or OpenLdap or other server?
154155
// If using MatchingRuleInChain return empty list of groups it means that ldap server isn`t Active Directory
@@ -158,6 +159,8 @@ class TLdapAuthProvider : public NActors::TActorBootstrapped<TLdapAuthProvider>
158159
allUserGroups = std::move(directUserGroups);
159160
GetNestedGroups(ld, &allUserGroups);
160161
}
162+
} else {
163+
allUserGroups = std::move(directUserGroups);
161164
}
162165
NKikimrLdap::MsgFree(entry);
163166
NKikimrLdap::Unbind(ld);
@@ -306,7 +309,10 @@ class TLdapAuthProvider : public NActors::TActorBootstrapped<TLdapAuthProvider>
306309
std::vector<TString> TryToGetGroupsUseMatchingRuleInChain(LDAP* ld, LDAPMessage* entry) const {
307310
static const TString matchingRuleInChain = "1.2.840.113556.1.4.1941"; // Only Active Directory supports
308311
TStringBuilder filter;
309-
filter << "(member:" << matchingRuleInChain << ":=" << NKikimrLdap::GetDn(ld, entry) << ')';
312+
char* dn = NKikimrLdap::GetDn(ld, entry);
313+
filter << "(member:" << matchingRuleInChain << ":=" << dn << ')';
314+
NKikimrLdap::MemFree(dn);
315+
dn = nullptr;
310316
LDAPMessage* searchMessage = nullptr;
311317
int result = NKikimrLdap::Search(ld, Settings.GetBaseDn(), NKikimrLdap::EScope::SUBTREE, filter, NKikimrLdap::noAttributes, 0, &searchMessage);
312318
if (!NKikimrLdap::IsSuccess(result)) {
@@ -320,7 +326,10 @@ class TLdapAuthProvider : public NActors::TActorBootstrapped<TLdapAuthProvider>
320326
std::vector<TString> groups;
321327
groups.reserve(countEntries);
322328
for (LDAPMessage* groupEntry = NKikimrLdap::FirstEntry(ld, searchMessage); groupEntry != nullptr; groupEntry = NKikimrLdap::NextEntry(ld, groupEntry)) {
323-
groups.push_back(NKikimrLdap::GetDn(ld, groupEntry));
329+
dn = NKikimrLdap::GetDn(ld, groupEntry);
330+
groups.push_back(dn);
331+
NKikimrLdap::MemFree(dn);
332+
dn = nullptr;
324333
}
325334
NKikimrLdap::MsgFree(searchMessage);
326335
return groups;

0 commit comments

Comments
 (0)