Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1msuQd-0007pg-Sw for pgsql-docs@arkaria.postgresql.org; Thu, 02 Dec 2021 22:19:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1msuQZ-0001cf-Ob for pgsql-docs@arkaria.postgresql.org; Thu, 02 Dec 2021 22:19:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1msWJc-00080Z-KY for pgsql-docs@lists.postgresql.org; Wed, 01 Dec 2021 20:34:56 +0000 Received: from rmr2.rz.htw-dresden.de ([141.56.16.232]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1msWJZ-0002KG-Pi for pgsql-docs@lists.postgresql.org; Wed, 01 Dec 2021 20:34:56 +0000 Received: from localhost (localhost [127.0.0.1]) by rmr2.rz.htw-dresden.de (Postfix) with ESMTP id 74B0B38815F; Wed, 1 Dec 2021 21:34:52 +0100 (CET) X-HTW-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on rmr2.rz.htw-dresden.de X-HTW-Virus-Scanned: Debian amavisd-new at rmr2.rz.htw-dresden.de Received: from rmr2.rz.htw-dresden.de ([127.0.0.1]) by localhost (rmr2.rz.htw-dresden.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id a4mB0E89YHsd; Wed, 1 Dec 2021 21:34:45 +0100 (CET) Received: from rmex21.dom.htw-dresden.de (rmex21.dom.htw-dresden.de [141.56.1.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "groupware.htw-dresden.de", Issuer "DFN-Verein Global Issuing CA" (verified OK)) by rmr2.rz.htw-dresden.de (Postfix) with ESMTPS id F1B0D388151; Wed, 1 Dec 2021 21:34:44 +0100 (CET) Received: from [192.168.178.10] (141.56.16.106) by rmex21.dom.htw-dresden.de (141.56.1.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.10; Wed, 1 Dec 2021 21:34:44 +0100 From: Max Ziermann Subject: Re: Triggers on underlying tables of updatable views To: Laurenz Albe , References: <163758281947.26190.10251137266467665332@wrigleys.postgresql.org> <2f54dbb7d59aacacbc4654b0bc56faaebe993e09.camel@cybertec.at> <3e14b477-40ce-4b6a-047a-9fea3843427c@htw-dresden.de> Message-ID: Date: Wed, 1 Dec 2021 21:34:44 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Language: en-GB X-Originating-IP: [141.56.16.106] X-ClientProxiedBy: rmex22.dom.htw-dresden.de (141.56.1.154) To rmex21.dom.htw-dresden.de (141.56.1.153) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I'm not sure where in the docs a clarification could best be placed. For me, the confusion arises from the fact that the updatable views section on the CREATE VIEW docs aren't very clear what *actually* happens when performing insert/update etc. through a view. It seems like the distinction between "security context" and the actual user might be helpful to understand the behaviour. With this background in mind, I still think that the wording "the user performing the update does not need ANY permissions on the underlying base relations" (from CREATE VIEW; emphasis mine) is misleading. However, to me, it would be perfectly fine if this statement was scoped to the actual insert/update on the base relation, thus excluding triggered functions (unless SECURITY DEFINERs). Best Regards, Max Ziermann Am 23.11.21 um 11:28 schrieb Laurenz Albe: > On Mon, 2021-11-22 at 21:02 +0100, Laurenz Albe wrote: >> On Mon, 2021-11-22 at 19:54 +0100, Max Ziermann wrote: >>> Am 22.11.21 um 16:41 schrieb Laurenz Albe: >>>> On Mon, 2021-11-22 at 12:06 +0000, PG Doc comments form wrote: >>>>> "Note that the user performing the insert, update or delete on the view must >>>>> have the corresponding insert, update or delete privilege on the view. In >>>>> addition the view's owner must have the relevant privileges on the >>>>> underlying base relations, but the user performing the update does not need >>>>> any permissions on the underlying base relations (see Section 41.5)." >>>>> >>>>> Could it be made more clear that triggers on a underlying table of an >>>>> updatable view are still executed with the permissions of the user >>>>> performing an insert/update/delete on the view? >>>> But that is not the case: that trigger will be executed with the permissions >>>> of the owner of the underlying table. >>> Maybe I am missing an obvious point, but I don't think that's the case. >>> SQL example: > After some more thinking and experimenting, I realize that was wrong. > > The trigger will always execute with the permissions of the user > running the query. > Only the permissions on the underlying tables are checked for the > view owner, the actual query is executed in the security context of > the user that queries the view. > > I don't think that requires special mention on the CREATE VIEW page, > since it is no different when views are not involved. > It might be worth mentioning on > https://www.postgresql.org/docs/current/trigger-definition.html > that triggers (unless the function is SECURITY DEFINER) are executed > under the security context of the user that runs the query, rather > than under the security context of the table owner. >