Skip to content

Commit b810317

Browse files
committed
Support in grpc proxy
1 parent 77fffde commit b810317

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

ydb/core/grpc_services/grpc_request_check_actor.h

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ bool TGRpcRequestProxyHandleMethods::ValidateAndReplyOnError(TCtx* ctx) {
3838
}
3939
}
4040

41+
inline const TVector<TEvTicketParser::TEvAuthorizeTicket::TEntry>& GetEntriesForAuthAndCheckRequest(TEvRequestAuthAndCheck::TPtr& ev) {
42+
if (ev->Get()->YdbToken && ev->Get()->YdbToken->StartsWith("Bearer")) {
43+
if (AppData()->AuthConfig.GetUseAccessService()
44+
&& (AppData()->DomainsConfig.GetSecurityConfig().ViewerAllowedSIDsSize() > 0 || AppData()->DomainsConfig.GetSecurityConfig().MonitoringAllowedSIDsSize() > 0)) {
45+
static TVector<NKikimr::TEvTicketParser::TEvAuthorizeTicket::TEntry> entries = {
46+
{NKikimr::TEvTicketParser::TEvAuthorizeTicket::ToPermissions({"ydb.developerApi.get", "ydb.developerApi.update"}), {{"gizmo_id", "gizmo"}}}
47+
};
48+
return entries;
49+
}
50+
}
51+
static TVector<NKikimr::TEvTicketParser::TEvAuthorizeTicket::TEntry> emptyEntries = {};
52+
return emptyEntries;
53+
}
54+
4155
template <typename TEvent>
4256
class TGrpcRequestCheckActor
4357
: public TGRpcRequestProxyHandleMethods
@@ -73,7 +87,7 @@ class TGrpcRequestCheckActor
7387
}
7488

7589
void ProcessCommonAttributes(const TSchemeBoardEvents::TDescribeSchemeResult& schemeData) {
76-
static std::vector<TString> allowedAttributes = {"folder_id", "service_account_id", "database_id", "container_id"};
90+
static std::vector<TString> allowedAttributes = {"folder_id", "service_account_id", "database_id"};
7791
TVector<std::pair<TString, TString>> attributes;
7892
attributes.reserve(schemeData.GetPathDescription().UserAttributesSize());
7993
for (const auto& attr : schemeData.GetPathDescription().GetUserAttributes()) {
@@ -83,6 +97,15 @@ class TGrpcRequestCheckActor
8397
}
8498
if (!attributes.empty()) {
8599
SetEntries({{GetPermissions(), attributes}});
100+
} else {
101+
if constexpr (std::is_same_v<TEvent, TEvRequestAuthAndCheck>) {
102+
if (!Request_->Get()->GetDatabaseName()) {
103+
const auto& entries = GetEntriesForAuthAndCheckRequest(Request_);
104+
if (!entries.empty()) {
105+
SetEntries(entries);
106+
}
107+
}
108+
}
86109
}
87110
}
88111

@@ -464,6 +487,12 @@ class TGrpcRequestCheckActor
464487
ReplyBackAndDie();
465488
}
466489

490+
void HandleAndDie(TEvRequestAuthAndCheck::TPtr& ev) {
491+
GrpcRequestBaseCtx_->FinishSpan();
492+
ev->Get()->ReplyWithYdbStatus(Ydb::StatusIds::SUCCESS);
493+
PassAway();
494+
}
495+
467496
template <typename T>
468497
void HandleAndDie(T& event) {
469498
GrpcRequestBaseCtx_->FinishSpan();

ydb/core/grpc_services/grpc_request_proxy.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ class TGRpcRequestProxyImpl
117117
NYql::TIssues()});
118118
}
119119

120+
void Handle(TEvRequestAuthAndCheck::TPtr& ev, const TActorContext&) {
121+
ev->Get()->FinishSpan();
122+
ev->Get()->ReplyWithYdbStatus(Ydb::StatusIds::SUCCESS);
123+
}
124+
120125
// returns true and defer event if no updates for given database
121126
// otherwice returns false and leave event untouched
122127
template <typename TEvent>
@@ -186,7 +191,7 @@ class TGRpcRequestProxyImpl
186191
if (maybeDatabaseName && !maybeDatabaseName.GetRef().empty()) {
187192
databaseName = CanonizePath(maybeDatabaseName.GetRef());
188193
} else {
189-
if (!AllowYdbRequestsWithoutDatabase && DynamicNode) {
194+
if (!AllowYdbRequestsWithoutDatabase && DynamicNode && !std::is_same_v<TEvent, TEvRequestAuthAndCheck>) { // TEvRequestAuthAndCheck is allowed to be processed without database
190195
requestBaseCtx->ReplyUnauthenticated("Requests without specified database are not allowed");
191196
requestBaseCtx->FinishSpan();
192197
return;
@@ -590,6 +595,7 @@ void TGRpcRequestProxyImpl::StateFunc(TAutoPtr<IEventHandle>& ev) {
590595
HFunc(TEvCoordinationSessionRequest, PreHandle);
591596
HFunc(TEvNodeCheckRequest, PreHandle);
592597
HFunc(TEvProxyRuntimeEvent, PreHandle);
598+
HFunc(TEvRequestAuthAndCheck, PreHandle);
593599

594600
default:
595601
Y_ABORT("Unknown request: %u\n", ev->GetTypeRewrite());

0 commit comments

Comments
 (0)