Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hp2VS-0003s9-Oe for pgsql-bugs@arkaria.postgresql.org; Sun, 21 Jul 2019 03:27:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hp2VR-0007p7-Bu for pgsql-bugs@arkaria.postgresql.org; Sun, 21 Jul 2019 03:27:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hp2VR-0007o7-4J for pgsql-bugs@lists.postgresql.org; Sun, 21 Jul 2019 03:27:25 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hp2VM-0006hx-Gg for pgsql-bugs@lists.postgresql.org; Sun, 21 Jul 2019 03:27:22 +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 x6L3RHOm008096; Sat, 20 Jul 2019 23:27:17 -0400 From: Tom Lane To: Vladimir Ryabtsev cc: pgsql-bugs@lists.postgresql.org Subject: Re: User mapping: view over a foreign table In-reply-to: References: Comments: In-reply-to Vladimir Ryabtsev message dated "Wed, 17 Jul 2019 14:24:04 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <8094.1563679637.1@sss.pgh.pa.us> Date: Sat, 20 Jul 2019 23:27:17 -0400 Message-ID: <8095.1563679637@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Vladimir Ryabtsev writes: > Supposing I have a foreign table F and a view V that selects rows from F. > The owner of F is USER1. > The owner of V is USER2. > The currently logged user is "me". > When I query the foreign table F, the DBMS engine looks for USER MAPPING > for "me", regardless of who is the owner of the table. > When I query the view V, the engine searches the USER MAPPING for USER2 who > is the owner of the view. > This looks inconsistent and misleading. AFAICS, it's exactly parallel to the handling of SQL permissions for the foreign table. If you query F directly, you must have SELECT permissions on F (or whatever is appropriate for your query type). If you query F via V, you must have SELECT on V and the owner of V must have SELECT on F. regards, tom lane