Database 数据库设计-授予对记录的访问权限
我正在设计一个数据库,限制对某些对象的访问。我的同事和我讨论了不同的方法,主要的候选方法有:1)隐式访问和2)显式访问 为了进行说明,假设有以下表格:Database 数据库设计-授予对记录的访问权限,database,database-design,Database,Database Design,我正在设计一个数据库,限制对某些对象的访问。我的同事和我讨论了不同的方法,主要的候选方法有:1)隐式访问和2)显式访问 为了进行说明,假设有以下表格: User (Id) ObjectA (Id, ParentId) -- Where ParentId is an ObjectA ObjectB (Id, ObjectAId) UserObjectA (UserId, ObjectAId) -- Grants access to an ObjectA UserObjectB (UserId, O
User (Id)
ObjectA (Id, ParentId) -- Where ParentId is an ObjectA
ObjectB (Id, ObjectAId)
UserObjectA (UserId, ObjectAId) -- Grants access to an ObjectA
UserObjectB (UserId, ObjectBId) -- Grants access to an ObjectB
隐式方法:
那么,我们使用这种隐式访问方法是否犯了错误?我肯定会三思而后行,希望有类似设计决策经验的人能给我一些建议。如果你能等一个月,Postgres 9.5将被淘汰,并具有路权安全性。如果你手头有一千万美元,甲骨文现在就有了 目前,或在其他数据库中,您可以模拟行安全性:
create schema protected;
create table protected.foo (
foo_id int primary key,
bar text,
owner name not null default_current user
);
create table protected.foo_children (
foo_child_id int primary key,
foo_id int not null references foo(food_id),
owner name not null default current_user references foo(owner) on update cascade
);
现在一些检查选项视图-如果postgres:
create view public.foo with (security_barrier) as
select
*
from protected.foo
where
owner = current_user
WITH CHECK OPTION;
create view public.foo_children with (security_barrier) as
select
*
from protected.foo_children
where
owner = current_user
WITH CHECK OPTION;
grant delete, insert, select, update on public.foo to some_users;
grant delete, insert, select, update on public.foo_children to some_users;
为了共享,您需要添加更多的表。重要的是,您可以为正确的列编制索引,这样就不会降低性能:
create schema acl;
create table acl.foo (
foo_id int primary key references protected.foo(foo_id),
grantee name not null,
privilege char(1) not null
);
更新您的视图:
create or update view public.foo with (security_barrier) as
select
*
from protected.foo
where
owner = current_user
or exists ( select 1 from acl.foo where privilege in ('s','u','d') and grantee = current_user) );
--add update trigger that checks for update privilege
--add delete trigger that checks for delete privilege
但我们每行需要不止一个“所有者”。UserObjectX表是多对多关系。FWIW,我正在使用SQL Server。