@@ -39,18 +39,40 @@ bool TGRpcRequestProxyHandleMethods::ValidateAndReplyOnError(TCtx* ctx) {
39
39
}
40
40
}
41
41
42
- inline const TVector<TEvTicketParser::TEvAuthorizeTicket::TEntry>& GetEntriesForAuthAndCheckRequest (TEvRequestAuthAndCheck::TPtr& ev) {
43
- if (ev->Get ()->YdbToken && ev->Get ()->YdbToken ->StartsWith (" Bearer" )) {
44
- if (AppData ()->AuthConfig .GetUseAccessService ()
45
- && (AppData ()->DomainsConfig .GetSecurityConfig ().ViewerAllowedSIDsSize () > 0 || AppData ()->DomainsConfig .GetSecurityConfig ().MonitoringAllowedSIDsSize () > 0 )) {
46
- static TVector<NKikimr::TEvTicketParser::TEvAuthorizeTicket::TEntry> entries = {
47
- {NKikimr::TEvTicketParser::TEvAuthorizeTicket::ToPermissions ({" ydb.developerApi.get" , " ydb.developerApi.update" }), {{" gizmo_id" , " gizmo" }}}
48
- };
49
- return entries;
42
+ inline TVector<TEvTicketParser::TEvAuthorizeTicket::TEntry> GetEntriesForAuthAndCheckRequest (TEvRequestAuthAndCheck::TPtr& ev, const TVector<std::pair<TString, TString>>& rootAttributes) {
43
+ const bool isBearerToken = ev->Get ()->YdbToken && ev->Get ()->YdbToken ->StartsWith (" Bearer" );
44
+ const bool useAccessService = AppData ()->AuthConfig .GetUseAccessService ();
45
+ const bool needClusterAccessResourceCheck = AppData ()->DomainsConfig .GetSecurityConfig ().ViewerAllowedSIDsSize () > 0 ||
46
+ AppData ()->DomainsConfig .GetSecurityConfig ().MonitoringAllowedSIDsSize () > 0 ;
47
+
48
+ if (!isBearerToken || !useAccessService || !needClusterAccessResourceCheck) {
49
+ return {};
50
+ }
51
+
52
+ const TString& accessServiceType = AppData ()->AuthConfig .GetAccessServiceType ();
53
+
54
+ if (accessServiceType == " Yandex_v2" ) {
55
+ static const TVector<NKikimr::TEvTicketParser::TEvAuthorizeTicket::TEntry> entries = {
56
+ {NKikimr::TEvTicketParser::TEvAuthorizeTicket::ToPermissions ({" ydb.developerApi.get" , " ydb.developerApi.update" }), {{" gizmo_id" , " gizmo" }}}
57
+ };
58
+ return entries;
59
+ } else if (accessServiceType == " Nebius_v1" ) {
60
+ static const auto permissions = NKikimr::TEvTicketParser::TEvAuthorizeTicket::ToPermissions ({
61
+ " ydb.clusters.get" , " ydb.clusters.monitor" , " ydb.clusters.manage"
62
+ });
63
+ auto it = std::find_if (rootAttributes.begin (), rootAttributes.end (),
64
+ [](const std::pair<TString, TString>& p) {
65
+ return p.first == " folder_id" ;
66
+ });
67
+ if (it == rootAttributes.end ()) {
68
+ return {};
50
69
}
70
+ return {
71
+ {permissions, {{" folder_id" , it->second }}}
72
+ };
73
+ } else {
74
+ return {};
51
75
}
52
- static TVector<NKikimr::TEvTicketParser::TEvAuthorizeTicket::TEntry> emptyEntries = {};
53
- return emptyEntries;
54
76
}
55
77
56
78
template <typename TEvent>
@@ -80,14 +102,14 @@ class TGrpcRequestCheckActor
80
102
81
103
static const TVector<TString>& GetPermissions ();
82
104
83
- void InitializeAttributesFromSchema (const TSchemeBoardEvents::TDescribeSchemeResult& schemeData) {
105
+ void InitializeAttributesFromSchema (const TSchemeBoardEvents::TDescribeSchemeResult& schemeData, const TVector<std::pair<TString, TString>>& rootAttributes ) {
84
106
CheckedDatabaseName_ = CanonizePath (schemeData.GetPath ());
85
107
if (!GrpcRequestBaseCtx_->TryCustomAttributeProcess (schemeData, this )) {
86
- ProcessCommonAttributes (schemeData);
108
+ ProcessCommonAttributes (schemeData, rootAttributes );
87
109
}
88
110
}
89
111
90
- void ProcessCommonAttributes (const TSchemeBoardEvents::TDescribeSchemeResult& schemeData) {
112
+ void ProcessCommonAttributes (const TSchemeBoardEvents::TDescribeSchemeResult& schemeData, const TVector<std::pair<TString, TString>>& rootAttributes ) {
91
113
TVector<TEvTicketParser::TEvAuthorizeTicket::TEntry> entries;
92
114
static std::vector<TString> allowedAttributes = {" folder_id" , " service_account_id" , " database_id" };
93
115
TVector<std::pair<TString, TString>> attributes;
@@ -102,7 +124,7 @@ class TGrpcRequestCheckActor
102
124
}
103
125
104
126
if constexpr (std::is_same_v<TEvent, TEvRequestAuthAndCheck>) {
105
- const auto & e = GetEntriesForAuthAndCheckRequest (Request_);
127
+ const auto & e = GetEntriesForAuthAndCheckRequest (Request_, rootAttributes );
106
128
entries.insert (entries.end (), e.begin (), e.end ());
107
129
}
108
130
@@ -115,12 +137,12 @@ class TGrpcRequestCheckActor
115
137
TBase::SetEntries (entries);
116
138
}
117
139
118
- void InitializeAttributes (const TSchemeBoardEvents::TDescribeSchemeResult& schemeData);
140
+ void InitializeAttributes (const TSchemeBoardEvents::TDescribeSchemeResult& schemeData, const TVector<std::pair<TString, TString>>& rootAttributes );
119
141
120
- void Initialize (const TSchemeBoardEvents::TDescribeSchemeResult& schemeData) {
142
+ void Initialize (const TSchemeBoardEvents::TDescribeSchemeResult& schemeData, const TVector<std::pair<TString, TString>>& rootAttributes ) {
121
143
TString peerName = GrpcRequestBaseCtx_->GetPeerName ();
122
144
TBase::SetPeerName (peerName);
123
- InitializeAttributes (schemeData);
145
+ InitializeAttributes (schemeData, rootAttributes );
124
146
TBase::SetDatabase (CheckedDatabaseName_);
125
147
InitializeAuditSettings (schemeData);
126
148
}
@@ -132,7 +154,8 @@ class TGrpcRequestCheckActor
132
154
TAutoPtr<TEventHandle<TEvent>> request,
133
155
IGRpcProxyCounters::TPtr counters,
134
156
bool skipCheckConnectRights,
135
- const IFacilityProvider* facilityProvider)
157
+ const IFacilityProvider* facilityProvider,
158
+ const TVector<std::pair<TString, TString>>& rootAttributes)
136
159
: Owner_(owner)
137
160
, Request_(std::move(request))
138
161
, Counters_(counters)
@@ -152,7 +175,7 @@ class TGrpcRequestCheckActor
152
175
TBase::SetSecurityToken (TString (clientCertificates.front ()));
153
176
}
154
177
}
155
- Initialize (schemeData);
178
+ Initialize (schemeData, rootAttributes );
156
179
}
157
180
158
181
void Bootstrap (const TActorContext& ctx) {
@@ -595,11 +618,11 @@ class TGrpcRequestCheckActor
595
618
596
619
// default behavior - attributes in schema
597
620
template <typename TEvent>
598
- void TGrpcRequestCheckActor<TEvent>::InitializeAttributes(const TSchemeBoardEvents::TDescribeSchemeResult& schemeData) {
621
+ void TGrpcRequestCheckActor<TEvent>::InitializeAttributes(const TSchemeBoardEvents::TDescribeSchemeResult& schemeData, const TVector<std::pair<TString, TString>>& rootAttributes ) {
599
622
for (const auto & attr : schemeData.GetPathDescription ().GetUserAttributes ()) {
600
623
Attributes_.emplace_back (std::make_pair (attr.GetKey (), attr.GetValue ()));
601
624
}
602
- InitializeAttributesFromSchema (schemeData);
625
+ InitializeAttributesFromSchema (schemeData, rootAttributes );
603
626
}
604
627
605
628
template <typename T>
@@ -643,9 +666,10 @@ IActor* CreateGrpcRequestCheckActor(
643
666
TAutoPtr<TEventHandle<TEvent>> request,
644
667
IGRpcProxyCounters::TPtr counters,
645
668
bool skipCheckConnectRights,
669
+ const TVector<std::pair<TString, TString>>& rootAttributes,
646
670
const IFacilityProvider* facilityProvider) {
647
671
648
- return new TGrpcRequestCheckActor<TEvent>(owner, schemeData, std::move (securityObject), std::move (request), counters, skipCheckConnectRights, facilityProvider);
672
+ return new TGrpcRequestCheckActor<TEvent>(owner, schemeData, std::move (securityObject), std::move (request), counters, skipCheckConnectRights, facilityProvider, rootAttributes );
649
673
}
650
674
651
675
}
0 commit comments