Skip to content

Commit 47691b2

Browse files
Configure cluster access resource Id for Nebius_v1 (#16614)
1 parent 8f837fc commit 47691b2

File tree

4 files changed

+47
-23
lines changed

4 files changed

+47
-23
lines changed

ydb/core/grpc_services/grpc_request_check_actor.h

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,36 @@ bool TGRpcRequestProxyHandleMethods::ValidateAndReplyOnError(TCtx* ctx) {
4040
}
4141

4242
inline const TVector<TEvTicketParser::TEvAuthorizeTicket::TEntry>& GetEntriesForAuthAndCheckRequest(TEvRequestAuthAndCheck::TPtr& ev) {
43-
if (ev->Get()->YdbToken && ev->Get()->YdbToken->StartsWith("Bearer")) {
44-
if (AppData()->AuthConfig.GetUseAccessService()
45-
&& (AppData()->DomainsConfig.GetSecurityConfig().ViewerAllowedSIDsSize() > 0 || AppData()->DomainsConfig.GetSecurityConfig().MonitoringAllowedSIDsSize() > 0)) {
46-
static TVector<NKikimr::TEvTicketParser::TEvAuthorizeTicket::TEntry> entries = {
47-
{NKikimr::TEvTicketParser::TEvAuthorizeTicket::ToPermissions({"ydb.developerApi.get", "ydb.developerApi.update"}), {{"gizmo_id", "gizmo"}}}
48-
};
49-
return entries;
43+
const bool isBearerToken = ev->Get()->YdbToken && ev->Get()->YdbToken->StartsWith("Bearer");
44+
const bool useAccessService = AppData()->AuthConfig.GetUseAccessService();
45+
const bool hasClusterAccessResourceId = !AppData()->AuthConfig.GetClusterAccessResourceId().empty();
46+
const bool needClusterAccessResourceCheck = AppData()->DomainsConfig.GetSecurityConfig().ViewerAllowedSIDsSize() > 0 ||
47+
AppData()->DomainsConfig.GetSecurityConfig().MonitoringAllowedSIDsSize() > 0;
48+
49+
if (!isBearerToken || !useAccessService || !hasClusterAccessResourceId || !needClusterAccessResourceCheck) {
50+
static const TVector<NKikimr::TEvTicketParser::TEvAuthorizeTicket::TEntry> emptyEntries = {};
51+
return emptyEntries;
52+
}
53+
54+
auto makeEntries = []() -> TVector<NKikimr::TEvTicketParser::TEvAuthorizeTicket::TEntry> {
55+
const TString& accessServiceType = AppData()->AuthConfig.GetAccessServiceType();
56+
TVector<TString> permissions;
57+
if (accessServiceType == "Yandex_v2") {
58+
permissions = {"ydb.developerApi.get", "ydb.developerApi.update"};
59+
} else if (accessServiceType == "Nebius_v1") {
60+
permissions = {"ydb.clusters.get", "ydb.clusters.monitor", "ydb.clusters.manage"};
61+
} else {
62+
return {};
5063
}
51-
}
52-
static TVector<NKikimr::TEvTicketParser::TEvAuthorizeTicket::TEntry> emptyEntries = {};
53-
return emptyEntries;
64+
const TString& clusterAccessResourceId = AppData()->AuthConfig.GetClusterAccessResourceId();
65+
TVector<NKikimr::TEvTicketParser::TEvAuthorizeTicket::TEntry> entries = {
66+
{NKikimr::TEvTicketParser::TEvAuthorizeTicket::ToPermissions(permissions), {{"gizmo_id", clusterAccessResourceId}}}
67+
};
68+
return entries;
69+
};
70+
71+
static TVector<NKikimr::TEvTicketParser::TEvAuthorizeTicket::TEntry> entries = makeEntries();
72+
return entries;
5473
}
5574

5675
template <typename TEvent>

ydb/core/protos/auth.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ message TAuthConfig {
5858
optional string NodeRegistrationToken = 82 [default = "root@builtin", (Ydb.sensitive) = true];
5959
optional TPasswordComplexity PasswordComplexity = 83;
6060
optional TAccountLockout AccountLockout = 84;
61+
optional string ClusterAccessResourceId = 85 [default = "gizmo"];
6162
}
6263

6364
message TUserRegistryConfig {

ydb/core/security/ticket_parser_impl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,12 @@ class TTicketParserImpl : public TActorBootstrapped<TDerived> {
479479
if (const auto folderId = record.GetAttributeValue(permission, "folder_id"); folderId) {
480480
AddNebiusContainerId(pathsContainer, folderId);
481481
}
482+
483+
// Use attribute "gizmo_id" as container id that contains cluster access resource
484+
// IAM can link roles for cluster access resource
485+
if (const auto gizmoId = record.GetAttributeValue(permission, "gizmo_id"); gizmoId) {
486+
AddNebiusContainerId(pathsContainer, gizmoId);
487+
}
482488
}
483489

484490
template <typename TTokenRecord>

ydb/core/security/ticket_parser_ut.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,19 +1661,17 @@ Y_UNIT_TEST_SUITE(TTicketParserTest) {
16611661
UNIT_ASSERT_C(result->Error.empty(), result->Error);
16621662
UNIT_ASSERT_C(result->Token->IsExist("something.read-bbbb4554@as"), result->Token->ShortDebugString());
16631663

1664-
if constexpr (!IsNebiusAccessService<TAccessServiceMock>()) {
1665-
// Authorization successful for gizmo resource
1666-
accessServiceMock.AllowedResourceIds.clear();
1667-
accessServiceMock.AllowedResourceIds.emplace("gizmo");
1668-
runtime->Send(new IEventHandle(MakeTicketParserID(), sender, new TEvTicketParser::TEvAuthorizeTicket(
1669-
userToken,
1670-
{{"gizmo_id", "gizmo"}, },
1671-
{"monitoring.view"})), 0);
1672-
result = runtime->GrabEdgeEvent<TEvTicketParser::TEvAuthorizeTicketResult>(handle);
1673-
UNIT_ASSERT_C(result->Error.empty(), result->Error);
1674-
UNIT_ASSERT_C(result->Token->IsExist("monitoring.view@as"), result->Token->ShortDebugString());
1675-
UNIT_ASSERT_C(result->Token->IsExist("monitoring.view-gizmo@as"), result->Token->ShortDebugString());
1676-
}
1664+
// Authorization successful for gizmo resource
1665+
accessServiceMock.AllowedResourceIds.clear();
1666+
accessServiceMock.AllowedResourceIds.emplace("gizmo");
1667+
runtime->Send(new IEventHandle(MakeTicketParserID(), sender, new TEvTicketParser::TEvAuthorizeTicket(
1668+
userToken,
1669+
{{"gizmo_id", "gizmo"}, },
1670+
{"monitoring.view"})), 0);
1671+
result = runtime->GrabEdgeEvent<TEvTicketParser::TEvAuthorizeTicketResult>(handle);
1672+
UNIT_ASSERT_C(result->Error.empty(), result->Error);
1673+
UNIT_ASSERT_C(result->Token->IsExist("monitoring.view@as"), result->Token->ShortDebugString());
1674+
UNIT_ASSERT_C(result->Token->IsExist("monitoring.view-gizmo@as"), result->Token->ShortDebugString());
16771675
}
16781676

16791677
Y_UNIT_TEST(Authorization) {

0 commit comments

Comments
 (0)