X-Original-To: pgsql-bugs@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 55F1047621F for ; Mon, 24 Feb 2003 20:24:54 -0500 (EST) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with SMTP id 25133-03 for ; Mon, 24 Feb 2003 20:24:25 -0500 (EST) Received: from gsy_sbs_1.cisx.com (unknown [213.133.202.58]) by postgresql.org (Postfix) with ESMTP id 3002D476371 for ; Mon, 24 Feb 2003 17:34:31 -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 FR9XXZ29; Mon, 24 Feb 2003 22:27:13 -0000 Message-ID: <00f501c2dc55$76ddbf50$1664a8c0@DEMOLITION> From: "Donald Fraser" To: "[BUGS]" References: <006001c2dbfc$0cddcfe0$1664a8c0@DEMOLITION> <3150.1046097764@sss.pgh.pa.us> <00cb01c2dc21$12eae290$1664a8c0@DEMOLITION> <5303.1046118557@sss.pgh.pa.us> Subject: Re: Bugs with rules on views/tables: permission denied Date: Mon, 24 Feb 2003 22:38:29 -0000 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_00F2_01C2DC55.73C89010" 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/126 X-Sequence-Number: 5542 This is a multi-part message in MIME format. ------=_NextPart_000_00F2_01C2DC55.73C89010 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable ----- Original Message -----=20 From: "Tom Lane" To: "Donald Fraser" Cc: "[BUGS]" Sent: Monday, February 24, 2003 8:29 PM Subject: Re: [BUGS] Bugs with rules on views/tables: permission denied=20 > "Donald Fraser" writes: > > As USER chkrule do: > > Bugs=3D3D> INSERT INTO vu_tbl_test (id, s_text) VALUES('1','sometext'); > > ERROR: vu_tbl_test: permission denied >=20 > What I get is=20 > ERROR: test_func: permission denied This is really weird... starting to pull my hair out! I cut and paste everything straight out of my email=20 and the first error I got was definitely: ERROR: vu_tbl_test: permission denied I noticed that I had made a typo on line 17 of SQL: REVOKE ALL ON TABLE public.tbl_test1 FROM PUBLIC;=20 should have read: REVOKE ALL ON TABLE public.tbl_test2 FROM PUBLIC;=20 So I changed this and tried again - this time I got ERROR: tbl_test2: permission denied It doesn't matter what I do now, I tried putting line 17 back how it was (shouldn't have mattered anyway), vacuuming, restarting the server and the first error message I get now=20 is always: ERROR: tbl_test2: permission denied I cannot get the original message: ERROR: vu_tbl_test: permission denied. Not sure what is going on with that one? I'm running PostgreSQL 7.3.1 on i686-pc-linux-gnu,=20 compiled by GCC 2.96 I take it you tested yours on at least 7.3.2 or greater?=20 Were there some changes between these versions that could effect this scenario? I didn't see any in the readme... > and the needed fix is to grant execute privilege on the function to the > calling user. In this case I have to draw an annalogy between functions and tables, albeit that they are completely different.=20 Functions can perform more sophisticated logic on data input to=20 tables that the user wouldn't normally have access to. Just like you=20 wouldn't give them access to those tables in the first place. Hence if you give them access to the function, you may as well give them access to the tables which is not the goal of views. It's probably a debatable point, of which I can see how Postgres has arrived at the current point of logic given it's past history with function permissions. At the moment to get around this I only allow access to tables through views (which is generally good database design) so when it comes to functions that modify tables, it doesn't matter too much because if a user calls a function directly they=20 still want have the permissions. They can only be given such persmission via views. It just seems a bit untidy that I can't stop a user calling the=20 functions directly in the first place. I'm sure one day there will be the scenario where I will want a function to do something other than just table modifications and then I will be stuck with the "how do I stop them calling it directly in an uncontrolled manner". >=20 > > If you give the USER chkrule UPDATE permissions on the view vu_tbl_test= the=3D > > n the error at Scenario 1 goes away. >=20 > Not for me. >=20 > The reason it acts this way is that rule permissions apply to tables > mentioned in the rule, not to functions. This is at least partly for > historical reasons: functions didn't have permissions to check, back > when the rule system was designed. But I'm not sure that it's wrong. > In your example, the end user is controlling the arguments given to > test_func. If the rule allowed him to call test_func without having > permission to do so, there'd be the potential for security breaches. In my opinion this is no more of a security breach than allowing the=20 modification of tables, via rules, that the user doesn't normally have=20 access to. The rule creator is granting them that permission by=20 putting it in the rule. Regards Donald Fraser. ------=_NextPart_000_00F2_01C2DC55.73C89010 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
 
