Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions ydb/core/grpc_services/grpc_request_check_actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ bool TGRpcRequestProxyHandleMethods::ValidateAndReplyOnError(TCtx* ctx) {
}
}

inline TVector<TEvTicketParser::TEvAuthorizeTicket::TEntry> GetEntriesForAuthAndCheckRequest(TEvRequestAuthAndCheck::TPtr& ev, const TVector<std::pair<TString, TString>>& rootAttributes) {
inline TVector<TEvTicketParser::TEvAuthorizeTicket::TEntry> GetEntriesForAuthAndCheckRequest(TEvRequestAuthAndCheck::TPtr& ev) {
const bool isBearerToken = ev->Get()->YdbToken && ev->Get()->YdbToken->StartsWith("Bearer");
const bool useAccessService = AppData()->AuthConfig.GetUseAccessService();
const bool needClusterAccessResourceCheck = AppData()->DomainsConfig.GetSecurityConfig().ViewerAllowedSIDsSize() > 0 ||
AppData()->DomainsConfig.GetSecurityConfig().MonitoringAllowedSIDsSize() > 0;
AppData()->DomainsConfig.GetSecurityConfig().MonitoringAllowedSIDsSize() > 0 ||
AppData()->DomainsConfig.GetSecurityConfig().AdministrationAllowedSIDsSize() > 0;

if (!isBearerToken || !useAccessService || !needClusterAccessResourceCheck) {
return {};
Expand All @@ -56,7 +57,23 @@ inline TVector<TEvTicketParser::TEvAuthorizeTicket::TEntry> GetEntriesForAuthAnd
{NKikimr::TEvTicketParser::TEvAuthorizeTicket::ToPermissions({"ydb.developerApi.get", "ydb.developerApi.update"}), {{"gizmo_id", "gizmo"}}}
};
return entries;
} else if (accessServiceType == "Nebius_v1") {
} else {
return {};
}
}

inline TVector<TEvTicketParser::TEvAuthorizeTicket::TEntry> GetEntriesForClusterAccessCheck(const TVector<std::pair<TString, TString>>& rootAttributes) {
const bool useAccessService = AppData()->AuthConfig.GetUseAccessService();
const bool needClusterAccessResourceCheck = AppData()->DomainsConfig.GetSecurityConfig().ViewerAllowedSIDsSize() > 0 ||
AppData()->DomainsConfig.GetSecurityConfig().MonitoringAllowedSIDsSize() > 0 ||
AppData()->DomainsConfig.GetSecurityConfig().AdministrationAllowedSIDsSize() > 0;

if (!useAccessService || !needClusterAccessResourceCheck) {
return {};
}

const TString& accessServiceType = AppData()->AuthConfig.GetAccessServiceType();
if (accessServiceType == "Nebius_v1") {
static const auto permissions = NKikimr::TEvTicketParser::TEvAuthorizeTicket::ToPermissions({
"ydb.clusters.get", "ydb.clusters.monitor", "ydb.clusters.manage"
});
Expand Down Expand Up @@ -124,10 +141,13 @@ class TGrpcRequestCheckActor
}

if constexpr (std::is_same_v<TEvent, TEvRequestAuthAndCheck>) {
const auto& e = GetEntriesForAuthAndCheckRequest(Request_, rootAttributes);
entries.insert(entries.end(), e.begin(), e.end());
TVector<TEvTicketParser::TEvAuthorizeTicket::TEntry> authCheckRequestEntries = GetEntriesForAuthAndCheckRequest(Request_);
entries.insert(entries.end(), authCheckRequestEntries.begin(), authCheckRequestEntries.end());
}

TVector<TEvTicketParser::TEvAuthorizeTicket::TEntry> clusterAccessCheckEntries = GetEntriesForClusterAccessCheck(rootAttributes);
entries.insert(entries.end(), clusterAccessCheckEntries.begin(), clusterAccessCheckEntries.end());

if (!entries.empty()) {
SetEntries(entries);
}
Expand Down
Loading