diff options
author | Stephen Frost <sfrost@snowman.net> | 2014-09-26 12:46:26 -0400 |
---|---|---|
committer | Stephen Frost <sfrost@snowman.net> | 2014-09-26 12:46:26 -0400 |
commit | ff27fcfa0affe16405e801ed55fed10e7bc75216 (patch) | |
tree | c5b2ae84766167640cc427217249839695da1a71 /src | |
parent | 07d46a8963ebbf69ef6e6853bb8a45623612dd34 (diff) | |
download | postgresql-ff27fcfa0affe16405e801ed55fed10e7bc75216.tar.gz postgresql-ff27fcfa0affe16405e801ed55fed10e7bc75216.zip |
Fix relcache for policies, and doc updates
Andres pointed out that there was an extra ';' in equalPolicies, which
made me realize that my prior testing with CLOBBER_CACHE_ALWAYS was
insufficient (it didn't always catch the issue, just most of the time).
Thanks to that, a different issue was discovered, specifically in
equalRSDescs. This change corrects eqaulRSDescs to return 'true' once
all policies have been confirmed logically identical. After stepping
through both functions to ensure correct behavior, I ran this for
about 12 hours of CLOBBER_CACHE_ALWAYS runs of the regression tests
with no failures.
In addition, correct a few typos in the documentation which were pointed
out by Thom Brown (thanks!) and improve the policy documentation further
by adding a flushed out usage example based on a unix passwd file.
Lastly, clean up a few comments in the regression tests and pg_dump.h.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/utils/cache/relcache.c | 4 | ||||
-rw-r--r-- | src/bin/pg_dump/pg_dump.h | 2 | ||||
-rw-r--r-- | src/test/regress/expected/rowsecurity.out | 10 | ||||
-rw-r--r-- | src/test/regress/sql/rowsecurity.sql | 10 |
4 files changed, 13 insertions, 13 deletions
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index ec483a0e8e6..c8137798f24 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -868,7 +868,7 @@ equalPolicy(RowSecurityPolicy *policy1, RowSecurityPolicy *policy2) return false; if (policy1->cmd != policy2->cmd) return false; - if (policy1->hassublinks != policy2->hassublinks); + if (policy1->hassublinks != policy2->hassublinks) return false; if (strcmp(policy1->policy_name,policy2->policy_name) != 0) return false; @@ -926,7 +926,7 @@ equalRSDesc(RowSecurityDesc *rsdesc1, RowSecurityDesc *rsdesc2) return false; } - return false; + return true; } /* diff --git a/src/bin/pg_dump/pg_dump.h b/src/bin/pg_dump/pg_dump.h index 646a2077a61..fd1184e8dbb 100644 --- a/src/bin/pg_dump/pg_dump.h +++ b/src/bin/pg_dump/pg_dump.h @@ -246,7 +246,7 @@ typedef struct _tableInfo bool hasindex; /* does it have any indexes? */ bool hasrules; /* does it have any rules? */ bool hastriggers; /* does it have any triggers? */ - bool rowsec; /* does it have any row-security policy? */ + bool rowsec; /* is row-security enabled? */ bool hasoids; /* does it have OIDs? */ uint32 frozenxid; /* for restore frozen xid */ uint32 minmxid; /* for restore min multi xid */ diff --git a/src/test/regress/expected/rowsecurity.out b/src/test/regress/expected/rowsecurity.out index 007afc606b7..3d793e2ff57 100644 --- a/src/test/regress/expected/rowsecurity.out +++ b/src/test/regress/expected/rowsecurity.out @@ -69,7 +69,7 @@ INSERT INTO document VALUES ( 7, 33, 2, 'rls_regress_user2', 'great technology book'), ( 8, 44, 1, 'rls_regress_user2', 'great manga'); ALTER TABLE document ENABLE ROW LEVEL SECURITY; --- user's security level must be higher that or equal to document's +-- user's security level must be higher than or equal to document's CREATE POLICY p1 ON document USING (dlevel <= (SELECT seclv FROM uaccount WHERE pguser = current_user)); -- viewpoint from rls_regress_user1 @@ -280,7 +280,7 @@ SELECT * FROM document d FULL OUTER JOIN category c on d.cid = c.cid; DELETE FROM category WHERE cid = 33; -- fails with FK violation ERROR: update or delete on table "category" violates foreign key constraint "document_cid_fkey" on table "document" DETAIL: Key (cid)=(33) is still referenced from table "document". --- cannot insert FK referencing invisible PK +-- can insert FK referencing invisible PK SET SESSION AUTHORIZATION rls_regress_user2; SELECT * FROM document d FULL OUTER JOIN category c on d.cid = c.cid; did | cid | dlevel | dauthor | dtitle | cid | cname @@ -301,7 +301,7 @@ SELECT * FROM document WHERE did = 8; -- and confirm we can't see it -----+-----+--------+---------+-------- (0 rows) --- database superuser cannot bypass RLS policy when enabled +-- database superuser does bypass RLS policy when enabled RESET SESSION AUTHORIZATION; SET row_security TO ON; SELECT * FROM document; @@ -327,7 +327,7 @@ SELECT * FROM category; 44 | manga (4 rows) --- database superuser cannot bypass RLS policy when FORCE enabled. +-- database superuser does not bypass RLS policy when FORCE enabled. RESET SESSION AUTHORIZATION; SET row_security TO FORCE; SELECT * FROM document; @@ -340,7 +340,7 @@ SELECT * FROM category; -----+------- (0 rows) --- database superuser can bypass RLS policy when disabled +-- database superuser does bypass RLS policy when disabled RESET SESSION AUTHORIZATION; SET row_security TO OFF; SELECT * FROM document; diff --git a/src/test/regress/sql/rowsecurity.sql b/src/test/regress/sql/rowsecurity.sql index 5409bb055ad..b7969a8dabf 100644 --- a/src/test/regress/sql/rowsecurity.sql +++ b/src/test/regress/sql/rowsecurity.sql @@ -84,7 +84,7 @@ INSERT INTO document VALUES ALTER TABLE document ENABLE ROW LEVEL SECURITY; --- user's security level must be higher that or equal to document's +-- user's security level must be higher than or equal to document's CREATE POLICY p1 ON document USING (dlevel <= (SELECT seclv FROM uaccount WHERE pguser = current_user)); @@ -136,7 +136,7 @@ SET SESSION AUTHORIZATION rls_regress_user1; SELECT * FROM document d FULL OUTER JOIN category c on d.cid = c.cid; DELETE FROM category WHERE cid = 33; -- fails with FK violation --- cannot insert FK referencing invisible PK +-- can insert FK referencing invisible PK SET SESSION AUTHORIZATION rls_regress_user2; SELECT * FROM document d FULL OUTER JOIN category c on d.cid = c.cid; INSERT INTO document VALUES (10, 33, 1, current_user, 'hoge'); @@ -146,19 +146,19 @@ SET SESSION AUTHORIZATION rls_regress_user1; INSERT INTO document VALUES (8, 44, 1, 'rls_regress_user1', 'my third manga'); -- Must fail with unique violation, revealing presence of did we can't see SELECT * FROM document WHERE did = 8; -- and confirm we can't see it --- database superuser cannot bypass RLS policy when enabled +-- database superuser does bypass RLS policy when enabled RESET SESSION AUTHORIZATION; SET row_security TO ON; SELECT * FROM document; SELECT * FROM category; --- database superuser cannot bypass RLS policy when FORCE enabled. +-- database superuser does not bypass RLS policy when FORCE enabled. RESET SESSION AUTHORIZATION; SET row_security TO FORCE; SELECT * FROM document; SELECT * FROM category; --- database superuser can bypass RLS policy when disabled +-- database superuser does bypass RLS policy when disabled RESET SESSION AUTHORIZATION; SET row_security TO OFF; SELECT * FROM document; |