aboutsummaryrefslogtreecommitdiff
path: root/src/backend/rewrite/rowsecurity.c
diff options
context:
space:
mode:
authorDean Rasheed <dean.a.rasheed@gmail.com>2019-04-02 08:19:09 +0100
committerDean Rasheed <dean.a.rasheed@gmail.com>2019-04-02 08:19:09 +0100
commitdb4bc99948bf746c7035b49cc581eb1c44a30788 (patch)
treebfbe016c86c7c5f7bfdc8f80aab37682780d3a10 /src/backend/rewrite/rowsecurity.c
parent327399412d035a3951f48d74356ff1449b9b7e91 (diff)
downloadpostgresql-db4bc99948bf746c7035b49cc581eb1c44a30788.tar.gz
postgresql-db4bc99948bf746c7035b49cc581eb1c44a30788.zip
Perform RLS subquery checks as the right user when going via a view.
When accessing a table with RLS via a view, the RLS checks are performed as the view owner. However, the code neglected to propagate that to any subqueries in the RLS checks. Fix that by calling setRuleCheckAsUser() for all RLS policy quals and withCheckOption checks for RTEs with RLS. Back-patch to 9.5 where RLS was added. Per bug #15708 from daurnimator. Discussion: https://postgr.es/m/15708-d65cab2ce9b1717a@postgresql.org
Diffstat (limited to 'src/backend/rewrite/rowsecurity.c')
-rw-r--r--src/backend/rewrite/rowsecurity.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/backend/rewrite/rowsecurity.c b/src/backend/rewrite/rowsecurity.c
index 5bd33f7ba41..72979b354fd 100644
--- a/src/backend/rewrite/rowsecurity.c
+++ b/src/backend/rewrite/rowsecurity.c
@@ -47,6 +47,7 @@
#include "nodes/pg_list.h"
#include "nodes/plannodes.h"
#include "parser/parsetree.h"
+#include "rewrite/rewriteDefine.h"
#include "rewrite/rewriteHandler.h"
#include "rewrite/rewriteManip.h"
#include "rewrite/rowsecurity.h"
@@ -382,6 +383,13 @@ get_row_security_policies(Query *root, RangeTblEntry *rte, int rt_index,
heap_close(rel, NoLock);
/*
+ * Copy checkAsUser to the row security quals and WithCheckOption checks,
+ * in case they contain any subqueries referring to other relations.
+ */
+ setRuleCheckAsUser((Node *) *securityQuals, rte->checkAsUser);
+ setRuleCheckAsUser((Node *) *withCheckOptions, rte->checkAsUser);
+
+ /*
* Mark this query as having row security, so plancache can invalidate it
* when necessary (eg: role changes)
*/