Debian Codegraph @

contrib/sepgsql/expected/dml.out

raw
1 --
2 -- Regression Test for DML Permissions
3 --
4 --
5 -- Setup
6 --
7 CREATE TABLE t1 (a int, junk int, b text);
8 SECURITY LABEL ON TABLE t1 IS 'system_u:object_r:sepgsql_table_t:s0';
9 ALTER TABLE t1 DROP COLUMN junk;
10 INSERT INTO t1 VALUES (1, 'aaa'), (2, 'bbb'), (3, 'ccc');
11 CREATE TABLE t2 (x int, y text);
12 SECURITY LABEL ON TABLE t2 IS 'system_u:object_r:sepgsql_ro_table_t:s0';
13 INSERT INTO t2 VALUES (1, 'xxx'), (2, 'yyy'), (3, 'zzz');
14 CREATE TABLE t3 (s int, t text);
15 SECURITY LABEL ON TABLE t3 IS 'system_u:object_r:sepgsql_fixed_table_t:s0';
16 INSERT INTO t3 VALUES (1, 'sss'), (2, 'ttt'), (3, 'uuu');
17 CREATE TABLE t4 (m int, junk int, n text);
18 SECURITY LABEL ON TABLE t4 IS 'system_u:object_r:sepgsql_secret_table_t:s0';
19 ALTER TABLE t4 DROP COLUMN junk;
20 INSERT INTO t4 VALUES (1, 'mmm'), (2, 'nnn'), (3, 'ooo');
21 CREATE TABLE t5 (e text, f text, g text);
22 SECURITY LABEL ON TABLE t5 IS 'system_u:object_r:sepgsql_table_t:s0';
23 SECURITY LABEL ON COLUMN t5.e IS 'system_u:object_r:sepgsql_table_t:s0';
24 SECURITY LABEL ON COLUMN t5.f IS 'system_u:object_r:sepgsql_ro_table_t:s0';
25 SECURITY LABEL ON COLUMN t5.g IS 'system_u:object_r:sepgsql_secret_table_t:s0';
26 ---
27 -- partitioned table parent
28 CREATE TABLE t1p (o int, p text, q text) PARTITION BY RANGE (o);
29 SECURITY LABEL ON TABLE t1p IS 'system_u:object_r:sepgsql_table_t:s0';
30 SECURITY LABEL ON COLUMN t1p.o IS 'system_u:object_r:sepgsql_table_t:s0';
31 SECURITY LABEL ON COLUMN t1p.p IS 'system_u:object_r:sepgsql_ro_table_t:s0';
32 SECURITY LABEL ON COLUMN t1p.q IS 'system_u:object_r:sepgsql_secret_table_t:s0';
33 -- partitioned table children
34 CREATE TABLE t1p_ones PARTITION OF t1p FOR VALUES FROM ('0') TO ('10');
35 SECURITY LABEL ON COLUMN t1p_ones.o IS 'system_u:object_r:sepgsql_table_t:s0';
36 SECURITY LABEL ON COLUMN t1p_ones.p IS 'system_u:object_r:sepgsql_ro_table_t:s0';
37 SECURITY LABEL ON COLUMN t1p_ones.q IS 'system_u:object_r:sepgsql_secret_table_t:s0';
38 CREATE TABLE t1p_tens PARTITION OF t1p FOR VALUES FROM ('10') TO ('100');
39 SECURITY LABEL ON COLUMN t1p_tens.o IS 'system_u:object_r:sepgsql_table_t:s0';
40 SECURITY LABEL ON COLUMN t1p_tens.p IS 'system_u:object_r:sepgsql_ro_table_t:s0';
41 SECURITY LABEL ON COLUMN t1p_tens.q IS 'system_u:object_r:sepgsql_secret_table_t:s0';
42 ---
43 CREATE TABLE customer (cid int primary key, cname text, ccredit text);
44 SECURITY LABEL ON COLUMN customer.ccredit IS 'system_u:object_r:sepgsql_secret_table_t:s0';
45 INSERT INTO customer VALUES (1, 'Taro', '1111-2222-3333-4444'),
46 (2, 'Hanako', '5555-6666-7777-8888');
47 CREATE FUNCTION customer_credit(int) RETURNS text
48 AS 'SELECT regexp_replace(ccredit, ''-[0-9]+$'', ''-????'') FROM customer WHERE cid = $1'
49 LANGUAGE sql;
50 SECURITY LABEL ON FUNCTION customer_credit(int)
51 IS 'system_u:object_r:sepgsql_trusted_proc_exec_t:s0';
52 SELECT objtype, objname, label FROM pg_seclabels
53 WHERE provider = 'selinux'
54 AND objtype in ('table', 'column')
55 AND objname in ('t1', 't2', 't3', 't4',
56 't5', 't5.e', 't5.f', 't5.g',
57 't1p', 't1p.o', 't1p.p', 't1p.q',
58 't1p_ones', 't1p_ones.o', 't1p_ones.p', 't1p_ones.q',
59 't1p_tens', 't1p_tens.o', 't1p_tens.p', 't1p_tens.q')
60 ORDER BY objname COLLATE "C";
61 objtype | objname | label
62 ---------+------------+---------------------------------------------
63 table | t1 | system_u:object_r:sepgsql_table_t:s0
64 table | t1p | system_u:object_r:sepgsql_table_t:s0
65 column | t1p.o | system_u:object_r:sepgsql_table_t:s0
66 column | t1p.p | system_u:object_r:sepgsql_ro_table_t:s0
67 column | t1p.q | system_u:object_r:sepgsql_secret_table_t:s0
68 table | t1p_ones | unconfined_u:object_r:sepgsql_table_t:s0
69 column | t1p_ones.o | system_u:object_r:sepgsql_table_t:s0
70 column | t1p_ones.p | system_u:object_r:sepgsql_ro_table_t:s0
71 column | t1p_ones.q | system_u:object_r:sepgsql_secret_table_t:s0
72 table | t1p_tens | unconfined_u:object_r:sepgsql_table_t:s0
73 column | t1p_tens.o | system_u:object_r:sepgsql_table_t:s0
74 column | t1p_tens.p | system_u:object_r:sepgsql_ro_table_t:s0
75 column | t1p_tens.q | system_u:object_r:sepgsql_secret_table_t:s0
76 table | t2 | system_u:object_r:sepgsql_ro_table_t:s0
77 table | t3 | system_u:object_r:sepgsql_fixed_table_t:s0
78 table | t4 | system_u:object_r:sepgsql_secret_table_t:s0
79 table | t5 | system_u:object_r:sepgsql_table_t:s0
80 column | t5.e | system_u:object_r:sepgsql_table_t:s0
81 column | t5.f | system_u:object_r:sepgsql_ro_table_t:s0
82 column | t5.g | system_u:object_r:sepgsql_secret_table_t:s0
83 (20 rows)
84
85 CREATE SCHEMA my_schema_1;
86 CREATE TABLE my_schema_1.ts1 (a int, b text);
87 CREATE TABLE my_schema_1.pts1 (o int, p text) PARTITION BY RANGE (o);
88 CREATE TABLE my_schema_1.pts1_ones PARTITION OF my_schema_1.pts1 FOR VALUES FROM ('0') to ('10');
89 CREATE SCHEMA my_schema_2;
90 CREATE TABLE my_schema_2.ts2 (x int, y text);
91 CREATE TABLE my_schema_2.pts2 (o int, p text) PARTITION BY RANGE (o);
92 CREATE TABLE my_schema_2.pts2_tens PARTITION OF my_schema_2.pts2 FOR VALUES FROM ('10') to ('100');
93 SECURITY LABEL ON SCHEMA my_schema_2
94 IS 'system_u:object_r:sepgsql_regtest_invisible_schema_t:s0';
95 -- Hardwired Rules
96 UPDATE pg_attribute SET attisdropped = true
97 WHERE attrelid = 't5'::regclass AND attname = 'f'; -- failed
98 ERROR: SELinux: hardwired security policy violation
99 --
100 -- Simple DML statements
101 --
102 SELECT sepgsql_getcon(); -- confirm client privilege
103 sepgsql_getcon
104 -----------------------------------------------------
105 unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0
106 (1 row)
107
108 SELECT * FROM t1; -- ok
109 a | b
110 ---+-----
111 1 | aaa
112 2 | bbb
113 3 | ccc
114 (3 rows)
115
116 SELECT * FROM t2; -- ok
117 x | y
118 ---+-----
119 1 | xxx
120 2 | yyy
121 3 | zzz
122 (3 rows)
123
124 SELECT * FROM t3; -- ok
125 s | t
126 ---+-----
127 1 | sss
128 2 | ttt
129 3 | uuu
130 (3 rows)
131
132 SELECT * FROM t4; -- failed
133 ERROR: SELinux: security policy violation
134 SELECT * FROM t5; -- failed
135 ERROR: SELinux: security policy violation
136 SELECT e,f FROM t5; -- ok
137 e | f
138 ---+---
139 (0 rows)
140
141 SELECT (t1.*)::record FROM t1; -- ok
142 t1
143 ---------
144 (1,aaa)
145 (2,bbb)
146 (3,ccc)
147 (3 rows)
148
149 SELECT (t4.*)::record FROM t4; -- failed
150 ERROR: SELinux: security policy violation
151 ---
152 -- partitioned table parent
153 SELECT * FROM t1p; -- failed
154 ERROR: SELinux: security policy violation
155 SELECT o,p FROM t1p; -- ok
156 o | p
157 ---+---
158 (0 rows)
159
160 --partitioned table children
161 SELECT * FROM t1p_ones; -- failed
162 ERROR: SELinux: security policy violation
163 SELECT o FROM t1p_ones; -- ok
164 o
165 ---
166 (0 rows)
167
168 SELECT o,p FROM t1p_ones; -- ok
169 o | p
170 ---+---
171 (0 rows)
172
173 SELECT * FROM t1p_tens; -- failed
174 ERROR: SELinux: security policy violation
175 SELECT o FROM t1p_tens; -- ok
176 o
177 ---
178 (0 rows)
179
180 SELECT o,p FROM t1p_tens; -- ok
181 o | p
182 ---+---
183 (0 rows)
184
185 ---
186 SELECT * FROM customer; -- failed
187 ERROR: SELinux: security policy violation
188 SELECT cid, cname, customer_credit(cid) FROM customer; -- ok
189 cid | cname | customer_credit
190 -----+--------+---------------------
191 1 | Taro | 1111-2222-3333-????
192 2 | Hanako | 5555-6666-7777-????
193 (2 rows)
194
195 SELECT count(*) FROM t5; -- ok
196 count
197 -------
198 0
199 (1 row)
200
201 SELECT count(*) FROM t5 WHERE g IS NULL; -- failed
202 ERROR: SELinux: security policy violation
203 ---
204 -- partitioned table parent
205 SELECT count(*) FROM t1p; -- ok
206 count
207 -------
208 0
209 (1 row)
210
211 SELECT count(*) FROM t1p WHERE q IS NULL; -- failed
212 ERROR: SELinux: security policy violation
213 -- partitioned table children
214 SELECT count(*) FROM t1p_ones; -- ok
215 count
216 -------
217 0
218 (1 row)
219
220 SELECT count(*) FROM t1p_ones WHERE q IS NULL; -- failed
221 ERROR: SELinux: security policy violation
222 SELECT count(*) FROM t1p_tens; -- ok
223 count
224 -------
225 0
226 (1 row)
227
228 SELECT count(*) FROM t1p_tens WHERE q IS NULL; -- failed
229 ERROR: SELinux: security policy violation
230 ---
231 INSERT INTO t1 VALUES (4, 'abc'); -- ok
232 INSERT INTO t2 VALUES (4, 'xyz'); -- failed
233 ERROR: SELinux: security policy violation
234 INSERT INTO t3 VALUES (4, 'stu'); -- ok
235 INSERT INTO t4 VALUES (4, 'mno'); -- failed
236 ERROR: SELinux: security policy violation
237 INSERT INTO t5 VALUES (1,2,3); -- failed
238 ERROR: SELinux: security policy violation
239 INSERT INTO t5 (e,f) VALUES ('abc', 'def'); -- failed
240 ERROR: SELinux: security policy violation
241 INSERT INTO t5 (e) VALUES ('abc'); -- ok
242 ---
243 -- partitioned table parent
244 INSERT INTO t1p (o,p) VALUES (9, 'mno'); -- failed
245 ERROR: SELinux: security policy violation
246 INSERT INTO t1p (o) VALUES (9); -- ok
247 INSERT INTO t1p (o,p) VALUES (99, 'pqr'); -- failed
248 ERROR: SELinux: security policy violation
249 INSERT INTO t1p (o) VALUES (99); -- ok
250 -- partitioned table children
251 INSERT INTO t1p_ones (o,p) VALUES (9, 'mno'); -- failed
252 ERROR: SELinux: security policy violation
253 INSERT INTO t1p_ones (o) VALUES (9); -- ok
254 INSERT INTO t1p_tens (o,p) VALUES (99, 'pqr'); -- failed
255 ERROR: SELinux: security policy violation
256 INSERT INTO t1p_tens (o) VALUES (99); -- ok
257 ---
258 UPDATE t1 SET b = b || '_upd'; -- ok
259 UPDATE t2 SET y = y || '_upd'; -- failed
260 ERROR: SELinux: security policy violation
261 UPDATE t3 SET t = t || '_upd'; -- failed
262 ERROR: SELinux: security policy violation
263 UPDATE t4 SET n = n || '_upd'; -- failed
264 ERROR: SELinux: security policy violation
265 UPDATE t5 SET e = 'xyz'; -- ok
266 UPDATE t5 SET e = f || '_upd'; -- ok
267 UPDATE t5 SET e = g || '_upd'; -- failed
268 ERROR: SELinux: security policy violation
269 ---
270 -- partitioned table parent
271 UPDATE t1p SET o = 9 WHERE o < 10; -- ok
272 UPDATE t1p SET o = 99 WHERE o >= 10; -- ok
273 UPDATE t1p SET o = ascii(COALESCE(p,'upd'))%10 WHERE o < 10; -- ok
274 UPDATE t1p SET o = ascii(COALESCE(q,'upd'))%100 WHERE o >= 10; -- failed
275 ERROR: SELinux: security policy violation
276 -- partitioned table children
277 UPDATE t1p_ones SET o = 9; -- ok
278 UPDATE t1p_ones SET o = ascii(COALESCE(p,'upd'))%10; -- ok
279 UPDATE t1p_ones SET o = ascii(COALESCE(q,'upd'))%10; -- failed
280 ERROR: SELinux: security policy violation
281 UPDATE t1p_tens SET o = 99; -- ok
282 UPDATE t1p_tens SET o = ascii(COALESCE(p,'upd'))%100; -- ok
283 UPDATE t1p_tens SET o = ascii(COALESCE(q,'upd'))%100; -- failed
284 ERROR: SELinux: security policy violation
285 ---
286 DELETE FROM t1; -- ok
287 DELETE FROM t2; -- failed
288 ERROR: SELinux: security policy violation
289 DELETE FROM t3; -- failed
290 ERROR: SELinux: security policy violation
291 DELETE FROM t4; -- failed
292 ERROR: SELinux: security policy violation
293 DELETE FROM t5; -- ok
294 DELETE FROM t5 WHERE f IS NULL; -- ok
295 DELETE FROM t5 WHERE g IS NULL; -- failed
296 ERROR: SELinux: security policy violation
297 ---
298 -- partitioned table parent
299 DELETE FROM t1p; -- ok
300 DELETE FROM t1p WHERE p IS NULL; -- ok
301 DELETE FROM t1p WHERE q IS NULL; -- failed
302 ERROR: SELinux: security policy violation
303 -- partitioned table children
304 DELETE FROM t1p_ones WHERE p IS NULL; -- ok
305 DELETE FROM t1p_ones WHERE q IS NULL; -- failed;
306 ERROR: SELinux: security policy violation
307 DELETE FROM t1p_tens WHERE p IS NULL; -- ok
308 DELETE FROM t1p_tens WHERE q IS NULL; -- failed
309 ERROR: SELinux: security policy violation
310 ---
311 --
312 -- COPY TO/FROM statements
313 --
314 COPY t1 TO '/dev/null'; -- ok
315 COPY t2 TO '/dev/null'; -- ok
316 COPY t3 TO '/dev/null'; -- ok
317 COPY t4 TO '/dev/null'; -- failed
318 ERROR: SELinux: security policy violation
319 COPY t5 TO '/dev/null'; -- failed
320 ERROR: SELinux: security policy violation
321 COPY t5(e,f) TO '/dev/null'; -- ok
322 ---
323 -- partitioned table parent
324 COPY (SELECT * FROM t1p) TO '/dev/null'; -- failed
325 ERROR: SELinux: security policy violation
326 COPY (SELECT (o,p) FROM t1p) TO '/dev/null'; -- ok
327 -- partitioned table children
328 COPY t1p_ones TO '/dev/null'; -- failed
329 ERROR: SELinux: security policy violation
330 COPY t1p_ones(o,p) TO '/dev/null'; -- ok
331 COPY t1p_tens TO '/dev/null'; -- failed
332 ERROR: SELinux: security policy violation
333 COPY t1p_tens(o,p) TO '/dev/null'; -- ok
334 ---
335 COPY t1 FROM '/dev/null'; -- ok
336 COPY t2 FROM '/dev/null'; -- failed
337 ERROR: SELinux: security policy violation
338 COPY t3 FROM '/dev/null'; -- ok
339 COPY t4 FROM '/dev/null'; -- failed
340 ERROR: SELinux: security policy violation
341 COPY t5 FROM '/dev/null'; -- failed
342 ERROR: SELinux: security policy violation
343 COPY t5 (e,f) FROM '/dev/null'; -- failed
344 ERROR: SELinux: security policy violation
345 COPY t5 (e) FROM '/dev/null'; -- ok
346 ---
347 -- partitioned table parent
348 COPY t1p FROM '/dev/null'; -- failed
349 ERROR: SELinux: security policy violation
350 COPY t1p (o) FROM '/dev/null'; -- ok
351 -- partitioned table children
352 COPY t1p_ones FROM '/dev/null'; -- failed
353 ERROR: SELinux: security policy violation
354 COPY t1p_ones (o) FROM '/dev/null'; -- ok
355 COPY t1p_tens FROM '/dev/null'; -- failed
356 ERROR: SELinux: security policy violation
357 COPY t1p_tens (o) FROM '/dev/null'; -- ok
358 ---
359 --
360 -- Schema search path
361 --
362 SET search_path = my_schema_1, my_schema_2, public;
363 SELECT * FROM ts1; -- ok
364 a | b
365 ---+---
366 (0 rows)
367
368 SELECT * FROM ts2; -- failed (relation not found)
369 ERROR: relation "ts2" does not exist
370 LINE 1: SELECT * FROM ts2;
371 ^
372 SELECT * FROM my_schema_2.ts2; -- failed (policy violation)
373 ERROR: SELinux: security policy violation
374 LINE 1: SELECT * FROM my_schema_2.ts2;
375 ^
376 --
377 -- Clean up
378 --
379 SELECT sepgsql_getcon(); -- confirm client privilege
380 sepgsql_getcon
381 ---------------------------------------------------------------------
382 unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0-s0:c0.c255
383 (1 row)
384
385 DROP TABLE IF EXISTS t1 CASCADE;
386 DROP TABLE IF EXISTS t2 CASCADE;
387 DROP TABLE IF EXISTS t3 CASCADE;
388 DROP TABLE IF EXISTS t4 CASCADE;
389 DROP TABLE IF EXISTS t5 CASCADE;
390 DROP TABLE IF EXISTS t1p CASCADE;
391 DROP TABLE IF EXISTS customer CASCADE;
392 DROP SCHEMA IF EXISTS my_schema_1 CASCADE;
393 NOTICE: drop cascades to 2 other objects
394 DETAIL: drop cascades to table my_schema_1.ts1
395 drop cascades to table my_schema_1.pts1
396 DROP SCHEMA IF EXISTS my_schema_2 CASCADE;
397 NOTICE: drop cascades to 2 other objects
398 DETAIL: drop cascades to table my_schema_2.ts2
399 drop cascades to table my_schema_2.pts2