Debian Codegraph @

contrib/sepgsql/expected/label.out

raw
1 --
2 -- Regression Tests for Label Management
3 --
4 --
5 -- Setup
6 --
7 CREATE TABLE t1 (a int, b text);
8 INSERT INTO t1 VALUES (1, 'aaa'), (2, 'bbb'), (3, 'ccc');
9 CREATE TABLE t2 AS SELECT * FROM t1 WHERE a % 2 = 0;
10 CREATE FUNCTION f1 () RETURNS text
11 AS 'SELECT sepgsql_getcon()'
12 LANGUAGE sql;
13 CREATE FUNCTION f2 () RETURNS text
14 AS 'SELECT sepgsql_getcon()'
15 LANGUAGE sql;
16 SECURITY LABEL ON FUNCTION f2()
17 IS 'system_u:object_r:sepgsql_trusted_proc_exec_t:s0';
18 CREATE FUNCTION f3 () RETURNS text
19 AS 'BEGIN
20 RAISE EXCEPTION ''an exception from f3()'';
21 RETURN NULL;
22 END;' LANGUAGE plpgsql;
23 SECURITY LABEL ON FUNCTION f3()
24 IS 'system_u:object_r:sepgsql_trusted_proc_exec_t:s0';
25 CREATE FUNCTION f4 () RETURNS text
26 AS 'SELECT sepgsql_getcon()'
27 LANGUAGE sql;
28 SECURITY LABEL ON FUNCTION f4()
29 IS 'system_u:object_r:sepgsql_nosuch_trusted_proc_exec_t:s0';
30 CREATE FUNCTION f5 (text) RETURNS bool
31 AS 'SELECT sepgsql_setcon($1)'
32 LANGUAGE sql;
33 SECURITY LABEL ON FUNCTION f5(text)
34 IS 'system_u:object_r:sepgsql_regtest_trusted_proc_exec_t:s0';
35 CREATE TABLE auth_tbl(uname text, credential text, label text);
36 INSERT INTO auth_tbl
37 VALUES ('foo', 'acbd18db4cc2f85cedef654fccc4a4d8', 'sepgsql_regtest_foo_t:s0'),
38 ('var', 'b2145aac704ce76dbe1ac7adac535b23', 'sepgsql_regtest_var_t:s0'),
39 ('baz', 'b2145aac704ce76dbe1ac7adac535b23', 'sepgsql_regtest_baz_t:s0');
40 SECURITY LABEL ON TABLE auth_tbl
41 IS 'system_u:object_r:sepgsql_secret_table_t:s0';
42 CREATE FUNCTION auth_func(text, text) RETURNS bool
43 LANGUAGE sql
44 AS 'SELECT sepgsql_setcon(regexp_replace(sepgsql_getcon(), ''_r:.*$'', ''_r:'' || label))
45 FROM auth_tbl WHERE uname = $1 AND credential = $2';
46 SECURITY LABEL ON FUNCTION auth_func(text,text)
47 IS 'system_u:object_r:sepgsql_regtest_trusted_proc_exec_t:s0';
48 CREATE TABLE foo_tbl(a int, b text);
49 INSERT INTO foo_tbl VALUES (1, 'aaa'), (2,'bbb'), (3,'ccc'), (4,'ddd');
50 SECURITY LABEL ON TABLE foo_tbl
51 IS 'system_u:object_r:sepgsql_regtest_foo_table_t:s0';
52 CREATE TABLE var_tbl(x int, y text);
53 INSERT INTO var_tbl VALUES (2,'xxx'), (3,'yyy'), (4,'zzz'), (5,'xyz');
54 SECURITY LABEL ON TABLE var_tbl
55 IS 'system_u:object_r:sepgsql_regtest_var_table_t:s0';
56 CREATE TABLE foo_ptbl(o int, p text) PARTITION BY RANGE (o);
57 CREATE TABLE foo_ptbl_ones PARTITION OF foo_ptbl FOR VALUES FROM ('0') TO ('10');
58 CREATE TABLE foo_ptbl_tens PARTITION OF foo_ptbl FOR VALUES FROM ('10') TO ('100');
59 INSERT INTO foo_ptbl VALUES (0, 'aaa'), (9,'bbb'), (10,'ccc'), (99,'ddd');
60 SECURITY LABEL ON TABLE foo_ptbl
61 IS 'system_u:object_r:sepgsql_regtest_foo_table_t:s0';
62 CREATE TABLE var_ptbl(q int, r text) PARTITION BY RANGE (q);
63 CREATE TABLE var_ptbl_ones PARTITION OF var_ptbl FOR VALUES FROM ('0') TO ('10');
64 CREATE TABLE var_ptbl_tens PARTITION OF var_ptbl FOR VALUES FROM ('10') TO ('100');
65 INSERT INTO var_ptbl VALUES (0,'xxx'), (9,'yyy'), (10,'zzz'), (99,'xyz');
66 SECURITY LABEL ON TABLE var_ptbl
67 IS 'system_u:object_r:sepgsql_regtest_var_table_t:s0';
68 --
69 -- Tests for default labeling behavior
70 --
71 SELECT sepgsql_getcon(); -- confirm client privilege
72 sepgsql_getcon
73 -----------------------------------------------------
74 unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0
75 (1 row)
76
77 CREATE TABLE t3 (s int, t text);
78 INSERT INTO t3 VALUES (1, 'sss'), (2, 'ttt'), (3, 'uuu');
79 SELECT sepgsql_getcon(); -- confirm client privilege
80 sepgsql_getcon
81 ----------------------------------------------------
82 unconfined_u:unconfined_r:sepgsql_regtest_dba_t:s0
83 (1 row)
84
85 CREATE TABLE t4 (m int, n text);
86 INSERT INTO t4 VALUES (1,'mmm'), (2,'nnn'), (3,'ooo');
87 SELECT sepgsql_getcon(); -- confirm client privilege
88 sepgsql_getcon
89 -----------------------------------------------------
90 unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0
91 (1 row)
92
93 CREATE TABLE tpart (o int, p text) PARTITION BY RANGE (o);
94 CREATE TABLE tpart_ones PARTITION OF tpart FOR VALUES FROM ('0') TO ('10');
95 SELECT sepgsql_getcon(); -- confirm client privilege
96 sepgsql_getcon
97 ----------------------------------------------------
98 unconfined_u:unconfined_r:sepgsql_regtest_dba_t:s0
99 (1 row)
100
101 CREATE TABLE tpart_tens PARTITION OF tpart FOR VALUES FROM ('10') TO ('100');
102 INSERT INTO tpart VALUES (0, 'aaa');
103 INSERT INTO tpart VALUES (9, 'bbb');
104 INSERT INTO tpart VALUES (99, 'ccc');
105 SELECT objtype, objname, label FROM pg_seclabels
106 WHERE provider = 'selinux' AND objtype = 'table' AND objname in ('t1', 't2', 't3',
107 'tpart',
108 'tpart_ones',
109 'tpart_tens')
110 ORDER BY objname COLLATE "C" ASC;
111 objtype | objname | label
112 ---------+------------+-----------------------------------------------
113 table | t1 | unconfined_u:object_r:sepgsql_table_t:s0
114 table | t2 | unconfined_u:object_r:sepgsql_table_t:s0
115 table | t3 | unconfined_u:object_r:user_sepgsql_table_t:s0
116 table | tpart | unconfined_u:object_r:user_sepgsql_table_t:s0
117 table | tpart_ones | unconfined_u:object_r:user_sepgsql_table_t:s0
118 table | tpart_tens | unconfined_u:object_r:sepgsql_table_t:s0
119 (6 rows)
120
121 SELECT objtype, objname, label FROM pg_seclabels
122 WHERE provider = 'selinux' AND objtype = 'column' AND (objname like 't3.%'
123 OR objname like 't4.%'
124 OR objname like 'tpart.%'
125 OR objname like 'tpart_ones.%'
126 OR objname like 'tpart_tens.%')
127 ORDER BY objname COLLATE "C" ASC;
128 objtype | objname | label
129 ---------+---------------------+-----------------------------------------------
130 column | t3.cmax | unconfined_u:object_r:user_sepgsql_table_t:s0
131 column | t3.cmin | unconfined_u:object_r:user_sepgsql_table_t:s0
132 column | t3.ctid | unconfined_u:object_r:user_sepgsql_table_t:s0
133 column | t3.s | unconfined_u:object_r:user_sepgsql_table_t:s0
134 column | t3.t | unconfined_u:object_r:user_sepgsql_table_t:s0
135 column | t3.tableoid | unconfined_u:object_r:user_sepgsql_table_t:s0
136 column | t3.xmax | unconfined_u:object_r:user_sepgsql_table_t:s0
137 column | t3.xmin | unconfined_u:object_r:user_sepgsql_table_t:s0
138 column | t4.cmax | unconfined_u:object_r:sepgsql_sysobj_t:s0
139 column | t4.cmin | unconfined_u:object_r:sepgsql_sysobj_t:s0
140 column | t4.ctid | unconfined_u:object_r:sepgsql_sysobj_t:s0
141 column | t4.m | unconfined_u:object_r:sepgsql_table_t:s0
142 column | t4.n | unconfined_u:object_r:sepgsql_table_t:s0
143 column | t4.tableoid | unconfined_u:object_r:sepgsql_sysobj_t:s0
144 column | t4.xmax | unconfined_u:object_r:sepgsql_sysobj_t:s0
145 column | t4.xmin | unconfined_u:object_r:sepgsql_sysobj_t:s0
146 column | tpart.cmax | unconfined_u:object_r:user_sepgsql_table_t:s0
147 column | tpart.cmin | unconfined_u:object_r:user_sepgsql_table_t:s0
148 column | tpart.ctid | unconfined_u:object_r:user_sepgsql_table_t:s0
149 column | tpart.o | unconfined_u:object_r:user_sepgsql_table_t:s0
150 column | tpart.p | unconfined_u:object_r:user_sepgsql_table_t:s0
151 column | tpart.tableoid | unconfined_u:object_r:user_sepgsql_table_t:s0
152 column | tpart.xmax | unconfined_u:object_r:user_sepgsql_table_t:s0
153 column | tpart.xmin | unconfined_u:object_r:user_sepgsql_table_t:s0
154 column | tpart_ones.cmax | unconfined_u:object_r:user_sepgsql_table_t:s0
155 column | tpart_ones.cmin | unconfined_u:object_r:user_sepgsql_table_t:s0
156 column | tpart_ones.ctid | unconfined_u:object_r:user_sepgsql_table_t:s0
157 column | tpart_ones.o | unconfined_u:object_r:user_sepgsql_table_t:s0
158 column | tpart_ones.p | unconfined_u:object_r:user_sepgsql_table_t:s0
159 column | tpart_ones.tableoid | unconfined_u:object_r:user_sepgsql_table_t:s0
160 column | tpart_ones.xmax | unconfined_u:object_r:user_sepgsql_table_t:s0
161 column | tpart_ones.xmin | unconfined_u:object_r:user_sepgsql_table_t:s0
162 column | tpart_tens.cmax | unconfined_u:object_r:sepgsql_sysobj_t:s0
163 column | tpart_tens.cmin | unconfined_u:object_r:sepgsql_sysobj_t:s0
164 column | tpart_tens.ctid | unconfined_u:object_r:sepgsql_sysobj_t:s0
165 column | tpart_tens.o | unconfined_u:object_r:sepgsql_table_t:s0
166 column | tpart_tens.p | unconfined_u:object_r:sepgsql_table_t:s0
167 column | tpart_tens.tableoid | unconfined_u:object_r:sepgsql_sysobj_t:s0
168 column | tpart_tens.xmax | unconfined_u:object_r:sepgsql_sysobj_t:s0
169 column | tpart_tens.xmin | unconfined_u:object_r:sepgsql_sysobj_t:s0
170 (40 rows)
171
172 --
173 -- Tests for SECURITY LABEL
174 --
175 SELECT sepgsql_getcon(); -- confirm client privilege
176 sepgsql_getcon
177 ----------------------------------------------------
178 unconfined_u:unconfined_r:sepgsql_regtest_dba_t:s0
179 (1 row)
180
181 SECURITY LABEL ON TABLE t1
182 IS 'system_u:object_r:sepgsql_ro_table_t:s0'; -- ok
183 SECURITY LABEL ON TABLE t2
184 IS 'invalid security context'; -- be failed
185 ERROR: SELinux: invalid security label: "invalid security context"
186 SECURITY LABEL ON COLUMN t2
187 IS 'system_u:object_r:sepgsql_ro_table_t:s0'; -- be failed
188 ERROR: column name must be qualified
189 SECURITY LABEL ON COLUMN t2.b
190 IS 'system_u:object_r:sepgsql_ro_table_t:s0'; -- ok
191 SECURITY LABEL ON TABLE tpart
192 IS 'system_u:object_r:sepgsql_ro_table_t:s0'; -- ok
193 SECURITY LABEL ON TABLE tpart
194 IS 'invalid security context'; -- failed
195 ERROR: SELinux: invalid security label: "invalid security context"
196 SECURITY LABEL ON COLUMN tpart
197 IS 'system_u:object_r:sepgsql_ro_table_t:s0'; -- failed
198 ERROR: column name must be qualified
199 SECURITY LABEL ON COLUMN tpart.o
200 IS 'system_u:object_r:sepgsql_ro_table_t:s0'; -- ok
201 --
202 -- Tests for Trusted Procedures
203 --
204 SELECT sepgsql_getcon(); -- confirm client privilege
205 sepgsql_getcon
206 -----------------------------------------------------
207 unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0
208 (1 row)
209
210 SET sepgsql.debug_audit = true;
211 SET client_min_messages = log;
212 SELECT f1(); -- normal procedure
213 LOG: SELinux: allowed { execute } scontext=unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0 tcontext=unconfined_u:object_r:sepgsql_proc_exec_t:s0 tclass=db_procedure name="public.f1()" permissive=0
214 LOG: SELinux: allowed { execute } scontext=unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0 tcontext=system_u:object_r:sepgsql_proc_exec_t:s0 tclass=db_procedure name="pg_catalog.sepgsql_getcon()" permissive=0
215 f1
216 -----------------------------------------------------
217 unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0
218 (1 row)
219
220 SELECT f2(); -- trusted procedure
221 LOG: SELinux: allowed { execute } scontext=unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0 tcontext=system_u:object_r:sepgsql_trusted_proc_exec_t:s0 tclass=db_procedure name="public.f2()" permissive=0
222 LOG: SELinux: allowed { entrypoint } scontext=unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0 tcontext=system_u:object_r:sepgsql_trusted_proc_exec_t:s0 tclass=db_procedure name="function f2()" permissive=0
223 LOG: SELinux: allowed { transition } scontext=unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0 tcontext=unconfined_u:unconfined_r:sepgsql_trusted_proc_t:s0 tclass=process permissive=0
224 LOG: SELinux: allowed { execute } scontext=unconfined_u:unconfined_r:sepgsql_trusted_proc_t:s0 tcontext=system_u:object_r:sepgsql_proc_exec_t:s0 tclass=db_procedure name="pg_catalog.sepgsql_getcon()" permissive=0
225 f2
226 -----------------------------------------------------
227 unconfined_u:unconfined_r:sepgsql_trusted_proc_t:s0
228 (1 row)
229
230 SELECT f3(); -- trusted procedure that raises an error
231 LOG: SELinux: allowed { execute } scontext=unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0 tcontext=system_u:object_r:sepgsql_trusted_proc_exec_t:s0 tclass=db_procedure name="public.f3()" permissive=0
232 LOG: SELinux: allowed { entrypoint } scontext=unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0 tcontext=system_u:object_r:sepgsql_trusted_proc_exec_t:s0 tclass=db_procedure name="function f3()" permissive=0
233 LOG: SELinux: allowed { transition } scontext=unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0 tcontext=unconfined_u:unconfined_r:sepgsql_trusted_proc_t:s0 tclass=process permissive=0
234 ERROR: an exception from f3()
235 CONTEXT: PL/pgSQL function f3() line 2 at RAISE
236 SELECT f4(); -- failed on domain transition
237 LOG: SELinux: allowed { execute } scontext=unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0 tcontext=system_u:object_r:sepgsql_nosuch_trusted_proc_exec_t:s0 tclass=db_procedure name="public.f4()" permissive=0
238 LOG: SELinux: allowed { entrypoint } scontext=unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0 tcontext=system_u:object_r:sepgsql_nosuch_trusted_proc_exec_t:s0 tclass=db_procedure name="function f4()" permissive=0
239 LOG: SELinux: denied { transition } scontext=unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0 tcontext=unconfined_u:unconfined_r:sepgsql_regtest_nosuch_t:s0 tclass=process permissive=0
240 ERROR: SELinux: security policy violation
241 SELECT sepgsql_getcon(); -- client's label must be restored
242 LOG: SELinux: allowed { execute } scontext=unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0 tcontext=system_u:object_r:sepgsql_proc_exec_t:s0 tclass=db_procedure name="pg_catalog.sepgsql_getcon()" permissive=0
243 sepgsql_getcon
244 -----------------------------------------------------
245 unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0
246 (1 row)
247
248 --
249 -- Test for Dynamic Domain Transition
250 --
251 -- validation of transaction aware dynamic-transition
252 SELECT sepgsql_getcon(); -- confirm client privilege
253 sepgsql_getcon
254 -----------------------------------------------------------------
255 unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0:c0.c25
256 (1 row)
257
258 SELECT sepgsql_setcon('unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0:c0.c15');
259 sepgsql_setcon
260 ----------------
261 t
262 (1 row)
263
264 SELECT sepgsql_getcon();
265 sepgsql_getcon
266 -----------------------------------------------------------------
267 unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0:c0.c15
268 (1 row)
269
270 SELECT sepgsql_setcon(NULL); -- failed to reset
271 ERROR: SELinux: security policy violation
272 SELECT sepgsql_getcon();
273 sepgsql_getcon
274 -----------------------------------------------------------------
275 unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0:c0.c15
276 (1 row)
277
278 BEGIN;
279 SELECT sepgsql_setcon('unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0:c0.c12');
280 sepgsql_setcon
281 ----------------
282 t
283 (1 row)
284
285 SELECT sepgsql_getcon();
286 sepgsql_getcon
287 -----------------------------------------------------------------
288 unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0:c0.c12
289 (1 row)
290
291 SAVEPOINT svpt_1;
292 SELECT sepgsql_setcon('unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0:c0.c9');
293 sepgsql_setcon
294 ----------------
295 t
296 (1 row)
297
298 SELECT sepgsql_getcon();
299 sepgsql_getcon
300 ----------------------------------------------------------------
301 unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0:c0.c9
302 (1 row)
303
304 SAVEPOINT svpt_2;
305 SELECT sepgsql_setcon('unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0:c0.c6');
306 sepgsql_setcon
307 ----------------
308 t
309 (1 row)
310
311 SELECT sepgsql_getcon();
312 sepgsql_getcon
313 ----------------------------------------------------------------
314 unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0:c0.c6
315 (1 row)
316
317 SAVEPOINT svpt_3;
318 SELECT sepgsql_setcon('unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0:c0.c3');
319 sepgsql_setcon
320 ----------------
321 t
322 (1 row)
323
324 SELECT sepgsql_getcon();
325 sepgsql_getcon
326 ----------------------------------------------------------------
327 unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0:c0.c3
328 (1 row)
329
330 ROLLBACK TO SAVEPOINT svpt_2;
331 SELECT sepgsql_getcon(); -- should be 's0:c0.c9'
332 sepgsql_getcon
333 ----------------------------------------------------------------
334 unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0:c0.c9
335 (1 row)
336
337 ROLLBACK TO SAVEPOINT svpt_1;
338 SELECT sepgsql_getcon(); -- should be 's0:c0.c12'
339 sepgsql_getcon
340 -----------------------------------------------------------------
341 unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0:c0.c12
342 (1 row)
343
344 ABORT;
345 SELECT sepgsql_getcon(); -- should be 's0:c0.c15'
346 sepgsql_getcon
347 -----------------------------------------------------------------
348 unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0:c0.c15
349 (1 row)
350
351 BEGIN;
352 SELECT sepgsql_setcon('unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0:c0.c8');
353 sepgsql_setcon
354 ----------------
355 t
356 (1 row)
357
358 SELECT sepgsql_getcon();
359 sepgsql_getcon
360 ----------------------------------------------------------------
361 unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0:c0.c8
362 (1 row)
363
364 SAVEPOINT svpt_1;
365 SELECT sepgsql_setcon('unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0:c0.c4');
366 sepgsql_setcon
367 ----------------
368 t
369 (1 row)
370
371 SELECT sepgsql_getcon();
372 sepgsql_getcon
373 ----------------------------------------------------------------
374 unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0:c0.c4
375 (1 row)
376
377 ROLLBACK TO SAVEPOINT svpt_1;
378 SELECT sepgsql_getcon(); -- should be 's0:c0.c8'
379 sepgsql_getcon
380 ----------------------------------------------------------------
381 unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0:c0.c8
382 (1 row)
383
384 SELECT sepgsql_setcon('unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0:c0.c6');
385 sepgsql_setcon
386 ----------------
387 t
388 (1 row)
389
390 COMMIT;
391 SELECT sepgsql_getcon(); -- should be 's0:c0.c6'
392 sepgsql_getcon
393 ----------------------------------------------------------------
394 unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0:c0.c6
395 (1 row)
396
397 -- sepgsql_regtest_user_t is not available dynamic-transition,
398 -- unless sepgsql_setcon() is called inside of trusted-procedure
399 SELECT sepgsql_getcon(); -- confirm client privilege
400 sepgsql_getcon
401 ------------------------------------------------------------
402 unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0:c0.c15
403 (1 row)
404
405 -- sepgsql_regtest_user_t has no permission to switch current label
406 SELECT sepgsql_setcon('unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0'); -- failed
407 ERROR: SELinux: security policy violation
408 SELECT sepgsql_getcon();
409 sepgsql_getcon
410 ------------------------------------------------------------
411 unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0:c0.c15
412 (1 row)
413
414 -- trusted procedure allows to switch, but unavailable to override MCS rules
415 SELECT f5('unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0:c0.c7'); -- OK
416 f5
417 ----
418 t
419 (1 row)
420
421 SELECT sepgsql_getcon();
422 sepgsql_getcon
423 -----------------------------------------------------------
424 unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0:c0.c7
425 (1 row)
426
427 SELECT f5('unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0:c0.c31'); -- Failed
428 ERROR: SELinux: security policy violation
429 CONTEXT: SQL function "f5" statement 1
430 SELECT sepgsql_getcon();
431 sepgsql_getcon
432 -----------------------------------------------------------
433 unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0:c0.c7
434 (1 row)
435
436 SELECT f5(NULL); -- Failed
437 ERROR: SELinux: security policy violation
438 CONTEXT: SQL function "f5" statement 1
439 SELECT sepgsql_getcon();
440 sepgsql_getcon
441 -----------------------------------------------------------
442 unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0:c0.c7
443 (1 row)
444
445 BEGIN;
446 SELECT f5('unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0:c0.c3'); -- OK
447 f5
448 ----
449 t
450 (1 row)
451
452 SELECT sepgsql_getcon();
453 sepgsql_getcon
454 -----------------------------------------------------------
455 unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0:c0.c3
456 (1 row)
457
458 ABORT;
459 SELECT sepgsql_getcon();
460 sepgsql_getcon
461 -----------------------------------------------------------
462 unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0:c0.c7
463 (1 row)
464
465 --
466 -- Test for simulation of typical connection pooling server
467 --
468 SELECT sepgsql_getcon(); -- confirm client privilege
469 sepgsql_getcon
470 -----------------------------------------------------
471 unconfined_u:unconfined_r:sepgsql_regtest_pool_t:s0
472 (1 row)
473
474 -- we shouldn't allow to switch client label without trusted procedure
475 SELECT sepgsql_setcon('unconfined_u:unconfined_r:sepgsql_regtest_foo_t:s0');
476 ERROR: SELinux: security policy violation
477 SELECT * FROM auth_tbl; -- failed, no permission to reference
478 ERROR: SELinux: security policy violation
479 -- switch to "foo"
480 SELECT auth_func('foo', 'acbd18db4cc2f85cedef654fccc4a4d8');
481 auth_func
482 -----------
483 t
484 (1 row)
485
486 SELECT sepgsql_getcon();
487 sepgsql_getcon
488 ----------------------------------------------------
489 unconfined_u:unconfined_r:sepgsql_regtest_foo_t:s0
490 (1 row)
491
492 SELECT * FROM foo_tbl; -- OK
493 a | b
494 ---+-----
495 1 | aaa
496 2 | bbb
497 3 | ccc
498 4 | ddd
499 (4 rows)
500
501 SELECT * FROM foo_ptbl; -- OK
502 o | p
503 ----+-----
504 0 | aaa
505 9 | bbb
506 10 | ccc
507 99 | ddd
508 (4 rows)
509
510 SELECT * FROM var_tbl; -- failed
511 ERROR: SELinux: security policy violation
512 SELECT * FROM var_ptbl; -- failed
513 ERROR: SELinux: security policy violation
514 SELECT * FROM auth_tbl; -- failed
515 ERROR: SELinux: security policy violation
516 SELECT sepgsql_setcon(NULL); -- end of session
517 sepgsql_setcon
518 ----------------
519 t
520 (1 row)
521
522 SELECT sepgsql_getcon();
523 sepgsql_getcon
524 -----------------------------------------------------
525 unconfined_u:unconfined_r:sepgsql_regtest_pool_t:s0
526 (1 row)
527
528 -- the pooler cannot touch these tables directly
529 SELECT * FROM foo_tbl; -- failed
530 ERROR: SELinux: security policy violation
531 SELECT * FROM foo_ptbl; -- failed
532 ERROR: SELinux: security policy violation
533 SELECT * FROM var_tbl; -- failed
534 ERROR: SELinux: security policy violation
535 SELECT * FROM var_ptbl; -- failed
536 ERROR: SELinux: security policy violation
537 -- switch to "var"
538 SELECT auth_func('var', 'b2145aac704ce76dbe1ac7adac535b23');
539 auth_func
540 -----------
541 t
542 (1 row)
543
544 SELECT sepgsql_getcon();
545 sepgsql_getcon
546 ----------------------------------------------------
547 unconfined_u:unconfined_r:sepgsql_regtest_var_t:s0
548 (1 row)
549
550 SELECT * FROM foo_tbl; -- failed
551 ERROR: SELinux: security policy violation
552 SELECT * FROM foo_ptbl; -- failed
553 ERROR: SELinux: security policy violation
554 SELECT * FROM var_tbl; -- OK
555 x | y
556 ---+-----
557 2 | xxx
558 3 | yyy
559 4 | zzz
560 5 | xyz
561 (4 rows)
562
563 SELECT * FROM var_ptbl; -- OK
564 q | r
565 ----+-----
566 0 | xxx
567 9 | yyy
568 10 | zzz
569 99 | xyz
570 (4 rows)
571
572 SELECT * FROM auth_tbl; -- failed
573 ERROR: SELinux: security policy violation
574 SELECT sepgsql_setcon(NULL); -- end of session
575 sepgsql_setcon
576 ----------------
577 t
578 (1 row)
579
580 -- misc checks
581 SELECT auth_func('var', 'invalid credential'); -- not works
582 auth_func
583 -----------
584
585 (1 row)
586
587 SELECT sepgsql_getcon();
588 sepgsql_getcon
589 -----------------------------------------------------
590 unconfined_u:unconfined_r:sepgsql_regtest_pool_t:s0
591 (1 row)
592
593 --
594 -- Clean up
595 --
596 SELECT sepgsql_getcon(); -- confirm client privilege
597 sepgsql_getcon
598 ---------------------------------------------------------------------
599 unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0-s0:c0.c255
600 (1 row)
601
602 DROP TABLE IF EXISTS t1 CASCADE;
603 DROP TABLE IF EXISTS t2 CASCADE;
604 DROP TABLE IF EXISTS t3 CASCADE;
605 DROP TABLE IF EXISTS t4 CASCADE;
606 DROP TABLE IF EXISTS tpart CASCADE;
607 DROP FUNCTION IF EXISTS f1() CASCADE;
608 DROP FUNCTION IF EXISTS f2() CASCADE;
609 DROP FUNCTION IF EXISTS f3() CASCADE;
610 DROP FUNCTION IF EXISTS f4() CASCADE;
611 DROP FUNCTION IF EXISTS f5(text) CASCADE;