限制Postgres中非超级用户角色的访问权限

时间:2018-07-30 06:17:53

标签: postgresql permissions roles

我在postgres中扮演两个角色,一个是 postgres ,它是超级管理员,另一个是 developers ,它仅创建数据库< / strong>仅访问。

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

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

复制步骤:

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

我不应该访问{strong> developers 角色之外的其他数据库,例如another_db的{​​{1}}

我试图撤消访问权限

postgres

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

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

1 个答案:

答案 0 :(得分:0)

CONNECT从未被授予该用户,因此吊销它没有任何作用。

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

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