Skip to content

Commit 7fea32f

Browse files
committed
Allow usage on schema for mdb_read_all_data (#23)
1 parent 84711e8 commit 7fea32f

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

src/backend/catalog/aclchk.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3701,6 +3701,7 @@ pg_namespace_aclmask_ext(Oid nsp_oid, Oid roleid,
37013701
bool isNull;
37023702
Acl *acl;
37033703
Oid ownerId;
3704+
Oid mdb_read_all_data_oid;
37043705

37053706
/* Superusers bypass all permission checking. */
37063707
if (superuser_arg(roleid))
@@ -3754,6 +3755,8 @@ pg_namespace_aclmask_ext(Oid nsp_oid, Oid roleid,
37543755

37553756
ownerId = ((Form_pg_namespace) GETSTRUCT(tuple))->nspowner;
37563757

3758+
mdb_read_all_data_oid = get_role_oid("mdb_read_all_data", true);
3759+
37573760
aclDatum = SysCacheGetAttr(NAMESPACEOID, tuple, Anum_pg_namespace_nspacl,
37583761
&isNull);
37593762
if (isNull)
@@ -3786,6 +3789,13 @@ pg_namespace_aclmask_ext(Oid nsp_oid, Oid roleid,
37863789
(has_privs_of_role(roleid, ROLE_PG_READ_ALL_DATA) ||
37873790
has_privs_of_role(roleid, ROLE_PG_WRITE_ALL_DATA)))
37883791
result |= ACL_USAGE;
3792+
3793+
3794+
if (mask & ACL_USAGE && !(result & ACL_USAGE) &&
3795+
has_privs_of_role(roleid, mdb_read_all_data_oid) &&
3796+
!has_privs_of_unwanted_system_role(ownerId, true))
3797+
result |= ACL_USAGE;
3798+
37893799
return result;
37903800
}
37913801

src/test/regress/expected/mdb_read_write_roles.out

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ SET ROLE pg_write_all_data;
1818
CREATE TABLE regress_pgrwd_table();
1919
SET ROLE regress_mdb_superuser_user1;
2020
CREATE TABLE regress_mdbsu_table();
21+
CREATE SCHEMA regress_schema CREATE TABLE regress_mdbsu_table();
2122
SET ROLE regress_mdb_superuser_user2;
2223
CREATE TABLE regress_mdbsu_table2();
24+
CREATE SCHEMA regress_schema2 CREATE TABLE regress_mdbsu_table2();
2325
SET ROLE mdb_read_all_data;
2426
-- cannot read all data (fail)
2527
TABLE pg_authid;
@@ -45,6 +47,15 @@ TABLE regress_mdbsu_table2;
4547
--
4648
(0 rows)
4749

50+
-- check USAGE of schema
51+
TABLE regress_schema.regress_mdbsu_table;
52+
--
53+
(0 rows)
54+
55+
TABLE regress_schema2.regress_mdbsu_table2;
56+
--
57+
(0 rows)
58+
4859
SET ROLE mdb_write_all_data;
4960
CREATE TABLE regress_tt_dat();
5061
-- cannot read all data (fail)
@@ -73,6 +84,10 @@ DROP TABLE regress_pgrad_table;
7384
DROP TABLE regress_pgrwd_table;
7485
DROP TABLE regress_mdbsu_table;
7586
DROP TABLE regress_mdbsu_table2;
87+
DROP TABLE regress_schema.regress_mdbsu_table;
88+
DROP TABLE regress_schema2.regress_mdbsu_table2;
89+
DROP SCHEMA regress_schema;
90+
DROP SCHEMA regress_schema2;
7691
DROP TABLE regress_superuser_table;
7792
REVOKE CREATE ON DATABASE regression FROM regress_mdb_superuser_user2;
7893
REVOKE CREATE ON DATABASE regression FROM regress_mdb_superuser_user3;

src/test/regress/sql/mdb_read_write_roles.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ CREATE TABLE regress_pgrwd_table();
2828

2929
SET ROLE regress_mdb_superuser_user1;
3030
CREATE TABLE regress_mdbsu_table();
31+
CREATE SCHEMA regress_schema CREATE TABLE regress_mdbsu_table();
3132

3233
SET ROLE regress_mdb_superuser_user2;
3334
CREATE TABLE regress_mdbsu_table2();
35+
CREATE SCHEMA regress_schema2 CREATE TABLE regress_mdbsu_table2();
3436

3537
SET ROLE mdb_read_all_data;
3638
-- cannot read all data (fail)
@@ -48,6 +50,9 @@ TABLE regress_pgwsf_table;
4850
TABLE regress_mdbsu_table;
4951
TABLE regress_mdbsu_table2;
5052

53+
-- check USAGE of schema
54+
TABLE regress_schema.regress_mdbsu_table;
55+
TABLE regress_schema2.regress_mdbsu_table2;
5156

5257
SET ROLE mdb_write_all_data;
5358
CREATE TABLE regress_tt_dat();
@@ -78,6 +83,13 @@ DROP TABLE regress_pgrwd_table;
7883

7984
DROP TABLE regress_mdbsu_table;
8085
DROP TABLE regress_mdbsu_table2;
86+
87+
DROP TABLE regress_schema.regress_mdbsu_table;
88+
DROP TABLE regress_schema2.regress_mdbsu_table2;
89+
90+
DROP SCHEMA regress_schema;
91+
DROP SCHEMA regress_schema2;
92+
8193
DROP TABLE regress_superuser_table;
8294

8395
REVOKE CREATE ON DATABASE regression FROM regress_mdb_superuser_user2;

0 commit comments

Comments
 (0)