@@ -5,18 +5,20 @@ CREATE ROLE user1 LOGIN;
5
5
CREATE ROLE user2 LOGIN;
6
6
GRANT USAGE, CREATE ON SCHEMA permissions TO user1;
7
7
GRANT USAGE, CREATE ON SCHEMA permissions TO user2;
8
- ALTER DEFAULT PRIVILEGES FOR ROLE user1
9
- IN SCHEMA permissions
10
- GRANT SELECT, INSERT ON TABLES
11
- TO user2;
12
8
/* Switch to #1 */
13
9
SET ROLE user1;
14
10
CREATE TABLE permissions.user1_table(id serial, a int);
15
11
INSERT INTO permissions.user1_table SELECT g, g FROM generate_series(1, 20) as g;
16
- /* Should fail */
12
+ /* Should fail (can't SELECT) */
13
+ SET ROLE user2;
14
+ SELECT create_range_partitions('permissions.user1_table', 'id', 1, 10, 2);
15
+ ERROR: permission denied for relation user1_table
16
+ /* Grant SELECT to user2 */
17
+ SET ROLE user1;
18
+ GRANT SELECT ON permissions.user1_table TO user2;
19
+ /* Should fail (don't own parent) */
17
20
SET ROLE user2;
18
21
SELECT create_range_partitions('permissions.user1_table', 'id', 1, 10, 2);
19
- NOTICE: sequence "user1_table_seq" does not exist, skipping
20
22
WARNING: only the owner or superuser can change partitioning configuration of table "user1_table"
21
23
ERROR: new row violates row-level security policy for table "pathman_config"
22
24
/* Should be ok */
@@ -58,21 +60,42 @@ WARNING: only the owner or superuser can change partitioning configuration of t
58
60
/* No rights to insert, should fail */
59
61
SET ROLE user2;
60
62
INSERT INTO permissions.user1_table (id, a) VALUES (35, 0);
61
- /* Have rights, should be ok (bgw connects as user1) */
63
+ ERROR: permission denied for relation user1_table
64
+ /* No rights to create partitions (need INSERT privilege) */
65
+ SET ROLE user2;
66
+ SELECT prepend_range_partition('permissions.user1_table');
67
+ ERROR: permission denied for parent relation "user1_table"
68
+ /* Allow user2 to create partitions */
62
69
SET ROLE user1;
63
70
GRANT INSERT ON permissions.user1_table TO user2;
71
+ /* Should be able to prepend a partition */
72
+ SET ROLE user2;
73
+ SELECT prepend_range_partition('permissions.user1_table');
74
+ prepend_range_partition
75
+ ---------------------------
76
+ permissions.user1_table_4
77
+ (1 row)
78
+
79
+ /* Have rights, should be ok (parent's ACL is shared by new children) */
64
80
SET ROLE user2;
65
81
INSERT INTO permissions.user1_table (id, a) VALUES (35, 0) RETURNING *;
66
82
id | a
67
83
----+---
68
84
35 | 0
69
85
(1 row)
70
86
71
- SELECT relacl FROM pg_class WHERE oid = 'permissions.user1_table_4'::regclass;
72
- relacl
73
- --------------------------------------
74
- {user1=arwdDxt/user1,user2=ar/user1}
75
- (1 row)
87
+ SELECT relname, relacl FROM pg_class
88
+ WHERE oid = ANY (SELECT partition FROM pathman_partition_list
89
+ WHERE parent = 'permissions.user1_table'::REGCLASS
90
+ ORDER BY range_max::int DESC
91
+ LIMIT 3)
92
+ ORDER BY relname; /* we also check ACL for "user1_table_2" */
93
+ relname | relacl
94
+ ---------------+--------------------------------------
95
+ user1_table_2 | {user1=arwdDxt/user1,user2=r/user1}
96
+ user1_table_5 | {user1=arwdDxt/user1,user2=ar/user1}
97
+ user1_table_6 | {user1=arwdDxt/user1,user2=ar/user1}
98
+ (3 rows)
76
99
77
100
/* Try to drop partition, should fail */
78
101
SELECT drop_range_partition('permissions.user1_table_4');
@@ -95,11 +118,12 @@ SELECT drop_partitions('permissions.user1_table');
95
118
NOTICE: function permissions.user1_table_upd_trig_func() does not exist, skipping
96
119
NOTICE: 10 rows copied from permissions.user1_table_1
97
120
NOTICE: 10 rows copied from permissions.user1_table_2
98
- NOTICE: 0 rows copied from permissions.user1_table_3
99
- NOTICE: 2 rows copied from permissions.user1_table_4
121
+ NOTICE: 0 rows copied from permissions.user1_table_4
122
+ NOTICE: 0 rows copied from permissions.user1_table_5
123
+ NOTICE: 1 rows copied from permissions.user1_table_6
100
124
drop_partitions
101
125
-----------------
102
- 4
126
+ 5
103
127
(1 row)
104
128
105
129
/* Switch to #2 */
0 commit comments