Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Frost2015-08-03 19:32:49 +0000
committerStephen Frost2015-08-03 19:32:49 +0000
commitdee0200f0276c0f9da930a2c926f90f5615f2d64 (patch)
treeeae2bb8d8694ae6bd2efd6faaa37d035cb79fd1e /src/backend/rewrite/rowsecurity.c
parentecc2d16bc97d160d3b4beecfc46676bbaaf157a5 (diff)
RLS: Keep deny policy when only restrictive exist
Only remove the default deny policy when a permissive policy exists (either from the hook or defined by the user). If only restrictive policies exist then no rows will be visible, as restrictive policies shouldn't make rows visible. To address this requirement, a single "USING (true)" permissive policy can be created. Update the test_rls_hooks regression tests to create the necessary "USING (true)" permissive policy. Back-patch to 9.5 where RLS was added. Per discussion with Dean.
Diffstat (limited to 'src/backend/rewrite/rowsecurity.c')
-rw-r--r--src/backend/rewrite/rowsecurity.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/backend/rewrite/rowsecurity.c b/src/backend/rewrite/rowsecurity.c
index 562dbc90e9f..5a81db3618c 100644
--- a/src/backend/rewrite/rowsecurity.c
+++ b/src/backend/rewrite/rowsecurity.c
@@ -225,12 +225,18 @@ get_row_security_policies(Query *root, CmdType commandType, RangeTblEntry *rte,
}
/*
- * If the only built-in policy is the default-deny one, and hook policies
- * exist, then use the hook policies only and do not apply the
+ * If the only built-in policy is the default-deny one, and permissive hook
+ * policies exist, then use the hook policies only and do not apply the
* default-deny policy. Otherwise, we will apply both sets below.
+ *
+ * Note that we do not remove the defaultDeny policy if only *restrictive*
+ * policies exist as restrictive policies should only ever be reducing what
+ * is visible. Therefore, at least one permissive policy must exist which
+ * allows records to be seen before restrictive policies can remove rows
+ * from that set. A single "true" policy can be created to address this
+ * requirement, if necessary.
*/
- if (defaultDeny &&
- (hook_policies_restrictive != NIL || hook_policies_permissive != NIL))
+ if (defaultDeny && hook_policies_permissive != NIL)
{
rowsec_expr = NULL;
rowsec_with_check_expr = NULL;