Skip to content

Commit 65bc867

Browse files
authored
Fix cluster permissions check under grpc (#20744)
1 parent 5d7b5f5 commit 65bc867

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

ydb/core/grpc_services/grpc_request_check_actor.h

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ bool TGRpcRequestProxyHandleMethods::ValidateAndReplyOnError(TCtx* ctx) {
3939
}
4040
}
4141

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

4849
if (!isBearerToken || !useAccessService || !needClusterAccessResourceCheck) {
4950
return {};
@@ -56,7 +57,23 @@ inline TVector<TEvTicketParser::TEvAuthorizeTicket::TEntry> GetEntriesForAuthAnd
5657
{NKikimr::TEvTicketParser::TEvAuthorizeTicket::ToPermissions({"ydb.developerApi.get", "ydb.developerApi.update"}), {{"gizmo_id", "gizmo"}}}
5758
};
5859
return entries;
59-
} else if (accessServiceType == "Nebius_v1") {
60+
} else {
61+
return {};
62+
}
63+
}
64+
65+
inline TVector<TEvTicketParser::TEvAuthorizeTicket::TEntry> GetEntriesForClusterAccessCheck(const TVector<std::pair<TString, TString>>& rootAttributes) {
66+
const bool useAccessService = AppData()->AuthConfig.GetUseAccessService();
67+
const bool needClusterAccessResourceCheck = AppData()->DomainsConfig.GetSecurityConfig().ViewerAllowedSIDsSize() > 0 ||
68+
AppData()->DomainsConfig.GetSecurityConfig().MonitoringAllowedSIDsSize() > 0 ||
69+
AppData()->DomainsConfig.GetSecurityConfig().AdministrationAllowedSIDsSize() > 0;
70+
71+
if (!useAccessService || !needClusterAccessResourceCheck) {
72+
return {};
73+
}
74+
75+
const TString& accessServiceType = AppData()->AuthConfig.GetAccessServiceType();
76+
if (accessServiceType == "Nebius_v1") {
6077
static const auto permissions = NKikimr::TEvTicketParser::TEvAuthorizeTicket::ToPermissions({
6178
"ydb.clusters.get", "ydb.clusters.monitor", "ydb.clusters.manage"
6279
});
@@ -124,10 +141,13 @@ class TGrpcRequestCheckActor
124141
}
125142

126143
if constexpr (std::is_same_v<TEvent, TEvRequestAuthAndCheck>) {
127-
const auto& e = GetEntriesForAuthAndCheckRequest(Request_, rootAttributes);
128-
entries.insert(entries.end(), e.begin(), e.end());
144+
TVector<TEvTicketParser::TEvAuthorizeTicket::TEntry> authCheckRequestEntries = GetEntriesForAuthAndCheckRequest(Request_);
145+
entries.insert(entries.end(), authCheckRequestEntries.begin(), authCheckRequestEntries.end());
129146
}
130147

148+
TVector<TEvTicketParser::TEvAuthorizeTicket::TEntry> clusterAccessCheckEntries = GetEntriesForClusterAccessCheck(rootAttributes);
149+
entries.insert(entries.end(), clusterAccessCheckEntries.begin(), clusterAccessCheckEntries.end());
150+
131151
if (!entries.empty()) {
132152
SetEntries(entries);
133153
}

0 commit comments

Comments
 (0)