【问题标题】:limit access of non super-user role in Postgres在 Postgres 中限制非超级用户角色的访问
【发布时间】:2019-01-06 08:25:47
【问题描述】:

我在 postgres 中有两个角色,一个是 postgres,它是 super admin,另一个是 developers,它只是 create db 只能访问。

 Role name  |                         Attributes                         | Member of
------------+------------------------------------------------------------+-----------
 developers | Create DB                                                  | {}
 postgres   | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

我在 developers 下创建了数据库,但是当我访问开发人员角色时,我仍然可以看到不在我下面的其他数据库。

重现步骤:

1) 以开发者身份登录

psql -U developers -d sampledb

2) 使用 \l

检查所有数据库
       Name          |   Owner    | Encoding |   Collate   |    Ctype    |    Access privileges
---------------------+------------+----------+-------------+-------------+-------------------------
 another_db          | postgres   | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres           +
                     |            |          |             |             | postgres=CTc/postgres
 developers          | postgres   | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres           +
                     |            |          |             |             | postgres=CTc/postgres  +
                     |            |          |             |             | developers=CTc/postgres
 sampledb            | developers | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 postgres            | postgres   | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0           | postgres   | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres            +
                     |            |          |             |             | postgres=CTc/postgres
 template1           | postgres   | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres            +
                     |            |          |             |             | postgres=CTc/postgres

我应该无法访问不属于 developers 角色的其他数据库,例如 another_db 拥有的 postgres

我试图撤销访问权限

REVOKE CONNECT ON DATABASE another_db FROM developers;
REVOKE ALL PRIVILEGES ON DATABASE another_db FROM developers;

但我仍然可以将开发人员角色连接到 another_db 数据库

sampledb=> \c another_db
You are now connected to database "another_db" as user "developers".

【问题讨论】:

    标签: postgresql permissions roles


    【解决方案1】:

    CONNECT 从未授予该用户,因此撤销它无效。

    您必须撤销特权FROM PUBLIC 并将其授予应该拥有它的角色。

    没有支持的方式来限制对数据库元数据的访问,例如 PostgreSQL 中的数据库列表。

    【讨论】:

    • 感谢您的回复,我也有一个问题,我以开发人员身份登录,但是当我列出所有数据库时,我可以看到另一个不属于我的数据库。它不应该是可见的,因为开发者不是所有者。
    • 这在 PostgreSQL 中是不可协商的。每个人都可以看到元数据,这在 PostgreSQL 中不被视为安全问题。
    猜你喜欢
    • 1970-01-01
    • 2015-10-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-29
    • 2012-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多