CREATETABLE rls_test_permissive (
username name,
supervisor name,
data integer
);
-- initial test data INSERTINTO rls_test_permissive VALUES ('regress_r1','regress_s1',4); INSERTINTO rls_test_permissive VALUES ('regress_r2','regress_s2',5); INSERTINTO rls_test_permissive VALUES ('regress_r3','regress_s3',6);
CREATETABLE rls_test_restrictive (
username name,
supervisor name,
data integer
);
-- At least one permissive policy must exist, otherwise -- the default deny policy will be applied. For -- testing the only-restrictive-policies from the hook, -- create a simple 'allow all' policy. CREATE POLICY p1 ON rls_test_restrictive USING (true);
-- initial test data INSERTINTO rls_test_restrictive VALUES ('regress_r1','regress_s1',1); INSERTINTO rls_test_restrictive VALUES ('regress_r2','regress_s2',2); INSERTINTO rls_test_restrictive VALUES ('regress_r3','regress_s3',3);
CREATETABLE rls_test_both (
username name,
supervisor name,
data integer
);
-- initial test data INSERTINTO rls_test_both VALUES ('regress_r1','regress_s1',7); INSERTINTO rls_test_both VALUES ('regress_r2','regress_s2',8); INSERTINTO rls_test_both VALUES ('regress_r3','regress_s3',9);
GRANTSELECT,INSERTON rls_test_permissive TO regress_r1; GRANTSELECT,INSERTON rls_test_restrictive TO regress_r1; GRANTSELECT,INSERTON rls_test_both TO regress_r1;
GRANTSELECT,INSERTON rls_test_permissive TO regress_s1; GRANTSELECT,INSERTON rls_test_restrictive TO regress_s1; GRANTSELECT,INSERTON rls_test_both TO regress_s1;
SET ROLE regress_r1;
-- With only the hook's policies, permissive -- hook's policy is current_user = username EXPLAIN (costs off) SELECT * FROM rls_test_permissive;
-- With only the hook's policies, both -- permissive hook's policy is current_user = username -- restrictive hook's policy is current_user = superuser -- combined with AND, results in nothing being allowed EXPLAIN (costs off) SELECT * FROM rls_test_both;
-- Create "internal" policies, to check that the policies from -- the hooks are combined correctly. CREATE POLICY p1 ON rls_test_permissive USING (data % 2 = 0);
-- Remove the original allow-all policy DROP POLICY p1 ON rls_test_restrictive; CREATE POLICY p1 ON rls_test_restrictive USING (data % 2 = 0);
CREATE POLICY p1 ON rls_test_both USING (data % 2 = 0);
SET ROLE regress_r1;
-- With both internal and hook policies, permissive EXPLAIN (costs off) SELECT * FROM rls_test_permissive;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.