Skip to content

Commit 0567dd5

Browse files
authored
[LDAP] Add flag to disable builtin auth mechanism (#7042)
1 parent 937dcbd commit 0567dd5

File tree

5 files changed

+55
-10
lines changed

5 files changed

+55
-10
lines changed

ydb/core/protos/auth.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ message TAuthConfig {
5353
optional bool UseBuiltinDomain = 78 [default = true];
5454
optional string AccessServiceType = 79 [default = "Yandex_v2"]; // For now the following values are supported: "Yandex_v2", "Nebius_v1"
5555
optional string CertificateAuthenticationDomain = 80 [default = "cert"];
56+
optional bool EnableLoginAuthentication = 81 [default = true];
5657
}
5758

5859
message TUserRegistryConfig {

ydb/core/tx/schemeshard/schemeshard__login.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "schemeshard_impl.h"
22
#include <ydb/library/security/util.h>
3+
#include <ydb/core/protos/auth.pb.h>
34

45
namespace NKikimr {
56
namespace NSchemeShard {
@@ -66,13 +67,18 @@ struct TSchemeShard::TTxLogin : TSchemeShard::TRwTxBase {
6667
Self->PublishToSchemeBoard(TTxId(), {SubDomainPathId}, ctx);
6768
}
6869

69-
NLogin::TLoginProvider::TLoginUserResponse LoginResponse = Self->LoginProvider.LoginUser(GetLoginRequest());
7070
THolder<TEvSchemeShard::TEvLoginResult> result = MakeHolder<TEvSchemeShard::TEvLoginResult>();
71-
if (LoginResponse.Error) {
72-
result->Record.SetError(LoginResponse.Error);
73-
}
74-
if (LoginResponse.Token) {
75-
result->Record.SetToken(LoginResponse.Token);
71+
const auto& loginRequest = GetLoginRequest();
72+
if (loginRequest.ExternalAuth || AppData(ctx)->AuthConfig.GetEnableLoginAuthentication()) {
73+
NLogin::TLoginProvider::TLoginUserResponse LoginResponse = Self->LoginProvider.LoginUser(loginRequest);
74+
if (LoginResponse.Error) {
75+
result->Record.SetError(LoginResponse.Error);
76+
}
77+
if (LoginResponse.Token) {
78+
result->Record.SetToken(LoginResponse.Token);
79+
}
80+
} else {
81+
result->Record.SetError("Login authentication is disabled");
7682
}
7783

7884
LOG_DEBUG_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD,

ydb/core/tx/schemeshard/schemeshard__operation_alter_login.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "schemeshard__operation_part.h"
22
#include "schemeshard__operation_common.h"
33
#include "schemeshard_impl.h"
4+
#include <ydb/core/protos/auth.pb.h>
45

56
namespace {
67

@@ -15,7 +16,9 @@ class TAlterLogin: public TSubOperationBase {
1516
NIceDb::TNiceDb db(context.GetTxc().DB); // do not track is there are direct writes happen
1617
TTabletId ssId = context.SS->SelfTabletId();
1718
auto result = MakeHolder<TProposeResponse>(OperationId.GetTxId(), ssId);
18-
if (Transaction.GetWorkingDir() != context.SS->LoginProvider.Audience) {
19+
if (!AppData()->AuthConfig.GetEnableLoginAuthentication()) {
20+
result->SetStatus(NKikimrScheme::StatusPreconditionFailed, "Login authentication is disabled");
21+
} else if (Transaction.GetWorkingDir() != context.SS->LoginProvider.Audience) {
1922
result->SetStatus(NKikimrScheme::StatusPreconditionFailed, "Wrong working dir");
2023
} else {
2124
const NKikimrConfig::TDomainsConfig::TSecurityConfig& securityConfig = context.SS->GetDomainsConfig().GetSecurityConfig();

ydb/core/tx/schemeshard/ut_login/ut_login.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <ydb/core/tx/schemeshard/ut_helpers/helpers.h>
22
#include <ydb/library/login/login.h>
3+
#include <ydb/core/protos/auth.pb.h>
34

45
using namespace NKikimr;
56
using namespace NSchemeShard;
@@ -28,4 +29,23 @@ Y_UNIT_TEST_SUITE(TSchemeShardLoginTest) {
2829
auto resultValidate = login.ValidateToken({.Token = resultLogin.token()});
2930
UNIT_ASSERT_VALUES_EQUAL(resultValidate.User, "user1");
3031
}
32+
33+
Y_UNIT_TEST(DisableBuiltinAuthMechanism) {
34+
TTestBasicRuntime runtime;
35+
TTestEnv env(runtime);
36+
runtime.GetAppData().AuthConfig.SetEnableLoginAuthentication(false);
37+
ui64 txId = 100;
38+
TActorId sender = runtime.AllocateEdgeActor();
39+
std::unique_ptr<TEvSchemeShard::TEvModifySchemeTransaction> transaction(CreateAlterLoginCreateUser(++txId, "user1", "password1"));
40+
transaction->Record.MutableTransaction(0)->SetWorkingDir("/MyRoot");
41+
ForwardToTablet(runtime, TTestTxConfig::SchemeShard, sender, transaction.release());
42+
auto resultLogin = Login(runtime, "user1", "password1");
43+
UNIT_ASSERT_VALUES_EQUAL(resultLogin.error(), "Login authentication is disabled");
44+
UNIT_ASSERT_VALUES_EQUAL(resultLogin.token(), "");
45+
auto describe = DescribePath(runtime, TTestTxConfig::SchemeShard, "/MyRoot");
46+
UNIT_ASSERT(describe.HasPathDescription());
47+
UNIT_ASSERT(describe.GetPathDescription().HasDomainDescription());
48+
UNIT_ASSERT(describe.GetPathDescription().GetDomainDescription().HasSecurityState());
49+
UNIT_ASSERT(describe.GetPathDescription().GetDomainDescription().GetSecurityState().PublicKeysSize() > 0);
50+
}
3151
}

ydb/services/ydb/ydb_ldap_login_ut.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ void InitLdapSettingsWithEmptyBindPassword(NKikimrProto::TLdapAuthentication* ld
9999

100100
class TLoginClientConnection {
101101
public:
102-
TLoginClientConnection(std::function<void(NKikimrProto::TLdapAuthentication*, ui16, TTempFileHandle&)> initLdapSettings)
102+
TLoginClientConnection(std::function<void(NKikimrProto::TLdapAuthentication*, ui16, TTempFileHandle&)> initLdapSettings, bool isLoginAuthenticationEnabled = true)
103103
: CaCertificateFile()
104-
, Server(InitAuthSettings(std::move(initLdapSettings)))
104+
, Server(InitAuthSettings(std::move(initLdapSettings), isLoginAuthenticationEnabled))
105105
, Connection(GetDriverConfig(Server.GetPort()))
106106
, Client(Connection)
107107
{}
@@ -119,7 +119,7 @@ class TLoginClientConnection {
119119
}
120120

121121
private:
122-
NKikimrConfig::TAppConfig InitAuthSettings(std::function<void(NKikimrProto::TLdapAuthentication*, ui16, TTempFileHandle&)>&& initLdapSettings) {
122+
NKikimrConfig::TAppConfig InitAuthSettings(std::function<void(NKikimrProto::TLdapAuthentication*, ui16, TTempFileHandle&)>&& initLdapSettings, bool isLoginAuthenticationEnabled = true) {
123123
TPortManager tp;
124124
LdapPort = tp.GetPort(389);
125125

@@ -128,6 +128,7 @@ class TLoginClientConnection {
128128

129129
authConfig->SetUseBlackBox(false);
130130
authConfig->SetUseLoginProvider(true);
131+
authConfig->SetEnableLoginAuthentication(isLoginAuthenticationEnabled);
131132
appConfig.MutableDomainsConfig()->MutableSecurityConfig()->SetEnforceUserTokenRequirement(true);
132133
appConfig.MutableFeatureFlags()->SetAllowYdbRequestsWithoutDatabase(false);
133134

@@ -375,5 +376,19 @@ Y_UNIT_TEST_SUITE(TGRpcLdapAuthentication) {
375376

376377
loginConnection.Stop();
377378
}
379+
380+
Y_UNIT_TEST(DisableBuiltinAuthMechanism) {
381+
TString login = "builtinUser";
382+
TString password = "builtinUserPassword";
383+
384+
TLoginClientConnection loginConnection(InitLdapSettings, false);
385+
386+
auto factory = CreateLoginCredentialsProviderFactory({.User = login, .Password = password});
387+
auto loginProvider = factory->CreateProvider(loginConnection.GetCoreFacility());
388+
TStringBuilder expectedErrorMessage;
389+
UNIT_ASSERT_EXCEPTION_CONTAINS(loginProvider->GetAuthInfo(), yexception, "Login authentication is disabled");
390+
391+
loginConnection.Stop();
392+
}
378393
}
379394
} //namespace NKikimr

0 commit comments

Comments
 (0)