Skip to content

Commit 11dd5a0

Browse files
authored
Add access control on bootstrap (#15228)
1 parent 22b98a2 commit 11dd5a0

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

ydb/core/base/appdata_fwd.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,13 @@ struct TAppData {
250250
bool EnableMvccSnapshotWithLegacyDomainRoot = false;
251251
bool UsePartitionStatsCollectorForTests = false;
252252
bool DisableCdcAutoSwitchingToReadyStateForTests = false;
253+
253254
TVector<TString> AdministrationAllowedSIDs; // use IsAdministrator method to check whether a user or a group is allowed to perform administrative tasks
255+
TVector<TString> RegisterDynamicNodeAllowedSIDs;
256+
TVector<TString> BootstrapAllowedSIDs;
254257
TVector<TString> DefaultUserSIDs;
255258
TString AllAuthenticatedUsers = "all-users@well-known";
256-
TVector<TString> RegisterDynamicNodeAllowedSIDs;
259+
257260
TString TenantName;
258261
TString NodeName;
259262

ydb/core/driver_lib/run/run.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ class TDomainsInitializer : public IAppDataInitializer {
243243
TVector<TString> registerDynamicNodeAllowedSIDs(allowedSids.cbegin(), allowedSids.cend());
244244
appData->RegisterDynamicNodeAllowedSIDs = std::move(registerDynamicNodeAllowedSIDs);
245245
}
246+
if (securityConfig.BootstrapAllowedSIDsSize() > 0) {
247+
const auto& allowedSids = securityConfig.GetBootstrapAllowedSIDs();
248+
TVector<TString> bootstrapAllowedSIDs(allowedSids.cbegin(), allowedSids.cend());
249+
appData->BootstrapAllowedSIDs = std::move(bootstrapAllowedSIDs);
250+
}
246251

247252
appData->InitFeatureFlags(Config.GetFeatureFlags());
248253
appData->AllowHugeKeyValueDeletes = Config.GetFeatureFlags().GetAllowHugeKeyValueDeletes();

ydb/core/grpc_services/rpc_config.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <ydb/core/mind/local.h>
1111
#include <ydb/core/protos/local.pb.h>
1212
#include <ydb/core/blobstorage/nodewarden/node_warden_events.h>
13+
#include <ydb/core/base/auth.h>
1314

1415
namespace NKikimr::NGRpcService {
1516

@@ -320,6 +321,12 @@ void DoBootstrapCluster(std::unique_ptr<IRequestOpCtx> p, const IFacilityProvide
320321
TBase::Bootstrap(ctx);
321322
Become(&TBootstrapClusterRequest::StateFunc);
322323

324+
if (!CheckAccess()) {
325+
Request().RaiseIssue(NYql::TIssue("Access denied"));
326+
Reply(Ydb::StatusIds::UNAUTHORIZED, ctx);
327+
return;
328+
}
329+
323330
const auto& request = *GetProtoRequest();
324331

325332
auto ev = std::make_unique<NStorage::TEvNodeConfigInvokeOnRoot>();
@@ -350,6 +357,15 @@ void DoBootstrapCluster(std::unique_ptr<IRequestOpCtx> p, const IFacilityProvide
350357
return TBase::StateFuncBase(ev);
351358
}
352359
}
360+
361+
bool CheckAccess() {
362+
if (Request().GetInternalToken()
363+
&& !(IsAdministrator(AppData(), Request().GetInternalToken().Get()) || IsTokenAllowed(Request().GetInternalToken().Get(), AppData()->BootstrapAllowedSIDs))) {
364+
return false;
365+
}
366+
367+
return true;
368+
}
353369
};
354370

355371
TActivationContext::Register(new TBootstrapClusterRequest(p.release()));

ydb/core/protos/config.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ message TDomainsConfig {
249249
optional string AllAuthenticatedUsers = 5;
250250
repeated string ViewerAllowedSIDs = 6;
251251
repeated string RegisterDynamicNodeAllowedSIDs = 8;
252+
repeated string BootstrapAllowedSIDs = 9;
252253

253254
message TUser {
254255
optional string Name = 1;

0 commit comments

Comments
 (0)