Skip to content

Commit 35feca1

Browse files
committed
MDB-32132: fix grantor selection for mdb_superuser (#4)
1 parent b81a317 commit 35feca1

3 files changed

Lines changed: 47 additions & 2 deletions

File tree

src/backend/utils/adt/acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5349,7 +5349,7 @@ select_best_grantor(Oid roleId, AclMode privileges,
53495349

53505350
if (is_member_of_role(GetUserId(), mdb_superuser_roleoid)
53515351
&& has_privs_of_role(GetUserId(), ownerId)) {
5352-
*grantorId = mdb_superuser_roleoid;
5352+
*grantorId = ownerId;
53535353
AclMode mdb_superuser_allowed_privs = needed_goptions;
53545354
*grantOptions = mdb_superuser_allowed_privs;
53555355
return;

src/test/regress/expected/mdb_superuser.out

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
CREATE ROLE regress_mdb_superuser_user1;
22
CREATE ROLE regress_mdb_superuser_user2;
33
CREATE ROLE regress_mdb_superuser_user3;
4+
CREATE ROLE regress_mdb_su_role_o1;
5+
CREATE ROLE regress_mdb_su_role_o2;
6+
GRANT mdb_superuser TO regress_mdb_su_role_o1;
47
GRANT mdb_admin TO mdb_superuser;
58
CREATE ROLE regress_superuser WITH SUPERUSER;
69
GRANT mdb_superuser TO regress_mdb_superuser_user1;
710
GRANT CREATE ON DATABASE regression TO regress_mdb_superuser_user2;
811
GRANT CREATE ON DATABASE regression TO regress_mdb_superuser_user3;
12+
GRANT CREATE ON DATABASE regression TO regress_mdb_su_role_o2;
913
SET ROLE regress_mdb_superuser_user2;
1014
CREATE FUNCTION regress_mdb_superuser_add(integer, integer) RETURNS integer
1115
AS 'SELECT $1 + $2;'
@@ -85,13 +89,30 @@ ERROR: permission denied for schema regtest
8589
SET ROLE regress_mdb_superuser_user1;
8690
GRANT ALL ON TABLE regtest.regtest TO regress_mdb_superuser_user1;
8791
ALTER TABLE regtest.regtest OWNER TO regress_mdb_superuser_user1;
92+
-- Check grantor
93+
SET ROLE regress_mdb_su_role_o2;
94+
CREATE TABLE public.role_o2_t();
95+
SET ROLE mdb_superuser;
96+
GRANT SELECT ON public.role_o2_t TO regress_mdb_su_role_o1;
97+
SELECT
98+
grantor
99+
from information_schema.role_table_grants
100+
where grantee='regress_mdb_su_role_o1' AND table_name = 'role_o2_t';
101+
grantor
102+
------------------------
103+
regress_mdb_su_role_o2
104+
(1 row)
105+
88106
\c regression
89107
DROP DATABASE regress_check_owner;
90108
-- end tests
91109
RESET SESSION AUTHORIZATION;
92110
--
93111
REVOKE CREATE ON DATABASE regression FROM regress_mdb_superuser_user2;
94112
REVOKE CREATE ON DATABASE regression FROM regress_mdb_superuser_user3;
113+
REVOKE CREATE ON DATABASE regression FROM regress_mdb_su_role_o2;
114+
DROP ROLE regress_mdb_su_role_o1;
115+
DROP ROLE regress_mdb_su_role_o2;
95116
DROP VIEW regress_mdb_superuser_view;
96117
DROP FUNCTION regress_mdb_superuser_add;
97118
DROP TABLE regress_mdb_superuser_schema.regress_mdb_superuser_table;

src/test/regress/sql/mdb_superuser.sql

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ CREATE ROLE regress_mdb_superuser_user1;
22
CREATE ROLE regress_mdb_superuser_user2;
33
CREATE ROLE regress_mdb_superuser_user3;
44

5+
CREATE ROLE regress_mdb_su_role_o1;
6+
CREATE ROLE regress_mdb_su_role_o2;
7+
8+
GRANT mdb_superuser TO regress_mdb_su_role_o1;
9+
510
GRANT mdb_admin TO mdb_superuser;
611

712
CREATE ROLE regress_superuser WITH SUPERUSER;
@@ -10,7 +15,7 @@ GRANT mdb_superuser TO regress_mdb_superuser_user1;
1015

1116
GRANT CREATE ON DATABASE regression TO regress_mdb_superuser_user2;
1217
GRANT CREATE ON DATABASE regression TO regress_mdb_superuser_user3;
13-
18+
GRANT CREATE ON DATABASE regression TO regress_mdb_su_role_o2;
1419

1520
SET ROLE regress_mdb_superuser_user2;
1621

@@ -118,6 +123,21 @@ SET ROLE regress_mdb_superuser_user1;
118123
GRANT ALL ON TABLE regtest.regtest TO regress_mdb_superuser_user1;
119124
ALTER TABLE regtest.regtest OWNER TO regress_mdb_superuser_user1;
120125

126+
-- Check grantor
127+
128+
SET ROLE regress_mdb_su_role_o2;
129+
130+
CREATE TABLE public.role_o2_t();
131+
132+
SET ROLE mdb_superuser;
133+
134+
GRANT SELECT ON public.role_o2_t TO regress_mdb_su_role_o1;
135+
136+
SELECT
137+
grantor
138+
from information_schema.role_table_grants
139+
where grantee='regress_mdb_su_role_o1' AND table_name = 'role_o2_t';
140+
121141
\c regression
122142
DROP DATABASE regress_check_owner;
123143

@@ -127,6 +147,10 @@ RESET SESSION AUTHORIZATION;
127147
--
128148
REVOKE CREATE ON DATABASE regression FROM regress_mdb_superuser_user2;
129149
REVOKE CREATE ON DATABASE regression FROM regress_mdb_superuser_user3;
150+
REVOKE CREATE ON DATABASE regression FROM regress_mdb_su_role_o2;
151+
152+
DROP ROLE regress_mdb_su_role_o1;
153+
DROP ROLE regress_mdb_su_role_o2;
130154

131155
DROP VIEW regress_mdb_superuser_view;
132156
DROP FUNCTION regress_mdb_superuser_add;

0 commit comments

Comments
 (0)