-
Notifications
You must be signed in to change notification settings - Fork 695
Extract password verification to a separate actor #19687
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
Open
yurikiselev
wants to merge
5
commits into
ydb-platform:main
Choose a base branch
from
yurikiselev:issue-15369-extract-login-handler-to-a-separate-actor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+493
−111
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
550f45f
Extract password verification to a saparate actor
yurikiselev 6ff56b7
Add unit tests
yurikiselev 06e6b31
Review fix - renamings and better checks in tests
yurikiselev 76b5e60
Review fix - move new events to exising "private" namespace
yurikiselev 4e4d9b6
Review fixes - add tests for admins; don't lose initial "fast' check …
yurikiselev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
ydb/core/tx/schemeshard/schemeshard__login_finalize.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
#include "schemeshard_impl.h" | ||
#include <ydb/library/security/util.h> | ||
#include <ydb/core/protos/auth.pb.h> | ||
#include <ydb/core/base/auth.h> | ||
#include <ydb/core/base/local_user_token.h> | ||
|
||
namespace NKikimr { | ||
namespace NSchemeShard { | ||
|
||
struct TSchemeShard::TTxLoginFinalize : TSchemeShard::TRwTxBase { | ||
private: | ||
TEvPrivate::TEvLoginFinalize::TPtr LoginFinalizeEventPtr; | ||
TString ErrMessage; | ||
|
||
public: | ||
TTxLoginFinalize(TSelf *self, TEvPrivate::TEvLoginFinalize::TPtr &ev) | ||
: TRwTxBase(self) | ||
, LoginFinalizeEventPtr(std::move(ev)) | ||
{} | ||
|
||
TTxType GetTxType() const override { | ||
return TXTYPE_LOGIN_FINALIZE; | ||
} | ||
|
||
void DoExecute(TTransactionContext& txc, const TActorContext& ctx) override { | ||
LOG_DEBUG_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, | ||
"TTxLoginFinalize Execute" | ||
<< " at schemeshard: " << Self->TabletID()); | ||
|
||
const auto& event = *LoginFinalizeEventPtr->Get(); | ||
if (event.NeedUpdateCache) { | ||
const auto isSuccessVerifying = | ||
event.CheckResult.Status == NLogin::TLoginProvider::TLoginUserResponse::EStatus::SUCCESS; | ||
Self->LoginProvider.UpdateCache( | ||
event.Request, | ||
event.PasswordHash, | ||
isSuccessVerifying | ||
); | ||
} | ||
const auto response = Self->LoginProvider.LoginUser(event.Request, event.CheckResult); | ||
|
||
if (!LoginFinalizeEventPtr->Get()->Request.ExternalAuth) { | ||
UpdateLoginSidsStats(response, txc); | ||
} | ||
if (!response.Error.empty()) { | ||
ErrMessage = response.Error; | ||
SendError(response.Error); | ||
return; | ||
} | ||
FillResult(response); | ||
} | ||
|
||
void DoComplete(const TActorContext &ctx) override { | ||
LOG_DEBUG_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, | ||
"TTxLoginFinalize Completed" | ||
<< ", with " << (ErrMessage ? "error: " + ErrMessage : "no errors") | ||
<< " at schemeshard: " << Self->TabletID()); | ||
} | ||
|
||
private: | ||
bool IsAdmin(const TString& user) const { | ||
const auto userToken = NKikimr::BuildLocalUserToken(Self->LoginProvider, user); | ||
return IsAdministrator(AppData(), &userToken); | ||
} | ||
|
||
void FillResult(const NLogin::TLoginProvider::TLoginUserResponse& response) { | ||
THolder<TEvSchemeShard::TEvLoginResult> result = MakeHolder<TEvSchemeShard::TEvLoginResult>(); | ||
switch (response.Status) { | ||
case NLogin::TLoginProvider::TLoginUserResponse::EStatus::SUCCESS: { | ||
result->Record.SetToken(response.Token); | ||
result->Record.SetSanitizedToken(response.SanitizedToken); | ||
result->Record.SetIsAdmin(IsAdmin(LoginFinalizeEventPtr->Get()->Request.User)); | ||
yurikiselev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
break; | ||
} | ||
case NLogin::TLoginProvider::TLoginUserResponse::EStatus::INVALID_PASSWORD: | ||
case NLogin::TLoginProvider::TLoginUserResponse::EStatus::INVALID_USER: | ||
case NLogin::TLoginProvider::TLoginUserResponse::EStatus::UNAVAILABLE_KEY: | ||
case NLogin::TLoginProvider::TLoginUserResponse::EStatus::UNSPECIFIED: { | ||
result->Record.SetError(response.Error); | ||
break; | ||
} | ||
} | ||
Self->Send( | ||
LoginFinalizeEventPtr->Get()->Source, | ||
std::move(result), | ||
0, | ||
LoginFinalizeEventPtr->Cookie | ||
); | ||
} | ||
|
||
void SendError(const TString& error) { | ||
auto result = MakeHolder<TEvSchemeShard::TEvLoginResult>(); | ||
result->Record.SetError(error); | ||
Self->Send( | ||
LoginFinalizeEventPtr->Get()->Source, | ||
std::move(result), | ||
0, | ||
LoginFinalizeEventPtr->Cookie | ||
); | ||
} | ||
|
||
void UpdateLoginSidsStats(const NLogin::TLoginProvider::TLoginUserResponse& response, TTransactionContext& txc) { | ||
NIceDb::TNiceDb db(txc.DB); | ||
switch (response.Status) { | ||
case NLogin::TLoginProvider::TLoginUserResponse::EStatus::SUCCESS: { | ||
const auto& sid = Self->LoginProvider.Sids[LoginFinalizeEventPtr->Get()->Request.User]; | ||
db.Table<Schema::LoginSids>() | ||
.Key(LoginFinalizeEventPtr->Get()->Request.User) | ||
.Update<Schema::LoginSids::LastSuccessfulAttempt, Schema::LoginSids::FailedAttemptCount>( | ||
ToMicroSeconds(sid.LastSuccessfulLogin), sid.FailedLoginAttemptCount | ||
azevaykin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
break; | ||
} | ||
case NLogin::TLoginProvider::TLoginUserResponse::EStatus::INVALID_PASSWORD: { | ||
const auto& sid = Self->LoginProvider.Sids[LoginFinalizeEventPtr->Get()->Request.User]; | ||
db.Table<Schema::LoginSids>() | ||
.Key(LoginFinalizeEventPtr->Get()->Request.User) | ||
.Update<Schema::LoginSids::LastFailedAttempt, Schema::LoginSids::FailedAttemptCount>( | ||
ToMicroSeconds(sid.LastFailedLogin), sid.FailedLoginAttemptCount | ||
); | ||
} | ||
default: | ||
break; | ||
} | ||
} | ||
}; | ||
|
||
NTabletFlatExecutor::ITransaction* TSchemeShard::CreateTxLoginFinalize(TEvPrivate::TEvLoginFinalize::TPtr &ev) { | ||
return new TTxLoginFinalize(this, ev); | ||
} | ||
|
||
}} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.