Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id CF1D7632674 for ; Sat, 19 Jun 2010 04:41:12 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 37270-03 for ; Sat, 19 Jun 2010 07:41:04 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sd-17937.dedibox.fr (sd-17937.dedibox.fr [88.191.100.74]) by mail.postgresql.org (Postfix) with ESMTP id 51F806324C9 for ; Sat, 19 Jun 2010 04:41:04 -0300 (ADT) Received: from [192.168.10.3] (ASte-Genev-Bois-153-1-68-252.w86-198.abo.wanadoo.fr [86.198.38.252]) by sd-17937.dedibox.fr (Postfix) with ESMTPA id 760763B8F5; Sat, 19 Jun 2010 09:41:03 +0200 (CEST) Message-ID: <4C1C748E.2090009@lelarge.info> Date: Sat, 19 Jun 2010 09:41:02 +0200 From: Guillaume Lelarge User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100423 Thunderbird/3.0.4 MIME-Version: 1.0 To: John Rouillard CC: pgsql-admin@postgresql.org Subject: Re: Ideas for a read only user access on partitioned tables. References: <20100618230913.GH703@renesys.com> In-Reply-To: <20100618230913.GH703@renesys.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201006/130 X-Sequence-Number: 34908 Hi, Le 19/06/2010 01:09, John Rouillard a écrit : > [...] > We are using postgres 8.4.4 as distributed in centos 5.5. > > We have a database that has a number of partitioned tables > (http://www.postgresql.org/docs/8.4/interactive/ddl-partitioning.html). > > We would like to add a read only user who is allowed to access all the > tables in the database. I had hoped that granting select on the master > table would also allow selects on the child tables. But that doesn't > seem to work. > > I also tried: > > grant select on table database.% to readonly_user; > > I also tried with database.*, but those generated a syntax error at > the wildcard. Also my guess is that it would have allowed it for all > existing tables and not for the new ones as they are created. > This syntax is not supported. See http://www.postgresql.org/docs/8.4/interactive/sql-grant.html for details. > In postgres 9.0 it looks like this use case is better supported with > the: > > grant select on all tables in schema public to ro_user; > > but using 9.0 isn't an option at the moment. Also can anybody confirm > that will do what I want and won't just set the rights on the tables > that exist in the schema at that time. > This query will give SELECT permission to user ro_user for existing tables. If you want to set default permissions for not-already-existing tables, you need to use ALTER DEFAULT PRIVILEGES. Only in 9.0 though. See http://www.postgresql.org/docs/9.0/static/sql-alterdefaultprivileges.html for more details on this statement. > One other thing I came across is setting the roleconfig > > {default_transaction_read_only=true} > > so I am wondering if I can duplicate the database owner's roles and > use this setting to make it readonly? Also it concerns me that it's > named default_transaction_read_only, which implies that it could be > overridden as it's only the default. > It could be orverridden. The first user that will issue a "SET default_transaction_read_only TO false;" will be able to make changes (if permission allow). > Does anybody have any other ideas on how to crack this problem from > the administration side rather than by changing the application. > Yes, use GRANT each time you create a table. You can also use a stored procedure that will create the table and adds your default permissions. -- Guillaume http://www.postgresql.fr http://dalibo.com