----- Original Message -----
From: "Tom Lane" <tgl@sss.pgh.pa.us>
To: "Donald Fraser" <demolish@cwgsy.net>
Cc: "[BUGS]" <pgsql-bugs@postgresql.org>
Sent: Monday, February 24, 2003 8:29=20 PM
Subject: Re: [BUGS] Bugs with rules on=20 views/tables: permission denied

> "Donald Fraser" <demolish@cwgsy.net> writ= es:
>=20 > As USER chkrule do:
> > Bugs=3D3D> INSERT INTO vu_tbl_test= (id,=20 s_text) VALUES('1','sometext');
> > ERROR:  vu_tbl_test:=20 permission denied
>
> What I get is
> ERROR: =20 test_func: permission denied
 
This is really weird... starting to pull m= y hair=20 out!
I cut and paste everything straight out of= my email=20
and the= first error=20 I got was definitely:
ERROR:  vu_tbl_test: permission=20 denied
 
I noticed that I had made a typo on line 1= 7 of=20 SQL:
REVOKE ALL ON TABLE public.tbl_test1 FROM = PUBLIC;=20
should have read:
REVOKE ALL ON TABLE public.tbl_test2 FROM = PUBLIC;=20
 
So I changed this and tried again - this t= ime I=20 got
ERROR:  tbl_test2: permission=20 denied
 
It doesn't matter what I do now, = ;I tried=20 putting line 17 back
how it was (shouldn't have mattered anyway), vacuuming,
restarting the server and the first= =20 error message I get now
is always:
ERROR:  tbl_test2: permission=20 denied
 
I cannot get the original message:<= /DIV>
ERROR:  vu_tbl_test: permission=20 denied.
 
Not sure what is going on with that= =20 one?
 
I'm running PostgreSQL 7.3.1 on i686-pc-li= nux-gnu,=20
compiled by GCC 2.96
I take it you tested yours on at least 7.3= .2 or=20 greater?
Were there some=20 changes between these versions that could effect
this scenario? I didn't see any in the=20 readme...
=
> and the needed fix is = to grant=20 execute privilege on the function to the
> calling user.
 
In this case I have to draw an annalo= gy=20 between functions and tables,
albeit that they are completely different.= =20
Functions can perform more sophisticated l= ogic on=20 data input to
tables that the user wouldn't normally hav= e access=20 to. Just like you
wouldn't give them access to those tables = in the=20 first place.
Hence if you give them access to the funct= ion, you=20 may as well give
them access to the tables which is not the= goal of=20 views.
It's probably a debatable point, of w= hich I=20 can see how Postgres
has arrived at the current point of logic = given=20 it's past history with
function permissions.
 
At the moment to get around this I only al= low=20 access to tables
through views (which is generally good dat= abase=20 design) so
when it comes to functions that modify tab= les, it=20 doesn't matter
too much because if a user calls=  a=20 function directly they
still want have the permissions. They can = only be=20 given such
persmission via views.
 
It just seems a bit untidy that I can't st= op a=20 user calling the
functions directly in the first place.
I'm sure one day there will be the scenari= o where I=20 will want
a function to do something other than just= table=20 modifications
and then I will be stuck with the "how do = I stop=20 them calling
it directly in an uncontrolled=20 manner".
 
>
> > If you give the USER ch= krule=20 UPDATE permissions on the view vu_tbl_test the=3D
> > n the error = at=20 Scenario 1 goes away.
>
> Not for me.
>
> The rea= son=20 it acts this way is that rule permissions apply to tables
> mentioned= in=20 the rule, not to functions.  This is at least partly for
> histo= rical=20 reasons: functions didn't have permissions to check, back
> when the = rule=20 system was designed.  But I'm not sure that it's wrong.
> In you= r=20 example, the end user is controlling the arguments given to
>=20 test_func.  If the rule allowed him to call test_func without=20 having
> permission to do so, there'd be the potential for security= =20 breaches.
 
In my opinion this is no more of a securit= y breach=20 than allowing the
modification of tables, via rules, that the user doesn't normally have
access to. The rule=20 creator is granting them that permission by
putting it in the rule.
 
Regards
Donald Fraser.
------=_NextPart_000_00F2_01C2DC55.73C89010--