Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cvxf9-0005Bq-KN for pgsql-bugs@arkaria.postgresql.org; Thu, 06 Apr 2017 03:00:43 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cvxf7-0008Q1-9b for pgsql-bugs@arkaria.postgresql.org; Thu, 06 Apr 2017 03:00:41 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cvxf6-0008Pr-OL for pgsql-bugs@postgresql.org; Thu, 06 Apr 2017 03:00:40 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cvxf4-0003XC-6Q for pgsql-bugs@postgresql.org; Thu, 06 Apr 2017 03:00:39 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v3630aJr014344; Wed, 5 Apr 2017 23:00:36 -0400 From: Tom Lane To: hkauchi@gmail.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #14613: Referencing foreign key needs privileges of table owner? In-reply-to: <20170406020941.25934.30410@wrigleys.postgresql.org> References: <20170406020941.25934.30410@wrigleys.postgresql.org> Comments: In-reply-to hkauchi@gmail.com message dated "Thu, 06 Apr 2017 02:09:41 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <14342.1491447636.1@sss.pgh.pa.us> Date: Wed, 05 Apr 2017 23:00:36 -0400 Message-ID: <14343.1491447636@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org hkauchi@gmail.com writes: > create role user1; > create role user2 login; > create table table1(id int primary key); > create table table2(id int primary key, table1_id integer references > table1(id)); > alter table table1 owner to user1; > alter table table2 owner to user2; > grant select,insert,update,delete on table1 to user2; > grant select,insert,update,delete on table2 to user2; > revoke all on schema public from public; // To prevent creation of > objects. You realize that that's much more draconian than needed to prevent creation of objects? In particular, you've left user1 unable to reference the table it owns, which hardly seems like a useful arrangement. > test=# insert into table2(id, table1_id) values(1,1); > ERROR: permission denied for schema public > LINE 1: SELECT 1 FROM ONLY "public"."table1" x WHERE "id" OPERATOR(p... > ^ > QUERY: SELECT 1 FROM ONLY "public"."table1" x WHERE "id" > OPERATOR(pg_catalog.=) $1 FOR KEY SHARE OF x This is not a bug. That foreign key check query is executed as the owner of table1. If it were not, you'd probably be complaining about some other permissions problem. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs