pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Donald Fraser <demolish@cwgsy.net>
To: [BUGS] <pgsql-bugs@postgresql.org>
Subject: Re: Bugs with rules on views/tables: permission denied
Date: Mon, 24 Feb 2003 16:23:27 -0000
Message-ID: <00cb01c2dc21$12eae290$1664a8c0@DEMOLITION> (raw)
References: <A102805E-3D28-11D7-A5D5-000393BE2C60@queens.unimelb.edu.au>
	<006001c2dbfc$0cddcfe0$1664a8c0@DEMOLITION>
	<3150.1046097764@sss.pgh.pa.us>


----- Original Message ----- 
From: "Tom Lane" <tgl@sss.pgh.pa.us>
To: "Donald Fraser" <demolish@cwgsy.net>
Cc: "[ADMIN]" <pgsql-admin@postgresql.org>
Sent: Monday, February 24, 2003 2:42 PM
Subject: Re: [ADMIN] Bugs with rules on views/tables: permission denied 


> "Donald Fraser" <demolish@cwgsy.net> writes:
> > In addition to this observation I note that the same bugs apply to views.
> 
> What bugs?  The original complaint was shown to be user error.  (If you
> try to duplicate the problem using the example quoted in your mail, it
> works fine.)
> 
> regards, tom lane

Sorry I didn't see any follow up emails on that one...
May be I haven't understood the documentation correctly either. I interpreted 
rules on views as follows:

1) Permissions on views grant the said USER the ability to perform the granted 
action on the view, for example SELECT, INSERT or UPDATE.
2) The rules of the view always run at the rule creator's permission access level.

Here is a simple example that fails with views, both in an update and an insert.

CREATE USER chkrule WITH  PASSWORD '' NOCREATEDB NOCREATEUSER;

CREATE OR REPLACE FUNCTION test_func(int4) RETURNS int4 AS ' 
DECLARE 
    id ALIAS FOR $1; 
    ndosomething int4; 
BEGIN 
    ndosomething := id; 
    RETURN ndosomething; 
END; ' LANGUAGE 'plpgsql' VOLATILE SECURITY DEFINER; 
REVOKE ALL ON FUNCTION test_func(int4) FROM PUBLIC; 

CREATE TABLE public.tbl_test1 (id int4 NOT NULL, s_text text NOT NULL, PRIMARY KEY (id)) WITHOUT OIDS; 
REVOKE ALL ON TABLE public.tbl_test1 FROM PUBLIC; 

CREATE TABLE public.tbl_test2 (id int4 NOT NULL, s_text text NOT NULL, PRIMARY KEY (id)) WITHOUT OIDS; 
REVOKE ALL ON TABLE public.tbl_test1 FROM PUBLIC; 

INSERT INTO tbl_test2(id, s_text) VALUES('1', 'testtext');

CREATE VIEW vu_tbl_test AS SELECT id, s_text FROM tbl_test1; 
REVOKE ALL ON TABLE vu_tbl_test FROM PUBLIC; 
GRANT SELECT, INSERT ON TABLE vu_tbl_test TO chkrule; 

CREATE RULE rul_vu_tbl_test_01 AS ON INSERT TO vu_tbl_test DO (UPDATE tbl_test2 SET s_text = NEW.s_text WHERE id = NEW.id);
CREATE RULE rul_vu_tbl_test_02 AS ON INSERT TO vu_tbl_test DO INSTEAD (INSERT INTO tbl_test1 (id, s_text) VALUES(test_func(NEW.id), NEW.s_text));

Scenario 1)
As USER chkrule do:
Bugs=> INSERT INTO vu_tbl_test (id, s_text) VALUES('1','sometext');
ERROR:  vu_tbl_test: permission denied

Scenario 2)
Now drop rule 1 as USER postgres
DROP RULE rul_vu_tbl_test_01 ON vu_tbl_test;

As USER chkrule do:
Bugs=> INSERT INTO vu_tbl_test (id, s_text) VALUES('1','sometext');
ERROR:  test_func: permission denied

If you give the USER chkrule UPDATE permissions on the view vu_tbl_test then the error at Scenario 1 goes away.

Regards
Donald Fraser.

view thread (5+ messages)  latest in thread

Message-ID: <00cb01c2dc21$12eae290$1664a8c0@DEMOLITION>
Permalink:  ../00cb01c2dc21$12eae290$1664a8c0@DEMOLITION/
Also on:    postgresql.org/message-id/00cb01c2dc21$12eae290$1664a8c0@DEMOLITION

 · 

reply

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, pgsql-bugs@postgresql.org
  Subject: Re: Bugs with rules on views/tables: permission denied
  In-Reply-To: <00cb01c2dc21$12eae290$1664a8c0@DEMOLITION>
  References: <A102805E-3D28-11D7-A5D5-000393BE2C60@queens.unimelb.edu.au> <006001c2dbfc$0cddcfe0$1664a8c0@DEMOLITION> <3150.1046097764@sss.pgh.pa.us> <00cb01c2dc21$12eae290$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