pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
'update' as action of 'insert' rule: permission denied
2+ messages / 2 participants
[nested] [flat]

* 'update' as action of 'insert' rule: permission denied
@ 2003-02-10 18:51 Tim Burgess <tim@queens.unimelb.edu.au>
  2003-02-13 21:42 ` Re: 'update' as action of 'insert' rule: permission denied Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: Tim Burgess @ 2003-02-10 18:51 UTC (permalink / raw)
  To: pgsql-bugs@postgresql.org

Gday All,

I'm surprised I can't find any descriptions of this in the archive 
already, since I had imagined it would be a common action, but 
apparently not!

Illustration:

As superuser:

create table1 ( test1 integer );
create table2 ( test2 integer );
create user pleb;
grant insert on table1 to pleb;
create rule test_rule as on insert to table1 do update table2 set test2 
= 2 where test2 = 0;

As user pleb:

insert into table1 values (1);
ERROR:  table1: Permission denied.

However, just to check, if we remove the rule (using DROP RULE) the 
INSERT query works fine.
I also wrote a query using 'insert' as the action instead of 'update' 
and that worked fine too.
I also tried granting the user pleb update and select permission on 
table test2, and that failed in the same way as above.

My impression from the doco is that the permission rules should be 
applied _before_ any rule interpretation is applied, and then again as 
the rule owner for the queries (extra queries only?  this is 
unspecified in the doco) that the rule creates.  Since the rule owner 
in this case is the superuser (correct?), the query should succeed 
whether or not the rule is present.

Note that the query succeeds when run as the superuser...

Cheerio!,

Tim Burgess
Queens' College
University of Melbourne




^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: 'update' as action of 'insert' rule: permission denied
  2003-02-10 18:51 'update' as action of 'insert' rule: permission denied Tim Burgess <tim@queens.unimelb.edu.au>
@ 2003-02-13 21:42 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2003-02-13 21:42 UTC (permalink / raw)
  To: Tim Burgess <tim@queens.unimelb.edu.au>; +Cc: pgsql-bugs@postgresql.org

Tim Burgess <tim@queens.unimelb.edu.au> writes:
> I'm surprised I can't find any descriptions of this in the archive 
> already, since I had imagined it would be a common action, but 
> apparently not!

I'm surprised too.  This bug seems to have escaped notice for quite awhile.
Attached is the patch against 7.3 (it would probably work in 7.2 or
earlier too, but I didn't try it).

			regards, tom lane


inline patch 1: src/backend/rewrite/rewriteHandler.c (+20/-3 lines) download inline-1.patch*** src/backend/rewrite/rewriteHandler.c.orig Thu Jan 16 21:01:16 2003 --- src/backend/rewrite/rewriteHandler.c Thu Feb 13 16:23:18 2003 *************** *** 62,70 **** --- 62,72 ---- { int current_varno, new_varno; + List *main_rtable; int rt_length; Query *sub_action; Query **sub_action_ptr; + List *rt; /* * Make modifiable copies of rule action and qual (what we're passed *************** *** 99,114 **** * Generate expanded rtable consisting of main parsetree's rtable plus * rule action's rtable; this becomes the complete rtable for the rule * action. Some of the entries may be unused after we finish ! * rewriting, but if we tried to clean those out we'd have a much * harder job to adjust RT indexes in the query's Vars. It's OK to * have unused RT entries, since planner will ignore them. * * NOTE: because planner will destructively alter rtable, we must ensure * that rule action's rtable is separate and shares no substructure * with the main rtable. Hence do a deep copy here. */ ! sub_action->rtable = nconc((List *) copyObject(parsetree->rtable), ! sub_action->rtable); /* * Each rule action's jointree should be the main parsetree's jointree --- 101,131 ---- * Generate expanded rtable consisting of main parsetree's rtable plus * rule action's rtable; this becomes the complete rtable for the rule * action. Some of the entries may be unused after we finish ! * rewriting, but if we tried to remove them we'd have a much * harder job to adjust RT indexes in the query's Vars. It's OK to * have unused RT entries, since planner will ignore them. * * NOTE: because planner will destructively alter rtable, we must ensure * that rule action's rtable is separate and shares no substructure * with the main rtable. Hence do a deep copy here. + * + * Also, we must disable write-access checking in all the RT entries + * copied from the main query. This is safe since in fact the rule action + * won't write on them, and it's necessary because the rule action may + * have a different commandType than the main query, causing + * ExecCheckRTEPerms() to make an inappropriate check. The read-access + * checks can be left enabled, although they're probably redundant. */ ! main_rtable = (List *) copyObject(parsetree->rtable); ! ! foreach(rt, main_rtable) ! { ! RangeTblEntry *rte = (RangeTblEntry *) lfirst(rt); ! ! rte->checkForWrite = false; ! } ! ! sub_action->rtable = nconc(main_rtable, sub_action->rtable); /* * Each rule action's jointree should be the main parsetree's jointree
^ permalink raw reply [nested|flat] 2+ messages in thread


end of thread, other threads:[~2003-02-13 21:42 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-02-10 18:51 'update' as action of 'insert' rule: permission denied Tim Burgess <tim@queens.unimelb.edu.au>
2003-02-13 21:42 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox