简体   繁体   English

DEFAULT PRIVILEGES 语句是否可能由另一个非超级用户角色所有?

[英]Is it possible for DEFAULT PRIVILEGES statements to be owned by another non-superuser role?

I am an accidental DBA for an environment where we are trying to not have any individual employee user own anything.我是一个偶然的 DBA,在我们试图不让任何个人员工用户拥有任何东西的环境中。 (This is so that we can DROP ROLE on an employee's access when needed without first researching / re-homing a lot of objects.) (这样我们就可以在需要时对员工的访问权限 DROP ROLE,而无需先研究/重新归位大量对象。)

We are also trying to make sure that we can automate, as much as possible, the access privileges associated with newly created objects.我们还试图确保我们可以尽可能自动化与新创建的对象相关的访问权限。

Employees have access to CREATE objects by virtue of being in an ownership role that has CREATE permissions on schemas where they are allowed to.员工可以访问 CREATE 对象,因为他们处于所有权角色中,该角色对他们被允许的模式具有 CREATE 权限。 If an employee needs to create a new object, the SOP is to SET ROLE to the ownership role before executing the CREATE transaction, because the ownership roles have DEFAULT PRIVILEGES statements set up to ensure that new objects they create have the right privileges for different groups of employees who need varying levels of access.如果一个员工需要创建一个新对象,SOP是在执行CREATE事务之前给所有权角色SET ROLE,因为所有权角色设置了DEFAULT PRIVILEGES语句,以确保他们创建的新对象对不同的组拥有正确的权限需要不同级别访问权限的员工。

If the employee doesn't follow SOP and forgets to SET ROLE beforehand, their role has access to create the object (since they're a member of the owning role) but it will not have the right privileges until they also remember to GRANT them.如果员工不遵守 SOP 并忘记事先设置角色,他们的角色有权创建对象(因为他们是拥有角色的成员),但除非他们还记得授予他们,否则它不会拥有正确的权限.

The solution appeared to be to write DEFAULT PRIVILEGES statements for each user to mirror those set up for the owning role.解决方案似乎是为每个用户编写 DEFAULT PRIVILEGES 语句,以反映为拥有角色设置的那些语句。 However, we found that even if those DEFAULT PRIVILEGES are written for objects created by a user role while in a second administrative role, the privileges themselves are still owned by the first role.但是,我们发现,即使这些 DEFAULT PRIVILEGES 是为用户角色在第二个管理角色中创建的对象编写的,这些权限本身仍然归第一个角色所有。 This violates the design we're trying to establish.这违反了我们试图建立的设计。

I think we've bumped into a fundamental reality of the Postgres architecture;我认为我们已经遇到了 Postgres 架构的一个基本现实; it seems that we can't simultaneously permit a system where employees could (unintentionally) create objects under their own role and allow those objects to have DEFAULT PRIVILEGES unless we're willing to allow those roles to own the DEFAULT PRIVILEGES.似乎我们不能同时允许员工可​​以(无意)在他们自己的角色下创建对象允许这些对象具有默认权限的系统,除非我们愿意允许这些角色拥有默认权限。

Is that right?那正确吗? Are we trying to have our cake and eat it too?我们是否想拥有我们的蛋糕并也吃它?


For additional context:对于其他上下文:

No one on my team has access to superuser permissions for the database;我的团队中没有人有权访问数据库的超级用户权限; anything under a superuser must be requested from IT.必须从 IT 请求超级用户下的任何内容。 (So we're trying to avoid a system that needs superuser permissions.) (所以我们试图避免需要超级用户权限的系统。)

One solution is to define roles like this:一种解决方案是定义这样的角色:

-- role that can create tables
CREATE ROLE table_owner NOLOGIN;
-- because it has the permission on the schema
GRANT CREATE ON SCHEMA myschema TO table_owner;

-- role that can do INSERT, SELECT, UPDATE, DELETE
CREATE ROLE dml_role NOLOGIN;
-- give it permissions
GRANT INSERT, SELECT, UPDATE, DELETE
   ON ALL TABLES IN SCHEMA myschema TO dml_role;
-- also for future tables
ALTER DEFAULT PRIVILEGES FOR table_owner IN SCHEMA myschema
   GRANT INSERT, SELECT, UPDATE, DELETE ON TABLES TO dml_role;

-- intermediary role that does *not* inherit privileges
CREATE ROLE break_inherit NOLOGIN NOINHERIT IN ROLE table_owner;

-- end user
CREATE ROLE enduser LOGIN IN ROLE dml_role, break_inherit;

Now enduser cannot create tables in myschema directly, because it does not inherit from that role.现在enduser无法直接在myschema创建表,因为它不继承自该角色。 So enduser can only create a table of it does SET ROLE table_owner first!所以enduser只能先创建一张它的表SET ROLE table_owner

But enduser automatically has privileges to work with the tables in myschema that belong to table_owner , because it inherits from dml_role .但是enduser自动拥有使用myschema中属于table_owner的表的权限,因为它继承自dml_role

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 非超级用户数据库管理 - Non-SuperUser Database Management 使用 Postgresql 以非超级用户用户身份创建演员表 - Create cast as a non-superuser user with Postgresql 使用非超级用户帐户获取大对象的实际数据 - Get the actual data of the large object using non-superuser account 如果服务器在使用 dblink 时不请求密码,则非超级用户无法连接 - Non-superuser cannot connect if the server does not request a password while using dblink 如何授予非超级用户特权以执行函数pg_read_binary_file? - How to GRANT priveleges to non-superuser to execute function pg_read_binary_file? Postgresql 外部数据包装器错误 如果服务器未请求密码,则非超级用户无法连接 - Postgresql Foreign data wrapper error Non-superuser cannot connect if the server does not request a password postgres不允许更改角色超级用户,而我的默认用户不是超级用户 - postgres will not allow alter role superuser and my default user isnt superuser 具有默认权限的 PostgreSQL 删除角色 - PostgreSQL drop role with default privileges 只读角色的 Postgres 默认权限 - Postgres default privileges for readonly role 选择当前角色作为非超级用户的数据库 - Select databases for current role as non superuser
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM