Skip to content

Commit

Permalink
add config option to specify TTL for user logins (#7083) (#7486)
Browse files Browse the repository at this point in the history
  • Loading branch information
adameat authored Aug 6, 2024
1 parent ccf98e2 commit 4e8a96c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions ydb/core/protos/auth.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ message TAuthConfig {
optional string UserAccountDomain = 43 [default = "passport"];
optional string ServiceDomain = 44 [default = "service"];
optional bool DomainLoginOnly = 45 [default = true];
optional string LoginTokenExpireTime = 46 [default = "12h"];
optional string RefreshPeriod = 50 [default = "1s"]; // how often we check for tickets freshness/expiration
optional string RefreshTime = 51 [default = "1h"]; // we will try to refresh valid ticket within RefreshTime/2 and RefreshTime randomly
optional string LifeTime = 52 [default = "1h"]; // for how long ticket will remain in the cache after last access
Expand Down
1 change: 1 addition & 0 deletions ydb/core/protos/flat_tx_scheme.proto
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ message TEvLogin {
optional string User = 1;
optional string Password = 2;
optional string ExternalAuth = 3;
optional uint64 ExpiresAfterMs = 4;
}

message TEvLoginResult {
Expand Down
3 changes: 3 additions & 0 deletions ydb/core/security/login_shared_func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ NKikimrScheme::TEvLogin CreateLoginRequest(const TAuthCredentials& credentials,
}
default: {}
}
if (config.HasLoginTokenExpireTime()) {
record.SetExpiresAfterMs(TDuration::Parse(config.GetLoginTokenExpireTime()).MilliSeconds());
}
return record;
}

Expand Down
12 changes: 9 additions & 3 deletions ydb/core/tx/schemeshard/schemeshard__login.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ struct TSchemeShard::TTxLogin : TSchemeShard::TRwTxBase {
TTxType GetTxType() const override { return TXTYPE_LOGIN; }

NLogin::TLoginProvider::TLoginUserRequest GetLoginRequest() const {
const auto& record(Request->Get()->Record);
return {
.User = Request->Get()->Record.GetUser(),
.Password = Request->Get()->Record.GetPassword(),
.ExternalAuth = Request->Get()->Record.GetExternalAuth()
.User = record.GetUser(),
.Password = record.GetPassword(),
.Options = {
.ExpiresAfter = record.HasExpiresAfterMs()
? std::chrono::milliseconds(record.GetExpiresAfterMs())
: std::chrono::system_clock::duration::zero()
},
.ExternalAuth = record.GetExternalAuth(),
};
}

Expand Down

0 comments on commit 4e8a96c

Please sign in to comment.