|
2 | 2 | CREATE ROLE regress_role_super SUPERUSER;
|
3 | 3 | CREATE ROLE regress_role_admin CREATEDB CREATEROLE REPLICATION BYPASSRLS;
|
4 | 4 | GRANT CREATE ON DATABASE regression TO regress_role_admin WITH GRANT OPTION;
|
| 5 | +CREATE ROLE regress_role_limited_admin CREATEROLE; |
5 | 6 | CREATE ROLE regress_role_normal;
|
6 |
| --- fail, only superusers can create users with these privileges |
7 |
| -SET SESSION AUTHORIZATION regress_role_admin; |
| 7 | +-- fail, CREATEROLE user can't give away role attributes without having them |
| 8 | +SET SESSION AUTHORIZATION regress_role_limited_admin; |
8 | 9 | CREATE ROLE regress_nosuch_superuser SUPERUSER;
|
9 | 10 | ERROR: must be superuser to create superusers
|
10 | 11 | CREATE ROLE regress_nosuch_replication_bypassrls REPLICATION BYPASSRLS;
|
11 |
| -ERROR: must be superuser to create replication users |
| 12 | +ERROR: must have replication permission to create replication users |
12 | 13 | CREATE ROLE regress_nosuch_replication REPLICATION;
|
13 |
| -ERROR: must be superuser to create replication users |
| 14 | +ERROR: must have replication permission to create replication users |
14 | 15 | CREATE ROLE regress_nosuch_bypassrls BYPASSRLS;
|
15 |
| -ERROR: must be superuser to create bypassrls users |
16 |
| --- ok, having CREATEROLE is enough to create users with these privileges |
| 16 | +ERROR: must have bypassrls to create bypassrls users |
| 17 | +CREATE ROLE regress_nosuch_createdb CREATEDB; |
| 18 | +ERROR: must have createdb permission to create createdb users |
| 19 | +-- ok, can create a role without any special attributes |
| 20 | +CREATE ROLE regress_role_limited; |
| 21 | +-- fail, can't give it in any of the restricted attributes |
| 22 | +ALTER ROLE regress_role_limited SUPERUSER; |
| 23 | +ERROR: must be superuser to alter superuser roles or change superuser attribute |
| 24 | +ALTER ROLE regress_role_limited REPLICATION; |
| 25 | +ERROR: must have replication privilege to change replication attribute |
| 26 | +ALTER ROLE regress_role_limited CREATEDB; |
| 27 | +ERROR: must have createdb privilege to change createdb attribute |
| 28 | +ALTER ROLE regress_role_limited BYPASSRLS; |
| 29 | +ERROR: must have bypassrls privilege to change bypassrls attribute |
| 30 | +DROP ROLE regress_role_limited; |
| 31 | +-- ok, can give away these role attributes if you have them |
| 32 | +SET SESSION AUTHORIZATION regress_role_admin; |
| 33 | +CREATE ROLE regress_replication_bypassrls REPLICATION BYPASSRLS; |
| 34 | +CREATE ROLE regress_replication REPLICATION; |
| 35 | +CREATE ROLE regress_bypassrls BYPASSRLS; |
17 | 36 | CREATE ROLE regress_createdb CREATEDB;
|
| 37 | +-- ok, can toggle these role attributes off and on if you have them |
| 38 | +ALTER ROLE regress_replication NOREPLICATION; |
| 39 | +ALTER ROLE regress_replication REPLICATION; |
| 40 | +ALTER ROLE regress_bypassrls NOBYPASSRLS; |
| 41 | +ALTER ROLE regress_bypassrls BYPASSRLS; |
| 42 | +ALTER ROLE regress_createdb NOCREATEDB; |
| 43 | +ALTER ROLE regress_createdb CREATEDB; |
| 44 | +-- fail, can't toggle SUPERUSER |
| 45 | +ALTER ROLE regress_createdb SUPERUSER; |
| 46 | +ERROR: must be superuser to alter superuser roles or change superuser attribute |
| 47 | +ALTER ROLE regress_createdb NOSUPERUSER; |
| 48 | +ERROR: must be superuser to alter superuser roles or change superuser attribute |
| 49 | +-- ok, having CREATEROLE is enough to create users with these privileges |
18 | 50 | CREATE ROLE regress_createrole CREATEROLE NOINHERIT;
|
19 | 51 | GRANT CREATE ON DATABASE regression TO regress_createrole WITH GRANT OPTION;
|
20 | 52 | CREATE ROLE regress_login LOGIN;
|
@@ -53,9 +85,9 @@ ERROR: permission denied to create database
|
53 | 85 | CREATE ROLE regress_plainrole;
|
54 | 86 | -- ok, roles with CREATEROLE can create new roles with it
|
55 | 87 | CREATE ROLE regress_rolecreator CREATEROLE;
|
56 |
| --- ok, roles with CREATEROLE can create new roles with privilege they lack |
57 |
| -CREATE ROLE regress_hasprivs CREATEDB CREATEROLE LOGIN INHERIT |
58 |
| - CONNECTION LIMIT 5; |
| 88 | +-- ok, roles with CREATEROLE can create new roles with different role |
| 89 | +-- attributes, including CREATEROLE |
| 90 | +CREATE ROLE regress_hasprivs CREATEROLE LOGIN INHERIT CONNECTION LIMIT 5; |
59 | 91 | -- ok, we should be able to modify a role we created
|
60 | 92 | COMMENT ON ROLE regress_hasprivs IS 'some comment';
|
61 | 93 | ALTER ROLE regress_hasprivs RENAME TO regress_tenant;
|
@@ -164,6 +196,9 @@ DROP ROLE regress_plainrole;
|
164 | 196 | -- must revoke privileges before dropping role
|
165 | 197 | REVOKE CREATE ON DATABASE regression FROM regress_createrole CASCADE;
|
166 | 198 | -- ok, should be able to drop non-superuser roles we created
|
| 199 | +DROP ROLE regress_replication_bypassrls; |
| 200 | +DROP ROLE regress_replication; |
| 201 | +DROP ROLE regress_bypassrls; |
167 | 202 | DROP ROLE regress_createdb;
|
168 | 203 | DROP ROLE regress_createrole;
|
169 | 204 | DROP ROLE regress_login;
|
|
0 commit comments