Skip to content

Commit

Permalink
[ldap] Add flag for disable nested groups search (ydb-platform#8414)
Browse files Browse the repository at this point in the history
  • Loading branch information
molotkov-and committed Sep 2, 2024
1 parent 0a09f29 commit d01be28
Show file tree
Hide file tree
Showing 3 changed files with 211 additions and 11 deletions.
5 changes: 5 additions & 0 deletions ydb/core/protos/auth.proto
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ message TLdapAuthentication {
optional TCertRequire CertRequire = 3 [default = DEMAND];
}

message TExtendedSettings {
optional bool EnableNestedGroupsSearch = 1 [default = false];
}

optional string Host = 1; // DEPRECATED: Use Hosts instead it
optional uint32 Port = 2;
required string BaseDn = 3;
Expand All @@ -113,4 +117,5 @@ message TLdapAuthentication {
optional string RequestedGroupAttribute = 9;
repeated string Hosts = 10;
optional string Scheme = 11 [default = "ldap"];
optional TExtendedSettings ExtendedSettings = 12;
}
15 changes: 12 additions & 3 deletions ydb/core/security/ldap_auth_provider/ldap_auth_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ class TLdapAuthProvider : public NActors::TActorBootstrapped<TLdapAuthProvider>
NKikimrLdap::BerFree(ber, 0);
}
std::vector<TString> allUserGroups;
if (!directUserGroups.empty()) {
auto& extendedSettings = Settings.GetExtendedSettings();
if (extendedSettings.GetEnableNestedGroupsSearch() && !directUserGroups.empty()) {
// Active Directory has special matching rule to fetch nested groups in one request it is MatchingRuleInChain
// We don`t know what is ldap server. Is it Active Directory or OpenLdap or other server?
// If using MatchingRuleInChain return empty list of groups it means that ldap server isn`t Active Directory
Expand All @@ -158,6 +159,8 @@ class TLdapAuthProvider : public NActors::TActorBootstrapped<TLdapAuthProvider>
allUserGroups = std::move(directUserGroups);
GetNestedGroups(ld, &allUserGroups);
}
} else {
allUserGroups = std::move(directUserGroups);
}
NKikimrLdap::MsgFree(entry);
NKikimrLdap::Unbind(ld);
Expand Down Expand Up @@ -306,7 +309,10 @@ class TLdapAuthProvider : public NActors::TActorBootstrapped<TLdapAuthProvider>
std::vector<TString> TryToGetGroupsUseMatchingRuleInChain(LDAP* ld, LDAPMessage* entry) const {
static const TString matchingRuleInChain = "1.2.840.113556.1.4.1941"; // Only Active Directory supports
TStringBuilder filter;
filter << "(member:" << matchingRuleInChain << ":=" << NKikimrLdap::GetDn(ld, entry) << ')';
char* dn = NKikimrLdap::GetDn(ld, entry);
filter << "(member:" << matchingRuleInChain << ":=" << dn << ')';
NKikimrLdap::MemFree(dn);
dn = nullptr;
LDAPMessage* searchMessage = nullptr;
int result = NKikimrLdap::Search(ld, Settings.GetBaseDn(), NKikimrLdap::EScope::SUBTREE, filter, NKikimrLdap::noAttributes, 0, &searchMessage);
if (!NKikimrLdap::IsSuccess(result)) {
Expand All @@ -320,7 +326,10 @@ class TLdapAuthProvider : public NActors::TActorBootstrapped<TLdapAuthProvider>
std::vector<TString> groups;
groups.reserve(countEntries);
for (LDAPMessage* groupEntry = NKikimrLdap::FirstEntry(ld, searchMessage); groupEntry != nullptr; groupEntry = NKikimrLdap::NextEntry(ld, groupEntry)) {
groups.push_back(NKikimrLdap::GetDn(ld, groupEntry));
dn = NKikimrLdap::GetDn(ld, groupEntry);
groups.push_back(dn);
NKikimrLdap::MemFree(dn);
dn = nullptr;
}
NKikimrLdap::MsgFree(searchMessage);
return groups;
Expand Down
Loading

0 comments on commit d01be28

Please sign in to comment.