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 1gPnQU-0004Wd-TV for pgsql-general@arkaria.postgresql.org; Thu, 22 Nov 2018 11:45:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gPnQT-0004AI-Je for pgsql-general@arkaria.postgresql.org; Thu, 22 Nov 2018 11:45:41 +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 1gPnQT-0004AB-Af for pgsql-general@lists.postgresql.org; Thu, 22 Nov 2018 11:45:41 +0000 Received: from mx1.mailbox.org ([80.241.60.212]) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gPnQP-0007kU-JP for pgsql-general@lists.postgresql.org; Thu, 22 Nov 2018 11:45:40 +0000 Received: from smtp1.mailbox.org (unknown [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id 70951444E1; Thu, 22 Nov 2018 12:45:36 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by hefe.heinlein-support.de (hefe.heinlein-support.de [91.198.250.172]) (amavisd-new, port 10030) with ESMTP id 2zVUgEv-EW0V; Thu, 22 Nov 2018 12:45:35 +0100 (CET) Message-ID: Subject: Re: Invoking user of the function with SECURITY DEFINER From: Laurenz Albe To: Madan Kumar , pgsql-general@lists.postgresql.org Date: Thu, 22 Nov 2018 12:45:34 +0100 In-Reply-To: References: Organization: Cybertec Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Madan Kumar wrote: > How to get the user who is invoking the function with SECURITY DEFINER? > When we define the function to be SECURITY DEFINER, it will execute in the > context of the user who created it. Let's say I've given execute permission > for this function to other users and wish to know who is executing it. > Is there a way to find that out? > I tried CURRENT_USER and SESSION_USER but they return the function owner > since they execute in that context. So is there any way to figure out the > user who is invoking the function? It works for me: As user "postgres": CREATE OR REPLACE FUNCTION tellme() RETURNS text LANGUAGE plpgsql SECURITY DEFINER AS 'BEGIN RETURN session_user; END;'; As user "laurenz": SELECT tellme(); tellme --------- laurenz (1 row) Yours, Laurenz Albe -- +43-670-6056265 Cybertec Schönig & Schönig GmbH Gröhrmühlgasse 26, A-2700 Wiener Neustadt Web: https://www.cybertec-postgresql.com