X-Original-To: pgsql-bugs@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 94418475A80 for ; Mon, 24 Feb 2003 11:23:14 -0500 (EST) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with SMTP id 97168-05 for ; Mon, 24 Feb 2003 11:23:03 -0500 (EST) Received: from gsy_sbs_1.cisx.com (unknown [213.133.202.58]) by postgresql.org (Postfix) with ESMTP id 53903475A8D for ; Mon, 24 Feb 2003 11:19:26 -0500 (EST) Received: from DEMOLITION ([192.168.100.22]) by gsy_sbs_1.cisx.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2650.21) id FR9XXZ2Y; Mon, 24 Feb 2003 16:12:11 -0000 Message-ID: <00cb01c2dc21$12eae290$1664a8c0@DEMOLITION> From: "Donald Fraser" To: "[BUGS]" References: <006001c2dbfc$0cddcfe0$1664a8c0@DEMOLITION> <3150.1046097764@sss.pgh.pa.us> Subject: Re: Bugs with rules on views/tables: permission denied Date: Mon, 24 Feb 2003 16:23:27 -0000 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_00C8_01C2DC21.0FA888D0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 X-Virus-Scanned: by amavisd-new X-Archive-Number: 200302/124 X-Sequence-Number: 5540 This is a multi-part message in MIME format. ------=_NextPart_000_00C8_01C2DC21.0FA888D0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable ----- Original Message -----=20 From: "Tom Lane" To: "Donald Fraser" Cc: "[ADMIN]" Sent: Monday, February 24, 2003 2:42 PM Subject: Re: [ADMIN] Bugs with rules on views/tables: permission denied=20 > "Donald Fraser" writes: > > In addition to this observation I note that the same bugs apply to view= s. >=20 > 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.) >=20 > 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 interpret= ed=20 rules on views as follows: 1) Permissions on views grant the said USER the ability to perform the gran= ted=20 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 in= sert. CREATE USER chkrule WITH PASSWORD '' NOCREATEDB NOCREATEUSER; CREATE OR REPLACE FUNCTION test_func(int4) RETURNS int4 AS '=20 DECLARE=20 id ALIAS FOR $1;=20 ndosomething int4;=20 BEGIN=20 ndosomething :=3D id;=20 RETURN ndosomething;=20 END; ' LANGUAGE 'plpgsql' VOLATILE SECURITY DEFINER;=20 REVOKE ALL ON FUNCTION test_func(int4) FROM PUBLIC;=20 CREATE TABLE public.tbl_test1 (id int4 NOT NULL, s_text text NOT NULL, PRIM= ARY KEY (id)) WITHOUT OIDS;=20 REVOKE ALL ON TABLE public.tbl_test1 FROM PUBLIC;=20 CREATE TABLE public.tbl_test2 (id int4 NOT NULL, s_text text NOT NULL, PRIM= ARY KEY (id)) WITHOUT OIDS;=20 REVOKE ALL ON TABLE public.tbl_test1 FROM PUBLIC;=20 INSERT INTO tbl_test2(id, s_text) VALUES('1', 'testtext'); CREATE VIEW vu_tbl_test AS SELECT id, s_text FROM tbl_test1;=20 REVOKE ALL ON TABLE vu_tbl_test FROM PUBLIC;=20 GRANT SELECT, INSERT ON TABLE vu_tbl_test TO chkrule;=20 CREATE RULE rul_vu_tbl_test_01 AS ON INSERT TO vu_tbl_test DO (UPDATE tbl_t= est2 SET s_text =3D NEW.s_text WHERE id =3D NEW.id); CREATE RULE rul_vu_tbl_test_02 AS ON INSERT TO vu_tbl_test DO INSTEAD (INSE= RT INTO tbl_test1 (id, s_text) VALUES(test_func(NEW.id), NEW.s_text)); Scenario 1) As USER chkrule do: Bugs=3D> 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=3D> 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 the= n the error at Scenario 1 goes away. Regards Donald Fraser. ------=_NextPart_000_00C8_01C2DC21.0FA888D0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
=
----- Original= Message=20 -----
From: "Tom Lane" <tgl@sss.pgh.pa.us>
To: "Donald Fraser"= =20 <demolish@cwgsy.net>
Cc: "[ADMIN]"=20 <pgsql-admin@postgresql.org>
Sent: Monday, February 24, 2003 2:42= =20 PM
Subject: Re: [ADMIN] Bugs with rules on views/tables: permission deni= ed=20


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

