Skip to content

Commit be7fe5b

Browse files
authored
Fix cluster permissions check under grpc (#20744) (#20763)
1 parent d6121f9 commit be7fe5b

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
@@ -38,11 +38,12 @@ bool TGRpcRequestProxyHandleMethods::ValidateAndReplyOnError(TCtx* ctx) {
3838
}
3939
}
4040

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

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

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

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

0 commit comments

Comments
 (0)