【问题标题】:Postgres - Update permissions on tables have no effectPostgres - 更新表的权限无效
【发布时间】:2022-10-07 18:58:13
【问题描述】:

用户:jira_user 数据库:jiradb 作为 postgres 执行命令

GRANT USAGE ON schema public TO jira_user;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO jira_user;
grant all privileges on database jiradb to jira_user;

但即便如此,我在测试服务器上得到以下结果

SELECT * FROM information_schema.table_privileges where table_name = \'AO_013613_ACTIVITY_SOURCE\';
 grantor  |  grantee  | table_catalog | table_schema |        table_name         | privilege_type | is_grantable | with_hierarchy 
----------+-----------+---------------+--------------+---------------------------+----------------+--------------+----------------
 postgres | jira_user | jiradb        | public       | AO_013613_ACTIVITY_SOURCE | INSERT         | NO           | NO
 postgres | jira_user | jiradb        | public       | AO_013613_ACTIVITY_SOURCE | SELECT         | NO           | YES
 postgres | jira_user | jiradb        | public       | AO_013613_ACTIVITY_SOURCE | UPDATE         | NO           | NO
 postgres | jira_user | jiradb        | public       | AO_013613_ACTIVITY_SOURCE | DELETE         | NO           | NO
 postgres | jira_user | jiradb        | public       | AO_013613_ACTIVITY_SOURCE | TRUNCATE       | NO           | NO
 postgres | jira_user | jiradb        | public       | AO_013613_ACTIVITY_SOURCE | REFERENCES     | NO           | NO
 postgres | jira_user | jiradb        | public       | AO_013613_ACTIVITY_SOURCE | TRIGGER        | NO           | NO

从产品服务器 - 它应该看起来像这样

  grantor  |  grantee  | table_catalog | table_schema |        table_name         | privilege_type | is_grantable | with_hierarchy 
-----------+-----------+---------------+--------------+---------------------------+----------------+--------------+----------------
 jira_user | jira_user | jiradb        | public       | AO_013613_ACTIVITY_SOURCE | INSERT         | YES          | NO
 jira_user | jira_user | jiradb        | public       | AO_013613_ACTIVITY_SOURCE | SELECT         | YES          | YES
 jira_user | jira_user | jiradb        | public       | AO_013613_ACTIVITY_SOURCE | UPDATE         | YES          | NO
 jira_user | jira_user | jiradb        | public       | AO_013613_ACTIVITY_SOURCE | DELETE         | YES          | NO
 jira_user | jira_user | jiradb        | public       | AO_013613_ACTIVITY_SOURCE | TRUNCATE       | YES          | NO
 jira_user | jira_user | jiradb        | public       | AO_013613_ACTIVITY_SOURCE | REFERENCES     | YES          | NO
 jira_user | jira_user | jiradb        | public       | AO_013613_ACTIVITY_SOURCE | TRIGGER        | YES          | NO`

必须承认我并不完全喜欢 Postgres,但我希望授权命令能够解决这个问题,然后在 test 中也提供与 prod 中相同的输出。现在意识到第一列显示的是不同的“授予者”。不确定这是否重要。

  • 我确实运行了赠款,但没有效果。但也许我没有完全理解 is_grantable 列。被理解为“授予/未授予”或者在阅读时可能是“可能授予/不可能授予”,这意味着我需要“在更高的层次上”做一些魔法来实现它可授予?

标签: sql postgresql permissions


【解决方案1】:

不同之处在于“prod 服务器”上的权限已被授予WITH GRANT OPTION,因此jira_user 可以将它们授予其他用户。这将是这样的:

RANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public
   TO jira_user WITH GRANT OPTION;

你应该绝不授予TRIGGER 权限。这是一个安全漏洞,因为它允许用户使用您的权限执行任意代码。

【讨论】:

    猜你喜欢
    • 2020-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-10
    • 2020-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多