大网数据广告活动
服务器运维问答

GRANT USAGE ON SCHEMA doesn't do anything

· 52CE 我爱测

For whatever reason, our database is not respecting GRANT commands. Below is an example with a newly created user. pddbtest=> create user test_user login; CREATE ROLE then verify user does not have schema permission yet pddbtest=…

问题原文

原帖链接 · Danny C · CC BY-SA 4.0

For whatever reason, our database is not respecting GRANT commands. Below is an example with a newly created user.

pddbtest=> create user test_user login;
CREATE ROLE

then verify user does not have schema permission yet

pddbtest=> SELECT rolname, has_schema_privilege(rolname, 'public', 'usage') from pg_roles where rolname='test_user';
  rolname  | has_schema_privilege
-----------+----------------------
 test_user | f
(1 row)

then grant permission

pddbtest=> grant usage on schema public to test_user;
GRANT

then read if permission exists now (it does not)

pddbtest=> SELECT rolname, has_schema_privilege(rolname, 'public', 'usage') from pg_roles where rolname='test_user';
  rolname  | has_schema_privilege
-----------+----------------------
 test_user | f
(1 row)

Even after granting permission on the schema, which doesn't return any errors, the database still sees the permission as not granted. (if I add a select grant on all tables in schema after, I also still get a schema permission denied error when trying to query any of the tables)

(Search path is "$user",public should that information be relevant)

EDIT: Here is the output of SELECT version(); and \dn+ as requested:

PostgreSQL 10.7 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.9.3, 64-bit


                             List of schemas
   Name    |     Owner      |         Access privileges        | Description 
-----------+----------------+----------------------------------+------------------------
 fnrbaks   | appuser_root   |                                  |
 mask      | maint_user_2   | maint_user_2=UC/maint_user_2+    |
           |                | readonly_viewer=U/maint_user_2   | 
 pganalyze | appuser_root   | appuser_root=UC/appuser_root    +| 
           |                | pganalyze=U/appuser_root        +| 
           |                | pganalyze2=U/appuser_root        | 
 public    | rdsadmin       | appuser_root=UC/rdsadmin        +| standard public schema
           |                | proddb=U/rdsadmin                | 
(4 rows)

已采纳解答

原帖链接 · Daniel Vérité · CC BY-SA 4.0

The public schema belongs here to rdsadmin. A possible explanation to the GRANT not working is that it's run by an under-priviledged user (not rdsadmin and not superuser) that doesn't have the right to grant rights on public:

grant usage on schema public to test_user;

By default if that grant is ineffective, a warning is displayed:

WARNING:  no privileges were granted for "public"

but it depends on the client_min_messages setting. If that setting is below the warning threshold (for instance it's set to error), then the warning is not displayed and you'd have the behavior shown in the question. This can be verified with:

 SHOW client_min_messages;

and changed to a more verbose level with:

SET client_min_messages TO notice;

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-06-11)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。