默认ACL
该项目在PostgreSQL 9.0中基本完成。另请参阅
- GRANT / REVOKE 在SCHEMA中
- ALTER DEFAULT PRIVILEGES
- pg_default_acl
描述
在TODO中我们有
允许GRANT/REVOKE权限根据模式权限被对象继承
这是一个关于为新创建的对象实现默认ACL/权限的提议。这仅在对象创建时进行(有一个单独的TODO项目用于使用通配符或类似方法对多个对象执行grant/revoke;如果我对此提出建议,那将是另一个维基页面)。
为什么要这样做
管理大型复杂数据库的权限非常费力。DBA被迫使用GUI工具或临时脚本,这些工具和脚本笨拙且容易出错。因此,许多DBA根本不创建和维护适当的角色设置,并运行不安全的数据库。我们每周在IRC上至少收到5次关于为新数据库提供更好的权限管理的请求。
允许DBA为新对象设置默认权限将大大简化实现数据库角色设置的任务。这也是朝着拥有更复杂的基于角色的管理工具迈出的一小步。
人员
目前参与设计和实施的人员
Stephen Frost - Project lead, developed catalog changes patch Emilie Giustozzi - Working on grammar changes Josh Berkus - Consulting on design & grammar, helping with the wiki Petr Jelinek - Initial gram.y patch, most of coding Simon Riggs - usability review
目录
pg_namespace_default_acl (names can be changed to protect the innocent) defaclnamespace - OID of the schema defaclgrantobjtype - Grantable object kind, char(1) similar to relkind but for all types of grantable objects; this is already defined in an enum in parsenodes.h: GrantObjectType or some such 'r' - table 'v' - view 'f' - function 'S' - sequence 'C' - column -- Probably can't support this, to be honest. It would imply knowing that all tables created have the column(s) referenced, and would cause errors most likely if the column wasn't there, which isn't good. 'l' - language 'W' - foreign-data wrapper 'F' - foreign server defacllist[] - array of acls that the object should have on creation this is NOT a mask, it's exactly what the object will get, in other words, the default PG perms are ignored if this is a def_acl in here for that schema/obj_kind This will look like a regular list of perms, eg: {role1=arwd/sfrost,role2=r/sfrost} Full row examples: 2200, 'r', '{role1=arwd/sfrost,role2=r/sfrost}' 2200, 'v', '{role1=r/sfrost,role2=r/sfrost}'
语法
当前(截至2009-07-14)的WIP补丁:[ 媒体:Defaultacls.diff.gz ]
当前语法是根据Josh的想法实现的,并做了一些小调整。
简单语法
ALTER SCHEMA blah SET DEFAULT PRIVILEGES ON TABLE SELECT TO public; ALTER SCHEMA blah SET DEFAULT PRIVILEGES ON TABLE SELECT TO webuser,admin AND UPDATE to admin AND INSERT to admin AND DELETE to admin; ALTER SCHEMA blah ADD DEFAULT PRIVILEGES ON TABLE INSERT TO webuser; ALTER SCHEMA blab DROP DEFAULT PRIVILEGES ON TABLE DELETE FROM admin;
对多个用户授予多个权限
ALTER SCHEMA blah SET DEFAULT PRIVILEGES ON TABLE SELECT to webuser,admin AND UPDATE,INSERT,DELETE to admin;
以及最复杂的语法,对多个用户授予对不同对象的多个不同权限
ALTER SCHEMA blah SET DEFAULT PRIVILEGES ON TABLE SELECT TO webuser,admin AND UPDATE,INSERT,DELETE TO admin ON VIEW SELECT TO webuser,admin;
语法建议
添加到ALTER SCHEMA以支持此功能的新语法注意:不使用grant/revoke术语(或这些命令),因为这意味着对于现有对象实际上会发生一些事情,而事实并非如此。这仅适用于正在创建的新对象所有这些都取决于gram.y的接受,当然。
建议#1
ALTER SCHEMA blah SET DEFAULT ACL TABLE select to role1,role2 TABLE insert to role2 VIEW select to role1;
建议#2:可能更好
Force types to be done separately and reorder things: ALTER SCHEMA blah SET DEFAULT TABLE ACL select to role1,role2 ACL insert to role2; ALTER SCHEMA blah SET DEFAULT VIEW ACL select to role1; Also allow using all for either side (priv list or role list): ALTER SCHEMA blah DROP DEFAULT VIEW ACL all from role1; ALTER SCHEMA blah DROP DEFAULT TABLE ACL select from all; ALTER SCHEMA blah ADD DEFAULT TABLE ACL all TO role1; All for 'ADD' implies public, below mean the same ALTER SCHEMA blah ADD DEFAULT TABLE ACL SELECT TO all; ALTER SCHEMA blah ADD DEFAULT TABLE ACL SELECT TO public;
建议#3
(Josh Berkus)我更喜欢更自然的语言语法,只要我们可以让gram.y支持它。此外,我认为“ACL”作为关键字令人困惑,而“permissions”既更清晰,也不太可能成为用户数据库对象的名称。
ALTER SCHEMA blah SET DEFAULT PERMISSIONS ON TABLE SELECT TO public; ALTER SCHEMA blah SET DEFAULT PERMISSIONS ON TABLE SELECT TO webuser,admin AND UPDATE to admin AND INSERT to admin AND DELETE to admin; ALTER SCHEMA blah ADD DEFAULT PERMISSIONS ON TABLE INSERT TO webuser; ALTER SCHEMA blab DROP DEFAULT PERMISSIONS ON TABLE DELETE FROM admin;
标点符号可能会根据gram.y的容忍度而有所不同。如果它对下面内容感到满意,这将更好
ALTER SCHEMA blah SET DEFAULT PERMISSIONS ON TABLE SELECT to webuser,admin AND UPDATE,INSERT,DELETE to admin;
我们也可能能够做到
ALTER SCHEMA blah SET DEFAULT PERMISSIONS ON TABLE SELECT TO webuser,admin AND UPDATE,INSERT,DELETE TO admin AND ON VIEW SELECT TO webuser,admin;
建议#4
(我们要做的事情)基本上,Josh的建议是我们目前的方向。Emilie Giustozzi正在努力更改gram.y以实现它。正如她正确指出的那样,我们将使用PRIVILEGES而不是PERMISSIONS,因为PRIVILEGES已经是PG中的关键或半关键词。
建议#5
(gsmet)我发现提议的语法中的“ON TABLE SELECT”部分令人困惑。
我更喜欢模仿GRANT语法的语法
ALTER SCHEMA blah SET DEFAULT PRIVILEGES GRANT SELECT ON TABLE TO webuser; ALTER SCHEMA blah SET DEFAULT PRIVILEGES GRANT UPDATE, INSERT ON TABLE TO admin, superadmin;
或者没有GRANT关键字
ALTER SCHEMA blah SET DEFAULT PRIVILEGES SELECT ON TABLE TO webuser; ALTER SCHEMA blah SET DEFAULT PRIVILEGES UPDATE, INSERT ON TABLE TO admin, superadmin;
Simon说:如果我们这样做,我们应该使用PRIVILEGE而不是复数
建议#6
如果我们为此有一个ALTER SCHEMA命令,那么用户将需要同时发出一个GRANT来更改现有表和一个ALTER SCHEMA来更改新表。寻求一个可以同时更改新表和现有表的权限的单一命令似乎更自然。
所以,我建议
GRANT .... ON SCHEMA ..... [WITH DEFAULT OPTION];
因此,我们使用GRANT设置现有表,并使用GRANT ON ALL ... WITH DEFAULT OPTION设置现有表和新表。这更容易使用,因为它是一个单一命令,学习的额外语法很少,文档也更集中。它还以类似于GRANT ALL建议的扩展方式扩展了GRANT。
如果需要,这个概念可以轻松地扩展到其他对象类型。
我们还需要在需要时将默认值设置为“无默认值”的功能。
REVOKE DEFAULT OPTION FOR ..... ON SCHEMA ....
PJMODOS说:@Simon 我记得Tom说过GRANT不应影响任何将来的权限,这就是我们使用ALTER SCHEMA的原因。此外,你的方法不允许我们仅对新对象授予权限,而不会影响现有对象。
其他想法
建议#3:也许也支持语法来实现对象的默认ACL,这将彻底替换现有的权限,例如
ALTER TABLE blah SET DEFAULT ACL; Alternatively, for the arguments above, perhaps have GRANT syntax support this general capability, eg: GRANT DEFAULT ON TABLE blah;
也支持ADD/DROP default acl,以便可以添加到def_acls[]列表中和从列表中删除,这样你就不必总是指定整个列表。如果使用“set”,则所有内容都将被提供的内容替换。
所有权的可能语法
This will probably be implemented separately as there is some concern about security. Intent is to implement this as essentially a 'ALTER TABLE blah OWNER TO role1;' as the user creating the table, so they will need the same perms they need to do that to begin with. This is just a convenience mechanism, not a change in what people are allowed to do. Should mean that you need to be a member of the role you're changing the ownership to, and that role need CREATE rights on the schema. ALTER SCHEMA blah ADD DEFAULT TABLE OWNER role1;
建议#4
Support defaults attached to the creating user rather than the schema that the object is created in. For instance: ALTER USER webuser_admin SET DEFAULT PRIVILEGES SELECT ON TABLE TO webuser_read_only; would mean that all tables created by webuser_admin would grant privileges for SELECT to webuser_read_only.
权限
设置模式的默认权限可能也需要单独的权限。这将允许DBA授予用户创建表的权限,但阻止他们更改底层管理结构。
我们需要为新对象定义默认所有者。这将等同于在创建表后立即运行REASSIGN OWNED BY current_role TO default_role;。