Sorry I didn't see any follow up emails on that one...
May be I haven't understood the documentat= ion=20 correctly either. I interpreted
rules on views as=20 follows:
 
1) Permissions on views grant the said&nbs= p;USER=20 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=20 creator's permission access level.
Here is a simple example that fails with v= iews,=20 both in an update and an insert.

CREATE USER chkrule WITH  PASS= WORD=20 '' NOCREATEDB NOCREATEUSER;

CREATE
OR REPLACE FUNCTION test_func(int4) RETURNS int4 AS=20 '
DECLARE
    id ALIAS FOR $1;
    ndosomething int4;
BEGIN
    ndosomething :=3D id;
    RETURN ndosomething;
END; ' LANGUAGE 'plpgsql' = VOLATILE=20 SECURITY DEFINER;
REVOKE ALL ON=20 FUNCTION test_func(int4) FROM PUBLIC;
 
CREATE TABLE=20 public.tbl_test1 (id int4 NOT NULL, s_text text NOT NULL, PRIMARY KEY (id))= =20 WITHOUT OIDS;
REVOKE ALL ON=20 TABLE public.tbl_test1 <= FONT=20 size=3D2>FROM PUBLIC;
 
CREATE TABLE=20 public.tbl_test2 (id int4 NOT N= ULL,=20 s_text text NOT NULL, PRIMARY KEY (id)) WITHOUT OIDS;
REVOKE ALL ON=20 TABLE public.tbl_test1 <= FONT=20 size=3D2>FROM PUBLIC;
 
INSERT INTO tbl_test2(id, = s_text)=20 VALUES('1', 'testtext');
 
CREATE VIEW vu_tbl_test AS SELECT id,=20 s_text FROM tbl_test1;=20
REVOKE ALL ON=20 TABLE vu_tbl_test FROM PUBLIC;
GRANT SELECT, INSERT ON TABLE vu_tbl_test TO chkrule;
<= FONT=20 size=3D2>
 
CREATE RULE=20 rul_vu_tbl_test_01 AS ON INSERT TO=20 vu_tbl_test DO (UPDATE tbl_test= 2 SET=20 s_text =3D NEW.s_text WHERE id = =3D=20 NEW.id);
CREATE RULE=20 rul_vu_tbl_test_02 AS ON INSERT TO=20 vu_tbl_test DO INSTEAD (INSERT= =20 INTO tbl_test1 (id, s_text)=20 VALUES(test_func(NEW.id), NEW.s_text));
 
Scenario 1)
As USER chkrule do:
Bugs=3D> INSERT INTO= =20 vu_tbl_test (id, s_text) VALUES('1','sometext');
ERROR:  vu_tbl_test: permission=20 denied
Scenario 2)
Now drop rule 1 as USER postgres
DROP RULE=20 rul_vu_tbl_test_01 ON=20 vu_tbl_test;
 
As USER chkrule do:
Bugs=3D> = INSERT INTO=20 vu_tbl_test (id, s_text) VALUES('1','sometext');
ERROR:  test_func:= =20 permission denied
 
If you give the USER chkrule UPDATE permis= sions on=20 the view vu_tbl_test then the error at Scenario 1 goes away.

Regards
Donald Fraser.
------=_NextPart_000_00C8_01C2DC21.0FA888D0--