|
| 1 | +-- Tests permission checks for the mdb_admin role with |
| 2 | +-- resource groups enabled. |
| 3 | + |
| 4 | +-- start_matchsubs |
| 5 | +-- m/ERROR: cannot find process: \d+/ |
| 6 | +-- s/\d+/XXX/g |
| 7 | +-- end_matchsubs |
| 8 | + |
| 9 | +DROP ROLE IF EXISTS role_rg_admin; |
| 10 | +DROP |
| 11 | +DROP ROLE IF EXISTS role_rg_noadmin; |
| 12 | +DROP |
| 13 | +DROP ROLE IF EXISTS mdb_admin; |
| 14 | +DROP |
| 15 | +-- start_ignore |
| 16 | +DROP RESOURCE GROUP rg_perm_admin1; |
| 17 | +DROP RESOURCE GROUP rg_perm_admin2; |
| 18 | +DROP RESOURCE GROUP rg_perm_revoke1; |
| 19 | +DROP RESOURCE GROUP rg_perm_revoke2; |
| 20 | +DROP RESOURCE GROUP rg_perm_test; |
| 21 | +-- end_ignore |
| 22 | + |
| 23 | +-- --------------------------------------------------------------------- |
| 24 | +-- Setup. The mdb_admin role is not predefined in the catalog; it is |
| 25 | +-- created here the same way the control plane provisions it at runtime. |
| 26 | +-- --------------------------------------------------------------------- |
| 27 | +CREATE RESOURCE GROUP rg_perm_test WITH (concurrency=2, cpu_max_percent=10); |
| 28 | +CREATE |
| 29 | +CREATE ROLE mdb_admin; |
| 30 | +CREATE |
| 31 | +CREATE ROLE role_rg_admin RESOURCE GROUP rg_perm_test; |
| 32 | +CREATE |
| 33 | +CREATE ROLE role_rg_noadmin RESOURCE GROUP rg_perm_test; |
| 34 | +CREATE |
| 35 | +GRANT mdb_admin TO role_rg_admin; |
| 36 | +GRANT |
| 37 | + |
| 38 | +-- --------------------------------------------------------------------- |
| 39 | +-- 1. Member of mdb_admin can CREATE/ALTER/DROP resource groups |
| 40 | +-- (statements are dispatched to segments). |
| 41 | +-- --------------------------------------------------------------------- |
| 42 | +1: SET ROLE role_rg_admin; |
| 43 | +SET |
| 44 | +1: CREATE RESOURCE GROUP rg_perm_admin1 WITH (concurrency=1, cpu_max_percent=5); |
| 45 | +CREATE |
| 46 | +1: ALTER RESOURCE GROUP rg_perm_admin1 SET cpu_max_percent 6; |
| 47 | +ALTER |
| 48 | +1: DROP RESOURCE GROUP rg_perm_admin1; |
| 49 | +DROP |
| 50 | + |
| 51 | +-- 2. Even a member cannot ALTER or DROP the system admin_group. |
| 52 | +1: ALTER RESOURCE GROUP admin_group SET cpu_max_percent 99; |
| 53 | +ERROR: must be superuser to alter resource group "admin_group" |
| 54 | +1: DROP RESOURCE GROUP admin_group; |
| 55 | +ERROR: must be superuser to drop resource group "admin_group" |
| 56 | +1q: ... <quitting> |
| 57 | + |
| 58 | +-- --------------------------------------------------------------------- |
| 59 | +-- 3. A non-member is rejected on every entry point. |
| 60 | +-- --------------------------------------------------------------------- |
| 61 | +2: SET ROLE role_rg_noadmin; |
| 62 | +SET |
| 63 | +2: CREATE RESOURCE GROUP rg_perm_admin2 WITH (concurrency=1, cpu_max_percent=5); |
| 64 | +ERROR: must be mdb_admin to create resource groups |
| 65 | +2: ALTER RESOURCE GROUP rg_perm_test SET cpu_max_percent 7; |
| 66 | +ERROR: must be mdb_admin to alter resource groups |
| 67 | +2: DROP RESOURCE GROUP rg_perm_test; |
| 68 | +ERROR: must be mdb_admin to drop resource groups |
| 69 | +2q: ... <quitting> |
| 70 | + |
| 71 | +-- --------------------------------------------------------------------- |
| 72 | +-- 4. pg_resgroup_move_query() honours the same permission check. |
| 73 | +-- The first call (non-member) must fail with "must be mdb_admin". |
| 74 | +-- The second call (member) gets past the permission gate and |
| 75 | +-- fails on the pid lookup (masked by start_matchsubs above). |
| 76 | +-- --------------------------------------------------------------------- |
| 77 | +3: SET ROLE role_rg_noadmin; |
| 78 | +SET |
| 79 | +3: SELECT pg_resgroup_move_query(999999999, 'admin_group'); |
| 80 | +ERROR: must be mdb_admin to move query |
| 81 | +3: RESET ROLE; |
| 82 | +RESET |
| 83 | +3: SET ROLE role_rg_admin; |
| 84 | +SET |
| 85 | +3: SELECT pg_resgroup_move_query(999999999, 'admin_group'); |
| 86 | +ERROR: cannot find process: XXX |
| 87 | +3q: ... <quitting> |
| 88 | + |
| 89 | +-- --------------------------------------------------------------------- |
| 90 | +-- 5. Cross-session REVOKE takes effect on the granted session's |
| 91 | +-- next statement (the privilege is re-checked per command, not |
| 92 | +-- cached at SET ROLE time). |
| 93 | +-- --------------------------------------------------------------------- |
| 94 | +4: SET ROLE role_rg_admin; |
| 95 | +SET |
| 96 | +4: CREATE RESOURCE GROUP rg_perm_revoke1 WITH (concurrency=1, cpu_max_percent=5); |
| 97 | +CREATE |
| 98 | +5: REVOKE mdb_admin FROM role_rg_admin; |
| 99 | +REVOKE |
| 100 | +4: CREATE RESOURCE GROUP rg_perm_revoke2 WITH (concurrency=1, cpu_max_percent=5); |
| 101 | +ERROR: must be mdb_admin to create resource groups |
| 102 | +4: DROP RESOURCE GROUP rg_perm_revoke1; |
| 103 | +ERROR: must be mdb_admin to drop resource groups |
| 104 | +4q: ... <quitting> |
| 105 | +5q: ... <quitting> |
| 106 | + |
| 107 | +-- --------------------------------------------------------------------- |
| 108 | +-- Cleanup. Roles must be dropped before the resource group they |
| 109 | +-- reference, otherwise DROP RESOURCE GROUP fails with |
| 110 | +-- "resource group is used by at least one role". |
| 111 | +-- --------------------------------------------------------------------- |
| 112 | +RESET ROLE; |
| 113 | +RESET |
| 114 | +DROP ROLE role_rg_admin; |
| 115 | +DROP |
| 116 | +DROP ROLE role_rg_noadmin; |
| 117 | +DROP |
| 118 | +DROP ROLE mdb_admin; |
| 119 | +DROP |
| 120 | +DROP RESOURCE GROUP rg_perm_revoke1; |
| 121 | +DROP |
| 122 | +DROP RESOURCE GROUP rg_perm_test; |
| 123 | +DROP |
0 commit comments