Skip to content

Commit

Permalink
Support in grpc proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
UgnineSirdis committed Jun 26, 2024
1 parent 77fffde commit b810317
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
31 changes: 30 additions & 1 deletion ydb/core/grpc_services/grpc_request_check_actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ bool TGRpcRequestProxyHandleMethods::ValidateAndReplyOnError(TCtx* ctx) {
}
}

inline const TVector<TEvTicketParser::TEvAuthorizeTicket::TEntry>& GetEntriesForAuthAndCheckRequest(TEvRequestAuthAndCheck::TPtr& ev) {
if (ev->Get()->YdbToken && ev->Get()->YdbToken->StartsWith("Bearer")) {
if (AppData()->AuthConfig.GetUseAccessService()
&& (AppData()->DomainsConfig.GetSecurityConfig().ViewerAllowedSIDsSize() > 0 || AppData()->DomainsConfig.GetSecurityConfig().MonitoringAllowedSIDsSize() > 0)) {
static TVector<NKikimr::TEvTicketParser::TEvAuthorizeTicket::TEntry> entries = {
{NKikimr::TEvTicketParser::TEvAuthorizeTicket::ToPermissions({"ydb.developerApi.get", "ydb.developerApi.update"}), {{"gizmo_id", "gizmo"}}}
};
return entries;
}
}
static TVector<NKikimr::TEvTicketParser::TEvAuthorizeTicket::TEntry> emptyEntries = {};
return emptyEntries;
}

template <typename TEvent>
class TGrpcRequestCheckActor
: public TGRpcRequestProxyHandleMethods
Expand Down Expand Up @@ -73,7 +87,7 @@ class TGrpcRequestCheckActor
}

void ProcessCommonAttributes(const TSchemeBoardEvents::TDescribeSchemeResult& schemeData) {
static std::vector<TString> allowedAttributes = {"folder_id", "service_account_id", "database_id", "container_id"};
static std::vector<TString> allowedAttributes = {"folder_id", "service_account_id", "database_id"};
TVector<std::pair<TString, TString>> attributes;
attributes.reserve(schemeData.GetPathDescription().UserAttributesSize());
for (const auto& attr : schemeData.GetPathDescription().GetUserAttributes()) {
Expand All @@ -83,6 +97,15 @@ class TGrpcRequestCheckActor
}
if (!attributes.empty()) {
SetEntries({{GetPermissions(), attributes}});
} else {
if constexpr (std::is_same_v<TEvent, TEvRequestAuthAndCheck>) {
if (!Request_->Get()->GetDatabaseName()) {
const auto& entries = GetEntriesForAuthAndCheckRequest(Request_);
if (!entries.empty()) {
SetEntries(entries);
}
}
}
}
}

Expand Down Expand Up @@ -464,6 +487,12 @@ class TGrpcRequestCheckActor
ReplyBackAndDie();
}

void HandleAndDie(TEvRequestAuthAndCheck::TPtr& ev) {
GrpcRequestBaseCtx_->FinishSpan();
ev->Get()->ReplyWithYdbStatus(Ydb::StatusIds::SUCCESS);
PassAway();
}

template <typename T>
void HandleAndDie(T& event) {
GrpcRequestBaseCtx_->FinishSpan();
Expand Down
8 changes: 7 additions & 1 deletion ydb/core/grpc_services/grpc_request_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ class TGRpcRequestProxyImpl
NYql::TIssues()});
}

void Handle(TEvRequestAuthAndCheck::TPtr& ev, const TActorContext&) {
ev->Get()->FinishSpan();
ev->Get()->ReplyWithYdbStatus(Ydb::StatusIds::SUCCESS);
}

// returns true and defer event if no updates for given database
// otherwice returns false and leave event untouched
template <typename TEvent>
Expand Down Expand Up @@ -186,7 +191,7 @@ class TGRpcRequestProxyImpl
if (maybeDatabaseName && !maybeDatabaseName.GetRef().empty()) {
databaseName = CanonizePath(maybeDatabaseName.GetRef());
} else {
if (!AllowYdbRequestsWithoutDatabase && DynamicNode) {
if (!AllowYdbRequestsWithoutDatabase && DynamicNode && !std::is_same_v<TEvent, TEvRequestAuthAndCheck>) { // TEvRequestAuthAndCheck is allowed to be processed without database
requestBaseCtx->ReplyUnauthenticated("Requests without specified database are not allowed");
requestBaseCtx->FinishSpan();
return;
Expand Down Expand Up @@ -590,6 +595,7 @@ void TGRpcRequestProxyImpl::StateFunc(TAutoPtr<IEventHandle>& ev) {
HFunc(TEvCoordinationSessionRequest, PreHandle);
HFunc(TEvNodeCheckRequest, PreHandle);
HFunc(TEvProxyRuntimeEvent, PreHandle);
HFunc(TEvRequestAuthAndCheck, PreHandle);

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

0 comments on commit b810317

Please sign in to comment.