Skip to content

Commit 54a0a74

Browse files
authored
Check ldap domain as suffix of user login (#6426)
1 parent bd51e57 commit 54a0a74

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

ydb/core/security/login_shared_func.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ THolder<NSchemeCache::TSchemeCacheNavigate> CreateNavigateKeySetRequest(const TS
1919

2020
TAuthCredentials PrepareCredentials(const TString& login, const TString& password, const NKikimrProto::TAuthConfig& config) {
2121
if (config.HasLdapAuthentication() && !config.GetLdapAuthenticationDomain().empty()) {
22-
size_t n = login.find("@" + config.GetLdapAuthenticationDomain());
23-
if (n != TString::npos) {
24-
return {.AuthType = TAuthCredentials::EAuthType::Ldap, .Login = login.substr(0, n), .Password = password};
22+
const TString domain = "@" + config.GetLdapAuthenticationDomain();
23+
if (login.EndsWith(domain)) {
24+
return {.AuthType = TAuthCredentials::EAuthType::Ldap, .Login = login.substr(0, login.size() - domain.size()), .Password = password};
2525
}
2626
}
2727
return {.AuthType = TAuthCredentials::EAuthType::Internal, .Login = login, .Password = password};

ydb/services/ydb/ydb_ldap_login_ut.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -378,5 +378,18 @@ Y_UNIT_TEST_SUITE(TGRpcLdapAuthentication) {
378378
loginConnection.Stop();
379379
ldapServer.Stop();
380380
}
381+
382+
Y_UNIT_TEST(LdapAuthSetIncorrectDomain) {
383+
TString login = "ldapuser";
384+
TString password = "ldapUserPassword";
385+
const TString incorrectLdapDomain = "@ldap.domain"; // Correct domain is AuthConfig.LdapAuthenticationDomain: "ldap"
386+
387+
auto factory = CreateLoginCredentialsProviderFactory({.User = login + incorrectLdapDomain, .Password = password});
388+
TLoginClientConnection loginConnection(InitLdapSettings);
389+
auto loginProvider = factory->CreateProvider(loginConnection.GetCoreFacility());
390+
UNIT_ASSERT_EXCEPTION_CONTAINS(loginProvider->GetAuthInfo(), yexception, "Invalid user");
391+
392+
loginConnection.Stop();
393+
}
381394
}
382395
} //namespace NKikimr

0 commit comments

Comments
 (0)