From: Donald Fraser <demolish@cwgsy.net>
To: [ADMIN] <pgsql-admin@postgresql.org>
Subject: Bugs with rules on views/tables: permission denied
Date: Mon, 24 Feb 2003 11:58:26 -0000
Message-ID: <006001c2dbfc$0cddcfe0$1664a8c0@DEMOLITION> (raw)
References: <A102805E-3D28-11D7-A5D5-000393BE2C60@queens.unimelb.edu.au>
----- Original Message -----
From: "Tim Burgess" <tim@queens.unimelb.edu.au>
To: <pgsql-bugs@postgresql.org>
Sent: Monday, February 10, 2003 6:51 PM
Subject: [BUGS] 'update' as action of 'insert' rule: permission denied
> 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...
>
In addition to this observation I note that the same bugs apply to views.
My observations are that unless the user has the permissions to execute
the equivalent SQL statement of the rule as though it were a normal
query then if will fail with "permission denied". The only time failure
doesn't occur is thus:
1) you are performing an INSERT on a table/view that you have been
granted INSERT permissions on and the rule is an INSERT.
e.g. create rule test_rule as on insert to table1 do insert into table2...
2) you are performing an UPDATE on a table/view that you have been
granted UPDATE permissions on and the rule is an UPDATE...
e.g. create rule test_rule as on update to table1 do update table2...
These bugs are a real pain as one of the main points of views are to
hide the underlying tables and rules that apply to additional tables.
If the user has to have permissions to such functions and additional
tables it defeats the purpose some what.
Regards
Donald Fraser
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: demolish@cwgsy.net
Subject: Re: Bugs with rules on views/tables: permission denied
In-Reply-To: <006001c2dbfc$0cddcfe0$1664a8c0@DEMOLITION>
References: <A102805E-3D28-11D7-A5D5-000393BE2C60@queens.unimelb.edu.au> <006001c2dbfc$0cddcfe0$1664a8c0@DEMOLITION>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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