Skip to content

Fix handle password complexity default values #15314

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
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
13 changes: 10 additions & 3 deletions ydb/core/tx/schemeshard/schemeshard_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7445,7 +7445,6 @@ void TSchemeShard::ConfigureBackgroundCleaningQueue(
<< ", InflightLimit# " << cleaningConfig.InflightLimit);
}

// void TScheme
void TSchemeShard::ConfigureLoginProvider(
const ::NKikimrProto::TAuthConfig& config,
const TActorContext &ctx)
Expand All @@ -7457,18 +7456,26 @@ void TSchemeShard::ConfigureLoginProvider(
.MinUpperCaseCount = passwordComplexityConfig.GetMinUpperCaseCount(),
.MinNumbersCount = passwordComplexityConfig.GetMinNumbersCount(),
.MinSpecialCharsCount = passwordComplexityConfig.GetMinSpecialCharsCount(),
.SpecialChars = (passwordComplexityConfig.GetSpecialChars().empty() ? NLogin::TPasswordComplexity::VALID_SPECIAL_CHARS : passwordComplexityConfig.GetSpecialChars()),
.SpecialChars = passwordComplexityConfig.GetSpecialChars(),
.CanContainUsername = passwordComplexityConfig.GetCanContainUsername()
});
LoginProvider.UpdatePasswordCheckParameters(passwordComplexity);

auto getSpecialChars = [&passwordComplexity] () {
TStringBuilder result;
for (const auto& ch : passwordComplexity.SpecialChars) {
result << ch;
}
return result;
};

LOG_NOTICE_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD,
"PasswordComplexity for LoginProvider configured: MinLength# " << passwordComplexity.MinLength
<< ", MinLowerCaseCount# " << passwordComplexity.MinLowerCaseCount
<< ", MinUpperCaseCount# " << passwordComplexity.MinUpperCaseCount
<< ", MinNumbersCount# " << passwordComplexity.MinNumbersCount
<< ", MinSpecialCharsCount# " << passwordComplexity.MinSpecialCharsCount
<< ", SpecialChars# " << (passwordComplexityConfig.GetSpecialChars().empty() ? NLogin::TPasswordComplexity::VALID_SPECIAL_CHARS : passwordComplexityConfig.GetSpecialChars())
<< ", SpecialChars# " << getSpecialChars()
<< ", CanContainUsername# " << (passwordComplexity.CanContainUsername ? "true" : "false"));
}

