Skip to content

SystemView Auth Permissions #13403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions ydb/core/sys_view/auth/owners.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@ class TOwnersScan : public TAuthScanBase<TOwnersScan> {
// TODO: add rows according to request's sender user rights

auto entryPath = CanonizePath(entry.Path);
auto entryOwner = entry.Self->Info.GetOwner();

for (auto& column : Columns) {
switch (column.Tag) {
case Schema::AuthOwners::Path::ColumnId:
cells.push_back(TCell(entryPath.data(), entryPath.size()));
break;
case Schema::AuthOwners::Sid::ColumnId:
cells.push_back(TCell(entryOwner.data(), entryOwner.size()));
if (entry.SecurityObject->HasOwnerSID()) {
cells.push_back(TCell(entry.SecurityObject->GetOwnerSID().data(), entry.SecurityObject->GetOwnerSID().size()));
} else {
cells.emplace_back();
}
break;
default:
cells.emplace_back();
Expand Down
89 changes: 89 additions & 0 deletions ydb/core/sys_view/auth/permissions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#include "auth_scan_base.h"
#include "permissions.h"

#include <ydb/core/sys_view/common/events.h>
#include <ydb/core/sys_view/common/schema.h>
#include <ydb/core/sys_view/common/scan_actor_base_impl.h>
#include <ydb/core/base/tablet_pipecache.h>
#include <ydb/core/ydb_convert/ydb_convert.h>
#include <ydb/library/login/protos/login.pb.h>

#include <ydb/library/actors/core/hfunc.h>

namespace NKikimr::NSysView::NAuth {

using namespace NSchemeShard;
using namespace NActors;

class TPermissionsScan : public TAuthScanBase<TPermissionsScan> {
public:
using TScanBase = TScanActorBase<TPermissionsScan>;
using TAuthBase = TAuthScanBase<TPermissionsScan>;

TPermissionsScan(bool effective, const NActors::TActorId& ownerId, ui32 scanId, const TTableId& tableId,
const TTableRange& tableRange, const TArrayRef<NMiniKQL::TKqpComputeContextBase::TColumn>& columns)
: TAuthBase(ownerId, scanId, tableId, tableRange, columns)
, Effective(effective)
{
}

protected:
void FillBatch(NKqp::TEvKqpCompute::TEvScanData& batch, const TNavigate::TEntry& entry) override {
Y_ABORT_UNLESS(entry.Status == TNavigate::EStatus::Ok);

TVector<TCell> cells(::Reserve(Columns.size()));

// TODO: add rows according to request's sender user rights

auto entryPath = CanonizePath(entry.Path);

for (const NACLibProto::TACE& ace : entry.SecurityObject->GetACL().GetACE()) {
if (ace.GetAccessType() != (ui32)NACLib::EAccessType::Allow) {
continue;
}
if (!Effective && ace.GetInherited()) {
continue;
}

auto permissions = ConvertACLMaskToYdbPermissionNames(ace.GetAccessRight());
for (const auto& permission : permissions) {
for (auto& column : Columns) {
switch (column.Tag) {
case Schema::AuthPermissions::Path::ColumnId:
cells.push_back(TCell(entryPath.data(), entryPath.size()));
break;
case Schema::AuthPermissions::Sid::ColumnId:
if (ace.HasSID()) {
cells.push_back(TCell(ace.GetSID().data(), ace.GetSID().size()));
} else {
cells.emplace_back();
}
break;
case Schema::AuthPermissions::Permission::ColumnId:
cells.push_back(TCell(permission.data(), permission.size()));
break;
default:
cells.emplace_back();
}
}

TArrayRef<const TCell> ref(cells);
batch.Rows.emplace_back(TOwnedCellVec::Make(ref));
cells.clear();
}
}

batch.Finished = false;
}

private:
const bool Effective;
};

THolder<NActors::IActor> CreatePermissionsScan(bool effective, const NActors::TActorId& ownerId, ui32 scanId, const TTableId& tableId,
const TTableRange& tableRange, const TArrayRef<NMiniKQL::TKqpComputeContextBase::TColumn>& columns)
{
return MakeHolder<TPermissionsScan>(effective, ownerId, scanId, tableId, tableRange, columns);
}

}
13 changes: 13 additions & 0 deletions ydb/core/sys_view/auth/permissions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <ydb/core/kqp/runtime/kqp_compute.h>

#include <ydb/library/actors/core/actor.h>
#include <ydb/library/actors/core/actorid.h>

namespace NKikimr::NSysView::NAuth {

THolder<NActors::IActor> CreatePermissionsScan(bool effective, const NActors::TActorId& ownerId, ui32 scanId, const TTableId& tableId,
const TTableRange& tableRange, const TArrayRef<NMiniKQL::TKqpComputeContextBase::TColumn>& columns);

}
2 changes: 2 additions & 0 deletions ydb/core/sys_view/auth/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ SRCS(
groups.h
owners.cpp
owners.h
permissions.cpp
permissions.h
users.cpp
users.h
)
Expand Down
2 changes: 2 additions & 0 deletions ydb/core/sys_view/common/schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ class TSystemViewResolver : public ISystemViewResolver {
RegisterSystemView<Schema::AuthGroups>(NAuth::GroupsName);
RegisterSystemView<Schema::AuthGroupMembers>(GroupMembersName);
RegisterSystemView<Schema::AuthOwners>(OwnersName);
RegisterSystemView<Schema::AuthPermissions>(PermissionsName);
RegisterSystemView<Schema::AuthPermissions>(EffectivePermissionsName);
}
}

Expand Down
15 changes: 15 additions & 0 deletions ydb/core/sys_view/common/schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ namespace NAuth {
constexpr TStringBuf GroupsName = "auth_groups";
constexpr TStringBuf GroupMembersName = "auth_group_members";
constexpr TStringBuf OwnersName = "auth_owners";
constexpr TStringBuf PermissionsName = "auth_permissions";
constexpr TStringBuf EffectivePermissionsName = "auth_effective_permissions";
}


Expand Down Expand Up @@ -658,6 +660,19 @@ struct Schema : NIceDb::Schema {
>;
};

struct AuthPermissions : Table<19> {
struct Path: Column<1, NScheme::NTypeIds::Utf8> {};
struct Sid: Column<2, NScheme::NTypeIds::Utf8> {};
struct Permission: Column<3, NScheme::NTypeIds::Utf8> {};

using TKey = TableKey<Path, Sid, Permission>;
using TColumns = TableColumns<
Path,
Sid,
Permission
>;
};

struct PgColumn {
NIceDb::TColumnId _ColumnId;
NScheme::TTypeInfo _ColumnTypeInfo;
Expand Down
9 changes: 7 additions & 2 deletions ydb/core/sys_view/scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

#include <ydb/core/kqp/compute_actor/kqp_compute_events.h>

#include <ydb/core/sys_view/auth/group_members.h>
#include <ydb/core/sys_view/auth/groups.h>
#include <ydb/core/sys_view/auth/owners.h>
#include <ydb/core/sys_view/auth/permissions.h>
#include <ydb/core/sys_view/auth/users.h>
#include <ydb/core/sys_view/auth/groups.h>
#include <ydb/core/sys_view/auth/group_members.h>
#include <ydb/core/sys_view/common/schema.h>
#include <ydb/core/sys_view/partition_stats/partition_stats.h>
#include <ydb/core/sys_view/nodes/nodes.h>
Expand Down Expand Up @@ -256,6 +257,10 @@ THolder<NActors::IActor> CreateSystemViewScan(
if (tableId.SysViewInfo == OwnersName) {
return NAuth::CreateOwnersScan(ownerId, scanId, tableId, tableRange, columns);
}
if (tableId.SysViewInfo == PermissionsName || tableId.SysViewInfo == EffectivePermissionsName) {
return NAuth::CreatePermissionsScan(tableId.SysViewInfo == EffectivePermissionsName,
ownerId, scanId, tableId, tableRange, columns);
}
}

return {};
Expand Down
Loading
Loading