pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Madan Kumar <madankumar1993@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Invoking user of the function with SECURITY DEFINER
Date: Thu, 22 Nov 2018 12:45:34 +0100
Message-ID: <bd95ac4a16c77efa49f724e93bbabb74dfbdae38.camel@cybertec.at> (raw)
In-Reply-To: <CAMtsaPG8BJJFNwe1MK0fd=U8_J=YSGaEus9+gvswVO9BhVNwmA@mail.gmail.com>
References: <CAMtsaPG8BJJFNwe1MK0fd=U8_J=YSGaEus9+gvswVO9BhVNwmA@mail.gmail.com>

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





view thread (5+ messages)  latest in thread

Message-ID: <bd95ac4a16c77efa49f724e93bbabb74dfbdae38.camel@cybertec.at>
Permalink:  ../bd95ac4a16c77efa49f724e93bbabb74dfbdae38.camel@cybertec.at/
Also on:    postgresql.org/message-id/bd95ac4a16c77efa49f724e93bbabb74dfbdae38.camel@cybertec.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: laurenz.albe@cybertec.at, madankumar1993@gmail.com
  Subject: Re: Invoking user of the function with SECURITY DEFINER
  In-Reply-To: <bd95ac4a16c77efa49f724e93bbabb74dfbdae38.camel@cybertec.at>
  References: <CAMtsaPG8BJJFNwe1MK0fd=U8_J=YSGaEus9+gvswVO9BhVNwmA@mail.gmail.com> <bd95ac4a16c77efa49f724e93bbabb74dfbdae38.camel@cybertec.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox