Skip to content

Check ldap domain as suffix of user login #6426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ydb/core/security/login_shared_func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ THolder<NSchemeCache::TSchemeCacheNavigate> CreateNavigateKeySetRequest(const TS

TAuthCredentials PrepareCredentials(const TString& login, const TString& password, const NKikimrProto::TAuthConfig& config) {
if (config.HasLdapAuthentication() && !config.GetLdapAuthenticationDomain().empty()) {
size_t n = login.find("@" + config.GetLdapAuthenticationDomain());
if (n != TString::npos) {
return {.AuthType = TAuthCredentials::EAuthType::Ldap, .Login = login.substr(0, n), .Password = password};
const TString domain = "@" + config.GetLdapAuthenticationDomain();
if (login.EndsWith(domain)) {
return {.AuthType = TAuthCredentials::EAuthType::Ldap, .Login = login.substr(0, login.size() - domain.size()), .Password = password};
}
}
return {.AuthType = TAuthCredentials::EAuthType::Internal, .Login = login, .Password = password};
Expand Down
13 changes: 13 additions & 0 deletions ydb/services/ydb/ydb_ldap_login_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,5 +378,18 @@ Y_UNIT_TEST_SUITE(TGRpcLdapAuthentication) {
loginConnection.Stop();
ldapServer.Stop();
}

Y_UNIT_TEST(LdapAuthSetIncorrectDomain) {
TString login = "ldapuser";
TString password = "ldapUserPassword";
const TString incorrectLdapDomain = "@ldap.domain"; // Correct domain is AuthConfig.LdapAuthenticationDomain: "ldap"

auto factory = CreateLoginCredentialsProviderFactory({.User = login + incorrectLdapDomain, .Password = password});
TLoginClientConnection loginConnection(InitLdapSettings);
auto loginProvider = factory->CreateProvider(loginConnection.GetCoreFacility());
UNIT_ASSERT_EXCEPTION_CONTAINS(loginProvider->GetAuthInfo(), yexception, "Invalid user");

loginConnection.Stop();
}
}
} //namespace NKikimr
Loading