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 1jjsbd-00037A-S4 for pgsql-general@arkaria.postgresql.org; Fri, 12 Jun 2020 22:57:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jjsbc-0001kk-Fa for pgsql-general@arkaria.postgresql.org; Fri, 12 Jun 2020 22:57:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jjsbc-0001j1-7q for pgsql-general@lists.postgresql.org; Fri, 12 Jun 2020 22:57:00 +0000 Received: from ook.raf.org ([139.99.156.21]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jjsbV-00032w-Rn for pgsql-general@lists.postgresql.org; Fri, 12 Jun 2020 22:56:59 +0000 Received: from localhost (localhost [127.0.0.1]) by ook.raf.org (Postfix) with ESMTP id C85B85DD18 for ; Sat, 13 Jun 2020 08:56:50 +1000 (AEST) X-Virus-Scanned: Debian amavisd-new at ook.raf.org Received: from ook.raf.org ([127.0.0.1]) by localhost (ook.raf.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id a2wuUULAYeup for ; Sat, 13 Jun 2020 08:56:48 +1000 (AEST) Received: by ook.raf.org (Postfix, from userid 1001) id E4EB85E2C2; Sat, 13 Jun 2020 08:56:48 +1000 (AEST) Date: Sat, 13 Jun 2020 08:56:48 +1000 From: raf To: pgsql-general@lists.postgresql.org Subject: Re: Changing from security definer to security invoker without dropping ? Message-ID: <20200612225648.4hbpvyf5w2j3m36a@raf.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Laura Smith wrote: > ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ > On Thursday, 11 June 2020 08:39, Pavel Stehule wrote: > > > Hi > > > > čt 11. 6. 2020 v 9:29 odesílatel Laura Smith napsal: > > > > > Hi, > > > > > > Just curious if there is a way to switch a function from definer to invoker without dropping ? > > > > create function foo(a int) returns int as $$ begin return $1; end $$ language plpgsql; > > > > postgres=# alter function foo (int) security definer; > > ALTER FUNCTION > > postgres=# alter function foo (int) security invoker; > > ALTER FUNCTION > > > > regards > > > > Pavel > > Thanks Pavel !  Didn't realise it was that easy. "create or replace function..." with "security invoker" (or without "security definer" since security invoker is the default) is probably another way to do it, but it would be slower than "alter function" since it needs to parse the code again. That might matter if you have many functions to change. Bear in mind that things might break with such a change. There might be a reason that the functions needed to be created as security definers. I'd recommend checking each function's need to be a security definer before changing it (or just test it thoroughly somewhere). cheers, raf