Expand Down
14 changes: 7 additions & 7 deletions ydb/core/tx/schemeshard/ut_login/ut_login.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardLoginTest) {
AlterLoginAddGroupMembership(runtime, ++txId, "/MyRoot", "user1", "group1");
TestDescribeResult(DescribePath(runtime, "/MyRoot"),
{NLs::HasGroup("group1", {"user1"})});

CreateAlterLoginRemoveGroup(runtime, ++txId, "/MyRoot", "group1");
TestDescribeResult(DescribePath(runtime, "/MyRoot"),
{NLs::HasNoGroup("group1")});
Expand All @@ -323,7 +323,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardLoginTest) {
TTestBasicRuntime runtime;
TTestEnv env(runtime, TTestEnvOptions().EnableStrictAclCheck(StrictAclCheck));
ui64 txId = 100;

for (bool missingOk : {false, true}) {
auto modifyTx = std::make_unique<TEvSchemeShard::TEvModifySchemeTransaction>(txId, TTestTxConfig::SchemeShard);
auto transaction = modifyTx->Record.AddTransaction();
Expand Down Expand Up @@ -370,7 +370,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardLoginTest) {
TestModificationResult(runtime, txId, NKikimrScheme::StatusSuccess);
TestDescribeResult(DescribePath(runtime, "/MyRoot/Dir1"),
{NLs::HasOwner("root@builtin")});

CreateAlterLoginRemoveGroup(runtime, ++txId, "/MyRoot", "group1");
TestDescribeResult(DescribePath(runtime, "/MyRoot"),
{NLs::HasNoGroup("group1")});
Expand Down Expand Up @@ -412,7 +412,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardLoginTest) {
TestModificationResult(runtime, txId, NKikimrScheme::StatusSuccess);
TestDescribeResult(DescribePath(runtime, "/MyRoot/Dir1"),
{NLs::HasNoRight("+U:group1")});

CreateAlterLoginRemoveGroup(runtime, ++txId, "/MyRoot", "group1");
TestDescribeResult(DescribePath(runtime, "/MyRoot"),
{NLs::HasNoGroup("group1")});
Expand Down Expand Up @@ -630,8 +630,8 @@ Y_UNIT_TEST_SUITE(TSchemeShardLoginTest) {
// required: cannot contain username

{
CreateAlterLoginCreateUser(runtime, ++txId, "/MyRoot", "user1", "password1");
auto resultLogin = Login(runtime, "user1", "password1");
CreateAlterLoginCreateUser(runtime, ++txId, "/MyRoot", "user1", "Pass_word1");
auto resultLogin = Login(runtime, "user1", "Pass_word1");
UNIT_ASSERT_VALUES_EQUAL(resultLogin.error(), "");
auto describe = DescribePath(runtime, TTestTxConfig::SchemeShard, "/MyRoot");
CheckSecurityState(describe, {.PublicKeysSize = 1, .SidsSize = 1});
Expand Down Expand Up @@ -1101,7 +1101,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardLoginTest) {
accountLockout->SetAttemptThreshold(4);
accountLockout->SetAttemptResetDuration("3s");
});

TTestEnv env(runtime);
auto accountLockoutConfig = runtime.GetAppData().AuthConfig.GetAccountLockout();
ui64 txId = 100;
Expand Down
3 changes: 1 addition & 2 deletions ydb/library/login/login_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ Y_UNIT_TEST_SUITE(Login) {
.MinLowerCaseCount = 2,
.MinUpperCaseCount = 2,
.MinNumbersCount = 2,
.MinSpecialCharsCount = 2,
.SpecialChars = TPasswordComplexity::VALID_SPECIAL_CHARS
.MinSpecialCharsCount = 2
});

provider.UpdatePasswordCheckParameters(passwordComplexity);
Expand Down
17 changes: 11 additions & 6 deletions ydb/library/login/password_checker/password_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace NLogin {

TPasswordComplexity::TPasswordComplexity()
: SpecialChars(VALID_SPECIAL_CHARS.cbegin(), VALID_SPECIAL_CHARS.cend())
: SpecialChars(VALID_SPECIAL_CHARS)
{}

TPasswordComplexity::TPasswordComplexity(const TInitializer& initializer)
Expand All @@ -16,10 +16,13 @@ TPasswordComplexity::TPasswordComplexity(const TInitializer& initializer)
, MinSpecialCharsCount(initializer.MinSpecialCharsCount)
, CanContainUsername(initializer.CanContainUsername)
{
static const std::unordered_set<char> validSpecialChars(VALID_SPECIAL_CHARS.cbegin(), VALID_SPECIAL_CHARS.cend());
for (const char ch : initializer.SpecialChars) {
if (validSpecialChars.contains(ch)) {
SpecialChars.insert(ch);
if (initializer.SpecialChars.empty()) {
SpecialChars.insert(VALID_SPECIAL_CHARS.begin(), VALID_SPECIAL_CHARS.end());
} else {
for (const char ch : initializer.SpecialChars) {
if (VALID_SPECIAL_CHARS.contains(ch)) {
SpecialChars.insert(ch);
}
}
}
}
Expand All @@ -28,7 +31,9 @@ bool TPasswordComplexity::IsSpecialCharValid(char ch) const {
return SpecialChars.contains(ch);
}

const TString TPasswordComplexity::VALID_SPECIAL_CHARS = "!@#$%^&*()_+{}|<>?=";
const std::unordered_set<char> TPasswordComplexity::VALID_SPECIAL_CHARS {'!', '@', '#', '$', '%', '^', '&',
'*', '(', ')', '_', '+', '{',
'}', '|', '<', '>', '?', '='};

TPasswordChecker::TComplexityState::TComplexityState(const TPasswordComplexity& passwordComplexity)
: PasswordComplexity(passwordComplexity)
Expand Down
4 changes: 2 additions & 2 deletions ydb/library/login/password_checker/password_checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class TPasswordComplexity {
size_t MinUpperCaseCount = 0;
size_t MinNumbersCount = 0;
size_t MinSpecialCharsCount = 0;
TString SpecialChars = VALID_SPECIAL_CHARS;
TString SpecialChars;
bool CanContainUsername = false;
};

static const TString VALID_SPECIAL_CHARS;
static const std::unordered_set<char> VALID_SPECIAL_CHARS;

size_t MinLength = 0;
size_t MinLowerCaseCount = 0;
Expand Down
13 changes: 12 additions & 1 deletion ydb/library/login/password_checker/password_checker_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Y_UNIT_TEST_SUITE(PasswordChecker) {
.MinUpperCaseCount = 2,
.MinNumbersCount = 2,
.MinSpecialCharsCount = 2,
.SpecialChars = TPasswordComplexity::VALID_SPECIAL_CHARS,
.CanContainUsername = false
});
TPasswordChecker passwordChecker(passwordComplexity);
Expand Down Expand Up @@ -169,6 +168,18 @@ Y_UNIT_TEST_SUITE(PasswordChecker) {
UNIT_ASSERT_STRINGS_EQUAL(result.Error, "Password is too short");
}

Y_UNIT_TEST(AcceptPasswordWithSpecialCharsIfSpecialCharsListIsEmpty) {
TPasswordComplexity passwordComplexity({
.SpecialChars = ""
});
TPasswordChecker passwordChecker(passwordComplexity);
TString username = "testuser";
TString password = "user_password";
TPasswordChecker::TResult result = passwordChecker.Check(username, password);
UNIT_ASSERT_C(result.Success, result.Error);
UNIT_ASSERT(result.Error.empty());
}

Y_UNIT_TEST(HashChecker) {
{
auto hash = R"(
Expand Down
Loading