| 1 |
-- |
| 2 |
-- Regression Test for DML Permissions |
| 3 |
-- |
| 4 |
|
| 5 |
-- |
| 6 |
-- Setup |
| 7 |
-- |
| 8 |
CREATE TABLE t1 (a int, junk int, b text); |
| 9 |
SECURITY LABEL ON TABLE t1 IS 'system_u:object_r:sepgsql_table_t:s0'; |
| 10 |
ALTER TABLE t1 DROP COLUMN junk; |
| 11 |
INSERT INTO t1 VALUES (1, 'aaa'), (2, 'bbb'), (3, 'ccc'); |
| 12 |
|
| 13 |
CREATE TABLE t2 (x int, y text); |
| 14 |
SECURITY LABEL ON TABLE t2 IS 'system_u:object_r:sepgsql_ro_table_t:s0'; |
| 15 |
INSERT INTO t2 VALUES (1, 'xxx'), (2, 'yyy'), (3, 'zzz'); |
| 16 |
|
| 17 |
CREATE TABLE t3 (s int, t text); |
| 18 |
SECURITY LABEL ON TABLE t3 IS 'system_u:object_r:sepgsql_fixed_table_t:s0'; |
| 19 |
INSERT INTO t3 VALUES (1, 'sss'), (2, 'ttt'), (3, 'uuu'); |
| 20 |
|
| 21 |
CREATE TABLE t4 (m int, junk int, n text); |
| 22 |
SECURITY LABEL ON TABLE t4 IS 'system_u:object_r:sepgsql_secret_table_t:s0'; |
| 23 |
ALTER TABLE t4 DROP COLUMN junk; |
| 24 |
INSERT INTO t4 VALUES (1, 'mmm'), (2, 'nnn'), (3, 'ooo'); |
| 25 |
|
| 26 |
CREATE TABLE t5 (e text, f text, g text); |
| 27 |
SECURITY LABEL ON TABLE t5 IS 'system_u:object_r:sepgsql_table_t:s0'; |
| 28 |
SECURITY LABEL ON COLUMN t5.e IS 'system_u:object_r:sepgsql_table_t:s0'; |
| 29 |
SECURITY LABEL ON COLUMN t5.f IS 'system_u:object_r:sepgsql_ro_table_t:s0'; |
| 30 |
SECURITY LABEL ON COLUMN t5.g IS 'system_u:object_r:sepgsql_secret_table_t:s0'; |
| 31 |
|
| 32 |
--- |
| 33 |
-- partitioned table parent |
| 34 |
CREATE TABLE t1p (o int, p text, q text) PARTITION BY RANGE (o); |
| 35 |
SECURITY LABEL ON TABLE t1p IS 'system_u:object_r:sepgsql_table_t:s0'; |
| 36 |
SECURITY LABEL ON COLUMN t1p.o IS 'system_u:object_r:sepgsql_table_t:s0'; |
| 37 |
SECURITY LABEL ON COLUMN t1p.p IS 'system_u:object_r:sepgsql_ro_table_t:s0'; |
| 38 |
SECURITY LABEL ON COLUMN t1p.q IS 'system_u:object_r:sepgsql_secret_table_t:s0'; |
| 39 |
|
| 40 |
-- partitioned table children |
| 41 |
CREATE TABLE t1p_ones PARTITION OF t1p FOR VALUES FROM ('0') TO ('10'); |
| 42 |
SECURITY LABEL ON COLUMN t1p_ones.o IS 'system_u:object_r:sepgsql_table_t:s0'; |
| 43 |
SECURITY LABEL ON COLUMN t1p_ones.p IS 'system_u:object_r:sepgsql_ro_table_t:s0'; |
| 44 |
SECURITY LABEL ON COLUMN t1p_ones.q IS 'system_u:object_r:sepgsql_secret_table_t:s0'; |
| 45 |
CREATE TABLE t1p_tens PARTITION OF t1p FOR VALUES FROM ('10') TO ('100'); |
| 46 |
SECURITY LABEL ON COLUMN t1p_tens.o IS 'system_u:object_r:sepgsql_table_t:s0'; |
| 47 |
SECURITY LABEL ON COLUMN t1p_tens.p IS 'system_u:object_r:sepgsql_ro_table_t:s0'; |
| 48 |
SECURITY LABEL ON COLUMN t1p_tens.q IS 'system_u:object_r:sepgsql_secret_table_t:s0'; |
| 49 |
|
| 50 |
--- |
| 51 |
|
| 52 |
CREATE TABLE customer (cid int primary key, cname text, ccredit text); |
| 53 |
SECURITY LABEL ON COLUMN customer.ccredit IS 'system_u:object_r:sepgsql_secret_table_t:s0'; |
| 54 |
INSERT INTO customer VALUES (1, 'Taro', '1111-2222-3333-4444'), |
| 55 |
(2, 'Hanako', '5555-6666-7777-8888'); |
| 56 |
CREATE FUNCTION customer_credit(int) RETURNS text |
| 57 |
AS 'SELECT regexp_replace(ccredit, ''-[0-9]+$'', ''-????'') FROM customer WHERE cid = $1' |
| 58 |
LANGUAGE sql; |
| 59 |
SECURITY LABEL ON FUNCTION customer_credit(int) |
| 60 |
IS 'system_u:object_r:sepgsql_trusted_proc_exec_t:s0'; |
| 61 |
|
| 62 |
SELECT objtype, objname, label FROM pg_seclabels |
| 63 |
WHERE provider = 'selinux' |
| 64 |
AND objtype in ('table', 'column') |
| 65 |
AND objname in ('t1', 't2', 't3', 't4', |
| 66 |
't5', 't5.e', 't5.f', 't5.g', |
| 67 |
't1p', 't1p.o', 't1p.p', 't1p.q', |
| 68 |
't1p_ones', 't1p_ones.o', 't1p_ones.p', 't1p_ones.q', |
| 69 |
't1p_tens', 't1p_tens.o', 't1p_tens.p', 't1p_tens.q') |
| 70 |
ORDER BY objname COLLATE "C"; |
| 71 |
|
| 72 |
CREATE SCHEMA my_schema_1; |
| 73 |
CREATE TABLE my_schema_1.ts1 (a int, b text); |
| 74 |
CREATE TABLE my_schema_1.pts1 (o int, p text) PARTITION BY RANGE (o); |
| 75 |
CREATE TABLE my_schema_1.pts1_ones PARTITION OF my_schema_1.pts1 FOR VALUES FROM ('0') to ('10'); |
| 76 |
|
| 77 |
CREATE SCHEMA my_schema_2; |
| 78 |
CREATE TABLE my_schema_2.ts2 (x int, y text); |
| 79 |
CREATE TABLE my_schema_2.pts2 (o int, p text) PARTITION BY RANGE (o); |
| 80 |
CREATE TABLE my_schema_2.pts2_tens PARTITION OF my_schema_2.pts2 FOR VALUES FROM ('10') to ('100'); |
| 81 |
|
| 82 |
SECURITY LABEL ON SCHEMA my_schema_2 |
| 83 |
IS 'system_u:object_r:sepgsql_regtest_invisible_schema_t:s0'; |
| 84 |
|
| 85 |
-- Hardwired Rules |
| 86 |
UPDATE pg_attribute SET attisdropped = true |
| 87 |
WHERE attrelid = 't5'::regclass AND attname = 'f'; -- failed |
| 88 |
|
| 89 |
-- |
| 90 |
-- Simple DML statements |
| 91 |
-- |
| 92 |
-- @SECURITY-CONTEXT=unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0 |
| 93 |
|
| 94 |
SELECT * FROM t1; -- ok |
| 95 |
SELECT * FROM t2; -- ok |
| 96 |
SELECT * FROM t3; -- ok |
| 97 |
SELECT * FROM t4; -- failed |
| 98 |
SELECT * FROM t5; -- failed |
| 99 |
SELECT e,f FROM t5; -- ok |
| 100 |
SELECT (t1.*)::record FROM t1; -- ok |
| 101 |
SELECT (t4.*)::record FROM t4; -- failed |
| 102 |
|
| 103 |
--- |
| 104 |
-- partitioned table parent |
| 105 |
SELECT * FROM t1p; -- failed |
| 106 |
SELECT o,p FROM t1p; -- ok |
| 107 |
--partitioned table children |
| 108 |
SELECT * FROM t1p_ones; -- failed |
| 109 |
SELECT o FROM t1p_ones; -- ok |
| 110 |
SELECT o,p FROM t1p_ones; -- ok |
| 111 |
SELECT * FROM t1p_tens; -- failed |
| 112 |
SELECT o FROM t1p_tens; -- ok |
| 113 |
SELECT o,p FROM t1p_tens; -- ok |
| 114 |
--- |
| 115 |
|
| 116 |
SELECT * FROM customer; -- failed |
| 117 |
SELECT cid, cname, customer_credit(cid) FROM customer; -- ok |
| 118 |
|
| 119 |
SELECT count(*) FROM t5; -- ok |
| 120 |
SELECT count(*) FROM t5 WHERE g IS NULL; -- failed |
| 121 |
|
| 122 |
--- |
| 123 |
-- partitioned table parent |
| 124 |
SELECT count(*) FROM t1p; -- ok |
| 125 |
SELECT count(*) FROM t1p WHERE q IS NULL; -- failed |
| 126 |
-- partitioned table children |
| 127 |
SELECT count(*) FROM t1p_ones; -- ok |
| 128 |
SELECT count(*) FROM t1p_ones WHERE q IS NULL; -- failed |
| 129 |
SELECT count(*) FROM t1p_tens; -- ok |
| 130 |
SELECT count(*) FROM t1p_tens WHERE q IS NULL; -- failed |
| 131 |
--- |
| 132 |
|
| 133 |
INSERT INTO t1 VALUES (4, 'abc'); -- ok |
| 134 |
INSERT INTO t2 VALUES (4, 'xyz'); -- failed |
| 135 |
INSERT INTO t3 VALUES (4, 'stu'); -- ok |
| 136 |
INSERT INTO t4 VALUES (4, 'mno'); -- failed |
| 137 |
INSERT INTO t5 VALUES (1,2,3); -- failed |
| 138 |
INSERT INTO t5 (e,f) VALUES ('abc', 'def'); -- failed |
| 139 |
INSERT INTO t5 (e) VALUES ('abc'); -- ok |
| 140 |
|
| 141 |
--- |
| 142 |
-- partitioned table parent |
| 143 |
INSERT INTO t1p (o,p) VALUES (9, 'mno'); -- failed |
| 144 |
INSERT INTO t1p (o) VALUES (9); -- ok |
| 145 |
INSERT INTO t1p (o,p) VALUES (99, 'pqr'); -- failed |
| 146 |
INSERT INTO t1p (o) VALUES (99); -- ok |
| 147 |
-- partitioned table children |
| 148 |
INSERT INTO t1p_ones (o,p) VALUES (9, 'mno'); -- failed |
| 149 |
INSERT INTO t1p_ones (o) VALUES (9); -- ok |
| 150 |
INSERT INTO t1p_tens (o,p) VALUES (99, 'pqr'); -- failed |
| 151 |
INSERT INTO t1p_tens (o) VALUES (99); -- ok |
| 152 |
--- |
| 153 |
|
| 154 |
UPDATE t1 SET b = b || '_upd'; -- ok |
| 155 |
UPDATE t2 SET y = y || '_upd'; -- failed |
| 156 |
UPDATE t3 SET t = t || '_upd'; -- failed |
| 157 |
UPDATE t4 SET n = n || '_upd'; -- failed |
| 158 |
UPDATE t5 SET e = 'xyz'; -- ok |
| 159 |
UPDATE t5 SET e = f || '_upd'; -- ok |
| 160 |
UPDATE t5 SET e = g || '_upd'; -- failed |
| 161 |
|
| 162 |
--- |
| 163 |
-- partitioned table parent |
| 164 |
UPDATE t1p SET o = 9 WHERE o < 10; -- ok |
| 165 |
UPDATE t1p SET o = 99 WHERE o >= 10; -- ok |
| 166 |
UPDATE t1p SET o = ascii(COALESCE(p,'upd'))%10 WHERE o < 10; -- ok |
| 167 |
UPDATE t1p SET o = ascii(COALESCE(q,'upd'))%100 WHERE o >= 10; -- failed |
| 168 |
-- partitioned table children |
| 169 |
UPDATE t1p_ones SET o = 9; -- ok |
| 170 |
UPDATE t1p_ones SET o = ascii(COALESCE(p,'upd'))%10; -- ok |
| 171 |
UPDATE t1p_ones SET o = ascii(COALESCE(q,'upd'))%10; -- failed |
| 172 |
UPDATE t1p_tens SET o = 99; -- ok |
| 173 |
UPDATE t1p_tens SET o = ascii(COALESCE(p,'upd'))%100; -- ok |
| 174 |
UPDATE t1p_tens SET o = ascii(COALESCE(q,'upd'))%100; -- failed |
| 175 |
--- |
| 176 |
|
| 177 |
DELETE FROM t1; -- ok |
| 178 |
DELETE FROM t2; -- failed |
| 179 |
DELETE FROM t3; -- failed |
| 180 |
DELETE FROM t4; -- failed |
| 181 |
DELETE FROM t5; -- ok |
| 182 |
DELETE FROM t5 WHERE f IS NULL; -- ok |
| 183 |
DELETE FROM t5 WHERE g IS NULL; -- failed |
| 184 |
|
| 185 |
--- |
| 186 |
-- partitioned table parent |
| 187 |
DELETE FROM t1p; -- ok |
| 188 |
DELETE FROM t1p WHERE p IS NULL; -- ok |
| 189 |
DELETE FROM t1p WHERE q IS NULL; -- failed |
| 190 |
-- partitioned table children |
| 191 |
DELETE FROM t1p_ones WHERE p IS NULL; -- ok |
| 192 |
DELETE FROM t1p_ones WHERE q IS NULL; -- failed; |
| 193 |
DELETE FROM t1p_tens WHERE p IS NULL; -- ok |
| 194 |
DELETE FROM t1p_tens WHERE q IS NULL; -- failed |
| 195 |
--- |
| 196 |
|
| 197 |
-- |
| 198 |
-- COPY TO/FROM statements |
| 199 |
-- |
| 200 |
COPY t1 TO '/dev/null'; -- ok |
| 201 |
COPY t2 TO '/dev/null'; -- ok |
| 202 |
COPY t3 TO '/dev/null'; -- ok |
| 203 |
COPY t4 TO '/dev/null'; -- failed |
| 204 |
COPY t5 TO '/dev/null'; -- failed |
| 205 |
COPY t5(e,f) TO '/dev/null'; -- ok |
| 206 |
|
| 207 |
--- |
| 208 |
-- partitioned table parent |
| 209 |
COPY (SELECT * FROM t1p) TO '/dev/null'; -- failed |
| 210 |
COPY (SELECT (o,p) FROM t1p) TO '/dev/null'; -- ok |
| 211 |
-- partitioned table children |
| 212 |
COPY t1p_ones TO '/dev/null'; -- failed |
| 213 |
COPY t1p_ones(o,p) TO '/dev/null'; -- ok |
| 214 |
COPY t1p_tens TO '/dev/null'; -- failed |
| 215 |
COPY t1p_tens(o,p) TO '/dev/null'; -- ok |
| 216 |
--- |
| 217 |
|
| 218 |
COPY t1 FROM '/dev/null'; -- ok |
| 219 |
COPY t2 FROM '/dev/null'; -- failed |
| 220 |
COPY t3 FROM '/dev/null'; -- ok |
| 221 |
COPY t4 FROM '/dev/null'; -- failed |
| 222 |
COPY t5 FROM '/dev/null'; -- failed |
| 223 |
COPY t5 (e,f) FROM '/dev/null'; -- failed |
| 224 |
COPY t5 (e) FROM '/dev/null'; -- ok |
| 225 |
|
| 226 |
--- |
| 227 |
-- partitioned table parent |
| 228 |
COPY t1p FROM '/dev/null'; -- failed |
| 229 |
COPY t1p (o) FROM '/dev/null'; -- ok |
| 230 |
-- partitioned table children |
| 231 |
COPY t1p_ones FROM '/dev/null'; -- failed |
| 232 |
COPY t1p_ones (o) FROM '/dev/null'; -- ok |
| 233 |
COPY t1p_tens FROM '/dev/null'; -- failed |
| 234 |
COPY t1p_tens (o) FROM '/dev/null'; -- ok |
| 235 |
--- |
| 236 |
|
| 237 |
-- |
| 238 |
-- Schema search path |
| 239 |
-- |
| 240 |
SET search_path = my_schema_1, my_schema_2, public; |
| 241 |
SELECT * FROM ts1; -- ok |
| 242 |
SELECT * FROM ts2; -- failed (relation not found) |
| 243 |
SELECT * FROM my_schema_2.ts2; -- failed (policy violation) |
| 244 |
|
| 245 |
-- |
| 246 |
-- Clean up |
| 247 |
-- |
| 248 |
-- @SECURITY-CONTEXT=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0-s0:c0.c255 |
| 249 |
DROP TABLE IF EXISTS t1 CASCADE; |
| 250 |
DROP TABLE IF EXISTS t2 CASCADE; |
| 251 |
DROP TABLE IF EXISTS t3 CASCADE; |
| 252 |
DROP TABLE IF EXISTS t4 CASCADE; |
| 253 |
DROP TABLE IF EXISTS t5 CASCADE; |
| 254 |
DROP TABLE IF EXISTS t1p CASCADE; |
| 255 |
DROP TABLE IF EXISTS customer CASCADE; |
| 256 |
DROP SCHEMA IF EXISTS my_schema_1 CASCADE; |
| 257 |
DROP SCHEMA IF EXISTS my_schema_2 CASCADE; |