gpt4 book ai didi

sql - PostgreSQL 不会递归地撤销角色

转载 作者:行者123 更新时间:2023-11-29 13:56:12 25 4
gpt4 key购买 nike

我在 Windows 7 SP1 64 位上使用 PostgreSQL 9.4,在撤销角色时遇到问题。假设我有三个用户:taylor、michelle 和 super 用户 postgres。作为 postgres,我通过管理员选项将角色“utente”授予 taylor

--postgres@localhost:5432
GRANT utente TO taylor WITH ADMIN OPTION;

然后,作为 taylor,我将 utente 的角色授予 michelle

--taylor@localhost:5432
GRANT utente TO michelle;

最后,作为 postgres,我撤销了 taylor 的 utente 角色

--postgres@localhost:5432
REVOKE utente FROM taylor

这个角色也应该递归地从 michelle 那里撤消,因为她只从 taylor 那里获得了这个角色。但事实并非如此,泰勒失去了这个角色,但米歇尔保留了它。我尝试使用 RESTRICT 选项运行命令,这应该会阻止它被执行,但它不起作用,命令以完全相同的方式执行,taylor 失去了角色,而 michelle 保留了角色。谁能给我解释一下?

谢谢。

最佳答案

RESTRICT 选项由 PostgreSQL 隐式应用,因此您不必显式指定它。

根据documentation :

A user can only revoke privileges that were granted directly by that user. If, for example, user A has granted a privilege with grant option to user B, and user B has in turned granted it to user C, then user A cannot revoke the privilege directly from C. Instead, user A could revoke the grant option from user B and use the CASCADE option so that the privilege is in turn revoked from user C.

所以:

REVOKE utente FROM taylor CASCADE;

但是正如您所指出的,这是行不通的。看起来这是文档中的错误或错误。

在干净的运行中:

patrick@puny:~$ psql -d pfams
psql (9.4.4)
Type "help" for help.

pfams=# SET SESSION AUTHORIZATION postgres;
SET
pfams=# CREATE ROLE utente NOLOGIN;
CREATE ROLE
pfams=# CREATE ROLE taylor LOGIN;
CREATE ROLE
pfams=# CREATE ROLE michelle LOGIN;
CREATE ROLE
pfams=# GRANT utente TO taylor WITH ADMIN OPTION;
GRANT ROLE
pfams=# SET SESSION AUTHORIZATION taylor;
SET
pfams=> GRANT utente TO michelle;
GRANT ROLE
pfams=# SET SESSION AUTHORIZATION postgres;
SET
pfams=# REVOKE utente FROM taylor CASCADE;
REVOKE ROLE
pfams=# \du taylor
List of roles
Role name | Attributes | Member of
-----------+------------+-----------
taylor | | {}

pfams=# \du michelle
List of roles
Role name | Attributes | Member of
-----------+------------+-----------
michelle | | {utente}

也许可以向 PostgreSQL 错误邮件列表报告一些事情。

关于sql - PostgreSQL 不会递归地撤销角色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31218721/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com