Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id A7F6BB5DBF4 for ; Tue, 25 Oct 2011 00:36:43 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 30661-08 for ; Tue, 25 Oct 2011 03:36:36 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from nm38-vm7.bullet.mail.ne1.yahoo.com (nm38-vm7.bullet.mail.ne1.yahoo.com [98.138.229.151]) by mail.postgresql.org (Postfix) with SMTP id 581CFB5DBC7 for ; Tue, 25 Oct 2011 00:36:36 -0300 (ADT) Received: from [98.138.90.54] by nm38.bullet.mail.ne1.yahoo.com with NNFMP; 25 Oct 2011 03:36:35 -0000 Received: from [98.138.87.8] by tm7.bullet.mail.ne1.yahoo.com with NNFMP; 25 Oct 2011 03:36:35 -0000 Received: from [127.0.0.1] by omp1008.mail.ne1.yahoo.com with NNFMP; 25 Oct 2011 03:36:35 -0000 X-Yahoo-Newman-Id: 103001.42479.bm@omp1008.mail.ne1.yahoo.com Received: (qmail 93197 invoked from network); 25 Oct 2011 03:36:35 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=DKIM-Signature:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:References:Mime-Version:In-Reply-To:X-Apple-Yahoo-Original-Message-Folder:Content-Type:Content-Transfer-Encoding:Message-Id:Cc:X-Mailer:From:X-Apple-Yahoo-Replied-Msgid:Subject:Date:To; b=3FzEI2DJT+jPLspEglRWtZWiZJI2KETdPGHYOJNp9Vy506F1X0nNiOLYpEqUEar56Ufo2HBedCG/itA9Ryi4oYfw+4svJVaHphTkcDua8iUWh6Chzf0y8I9pigOzaRftfvBE7/uLD8jyEtc6f9DOi4YI3Q0CR1B8RDj4lPTmlUs= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1319513795; bh=SusiY7wsG+4sqwmGzsEVGSM4GQLpzf/2aKn7MvzdALQ=; h=X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:References:Mime-Version:In-Reply-To:X-Apple-Yahoo-Original-Message-Folder:Content-Type:Content-Transfer-Encoding:Message-Id:Cc:X-Mailer:From:X-Apple-Yahoo-Replied-Msgid:Subject:Date:To; b=W9PIrAwuLMVukF7WWAC/qePrF5xkhYHGwGrcNFRT/4Cf/dYEZzNP/IylzQGkal3FHQjijLvfUBdVXiPZYl2X2ebIOsT4E8zxvOYWNYgSupoT+p9j/2L4AhzvvDXrN/TKDpDYUm5AoVg64i/sYPJbSxEp4zitJGO7I73DYvGC4xo= X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: k1trobcVM1nRy3iiSeDCwvK4Ou76DI4ke4ohmFdD.up20cd yI6dNFddqnAU7t9k2zm_P.2yZr66LApBYHG.XEACFeRrQlJZsQxVQBgKcG_o MuRBKwbnoPUdevojnyeOHkOLSPE2zuZhh.BfpgRnpiGywUpbS_UB97dk2JZB 2bBMi1C_PaxgpmgJpvSGiCNNUXxFk8w8d1cELLWIiUmrlE1Qk9scOjj4HOjX aE1Eg_8wk2YVK0a4MhMfTG_LnmPC1vmZF2yZt.uyUOmS8vgK0FtbnhIFgKuO Y6NmkxIbDnrt6ieQZQKVflGMxj_yOHpnpFHxOeB_9_etuZcYCbyBzzgM_4AU .coU3L5XnrQw2A5TuuKYtkMDd1jQQ4aCX47WywIQGKx6r3_3W6zi7pTpe_EX P X-Yahoo-SMTP: mpGJl6eswBD2IBufoVEg0Pa8gg-- Received: from [192.12.17.102] (polobo@24.93.23.188 with xymcookie) by smtp104-mob.biz.mail.ne1.yahoo.com with SMTP; 24 Oct 2011 20:36:34 -0700 PDT References: <4EA62500.9070000@ringerc.id.au> Mime-Version: 1.0 (iPad Mail 8J2) In-Reply-To: <4EA62500.9070000@ringerc.id.au> X-Apple-Yahoo-Original-Message-Folder: Inbox Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Message-Id: <34C216F7-8D8D-4F18-A693-AAF922BF6672@yahoo.com> Cc: =?utf-8?Q?Brice_Andr=C3=A9?= , "pgsql-sql@postgresql.org" X-Mailer: iPad Mail (8J2) From: David Johnston X-Apple-Yahoo-Replied-Msgid: 1_113410_AOGkiGIAAEHWTqYlHAB+3VSgCNA Subject: Re: Handling mutliple clients access with views Date: Mon, 24 Oct 2011 23:36:33 -0400 To: Craig Ringer X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.403 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RP_MATCHES_RCVD=-0.504 X-Spam-Level: X-Archive-Number: 201110/67 X-Sequence-Number: 35951 On Oct 24, 2011, at 22:54, Craig Ringer wrote: > On 25/10/11 03:23, Brice Andr=C3=A9 wrote: >> Hello everyone, >>=20 >> I am developping a web service where some tables are handling the data >> of different clients. Depending on configured rights, one client can >> have no access, or read access, or read and write access to other >> clients data. >>=20 >> In order to handle that, I am using views and, to ensure that a client >> cannot access data outside the view, all clients info is stored in a >> table where its postgresql user name is also stored. So, in order to >> limit access of view, I am using the postgresql special function >> "current_user()" and I am retrieving the id of my client like this. >=20 > That sounds ... roundabout. >=20 > Why not use roles and role inheritance? You can use SET ROLE to > temporarily change roles, log in as different roles, have one role be a > member of other roles, have role access permissions on tables/views at > the column or table level, etc. >=20 >> - My method requests that each user has its own postgresql user. But, >> in this case, my web server needs to establish a postgresql connection >> for each user, which will maybe cause problems. >=20 > Connect as a single user, then SET ROLE to the user you want in order to > control access. >=20 > Instead of using current_user() and programmatic security checking, use > GRANT and REVOKE for declarative access checking where possible. >=20 >> So, I was guessing if I was not completely wrong by doing like that. >> Maybe is there a simpler way of doing what I try to do ? Or maybe am I a >> little bit too parano=C3=AFde, and maybe should I handle all my clients w= ith >> a single postgresql user, handling all safety aspect in my php script ? >=20 > Nope, I heartily approve of doing security in-database, especially if > you can do it declaratively. >=20 > -- > Craig Ringer >=20 > --=20 > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql Except database roles cannot strictly enforce row-level security (i.e., mult= iple-tenant) which is the goal of this setup. Views are not fool-proof in providing row-level security, for that you need f= unctions. While a view itself will not provide the protected data a function= can be used to process data (via RAISE NOTICE) that would otherwise be filt= ered out in the end result. This is because views are simply re-write rules= . David J.