Skip to content

Commit

Permalink
[ldap] Prohibit requests with empty password (ydb-platform#10401)
Browse files Browse the repository at this point in the history
  • Loading branch information
molotkov-and authored and uzhastik committed Oct 24, 2024
1 parent 8d559a6 commit c143dd8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ydb/core/security/ldap_auth_provider/ldap_auth_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ class TLdapAuthProvider : public NActors::TActorBootstrapped<TLdapAuthProvider>
+ NKikimrLdap::LdapError(*request.Ld),
.Retryable = false}}};
}
if (request.Password.Empty()) {
NKikimrLdap::MemFree(dn);
return {{TEvLdapAuthProvider::EStatus::UNAUTHORIZED,
{.Message = "LDAP login failed. Empty password",
.Retryable = false}}};
}
TEvLdapAuthProvider::TError error;
int result = NKikimrLdap::Bind(*request.Ld, dn, request.Password);
if (!NKikimrLdap::IsSuccess(result)) {
Expand Down
42 changes: 42 additions & 0 deletions ydb/services/ydb/ydb_ldap_login_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,48 @@ Y_UNIT_TEST_SUITE(TGRpcLdapAuthentication) {
ldapServer.Stop();
}

Y_UNIT_TEST(LdapAuthWithEmptyPassword) {
TString login = "ldapUser";
TString password = "";

LdapMock::TLdapMockResponses responses;
responses.BindResponses.push_back({{{.Login = "cn=robouser,dc=search,dc=yandex,dc=net", .Password = "robouserPassword"}}, {.Status = LdapMock::EStatus::SUCCESS}});

LdapMock::TSearchRequestInfo fetchUserSearchRequestInfo {
{
.BaseDn = "dc=search,dc=yandex,dc=net",
.Scope = 2,
.DerefAliases = 0,
.Filter = {.Type = LdapMock::EFilterType::LDAP_FILTER_EQUALITY, .Attribute = "uid", .Value = login},
.Attributes = {"1.1"}
}
};

std::vector<LdapMock::TSearchEntry> fetchUserSearchResponseEntries {
{
.Dn = "uid=" + login + ",dc=search,dc=yandex,dc=net"
}
};

LdapMock::TSearchResponseInfo fetchUserSearchResponseInfo {
.ResponseEntries = fetchUserSearchResponseEntries,
.ResponseDone = {.Status = LdapMock::EStatus::SUCCESS}
};
responses.SearchResponses.push_back({fetchUserSearchRequestInfo, fetchUserSearchResponseInfo});

TLoginClientConnection loginConnection(InitLdapSettings);
LdapMock::TLdapSimpleServer ldapServer(loginConnection.GetLdapPort(), responses);

auto factory = CreateLoginCredentialsProviderFactory({.User = login + "@ldap", .Password = password});
auto loginProvider = factory->CreateProvider(loginConnection.GetCoreFacility());
TStringBuilder expectedErrorMessage;
expectedErrorMessage << "LDAP login failed. Empty password";
UNIT_ASSERT_EXCEPTION_CONTAINS(loginProvider->GetAuthInfo(), yexception, expectedErrorMessage);

loginConnection.Stop();
ldapServer.Stop();
}

Y_UNIT_TEST(LdapAuthSetIncorrectDomain) {
TString login = "ldapuser";
TString password = "ldapUserPassword";
Expand Down

0 comments on commit c143dd8

Please sign in to comment.