pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedInvoking user of the function with SECURITY DEFINER
5+ messages / 4 participants
[nested] [flat]
* Invoking user of the function with SECURITY DEFINER
@ 2018-11-22 11:24 Madan Kumar <madankumar1993@gmail.com>
0 siblings, 1 reply; 5+ messages in thread
From: Madan Kumar @ 2018-11-22 11:24 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Hi,
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?
Warm Regards,
Madan Kumar K <https://about.me/madankumark;
*"There is no Elevator to Success. You have to take the Stairs"*
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Invoking user of the function with SECURITY DEFINER
@ 2018-11-22 11:45 Laurenz Albe <laurenz.albe@cybertec.at>
parent: Madan Kumar <madankumar1993@gmail.com>
0 siblings, 1 reply; 5+ messages in thread
From: Laurenz Albe @ 2018-11-22 11:45 UTC (permalink / raw)
To: Madan Kumar <madankumar1993@gmail.com>; pgsql-general@lists.postgresql.org
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
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Invoking user of the function with SECURITY DEFINER
@ 2018-11-24 20:54 raf <raf@raf.org>
parent: Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 1 reply; 5+ messages in thread
From: raf @ 2018-11-24 20:54 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Laurenz Albe wrote:
> 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
session_user has always worked for me.
cheers,
raf
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Invoking user of the function with SECURITY DEFINER
@ 2018-11-25 11:50 Madan Kumar <madankumar1993@gmail.com>
parent: raf <raf@raf.org>
0 siblings, 1 reply; 5+ messages in thread
From: Madan Kumar @ 2018-11-25 11:50 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Got it..
In my case i was getting session_user in declare section and trying to
validate later which always resulted in the function owner.
DECLARE
user text := SESSION_USER;
So using it within the BEGIN; ...; END; clause worked for me.
Thanks.
Warm Regards,
Madan Kumar K <https://about.me/madankumark;
*"There is no Elevator to Success. You have to take the Stairs"*
On Sun, Nov 25, 2018 at 2:24 AM raf <raf@raf.org> wrote:
> Laurenz Albe wrote:
>
> > 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
>
> session_user has always worked for me.
>
> cheers,
> raf
>
>
>
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Invoking user of the function with SECURITY DEFINER
@ 2019-04-10 15:19 Олег Самойлов <splarv@ya.ru>
parent: Madan Kumar <madankumar1993@gmail.com>
0 siblings, 0 replies; 5+ messages in thread
From: Олег Самойлов @ 2019-04-10 15:19 UTC (permalink / raw)
To: Madan Kumar <madankumar1993@gmail.com>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Looked like a bug.
> 25 нояб. 2018 г., в 14:50, Madan Kumar <madankumar1993@gmail.com> написал(а):
>
> Got it..
> In my case i was getting session_user in declare section and trying to validate later which always resulted in the function owner.
> DECLARE
> user text := SESSION_USER;
>
> So using it within the BEGIN; ...; END; clause worked for me.
> Thanks.
>
>
> Warm Regards,
> Madan Kumar K
>
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2019-04-10 15:19 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-11-22 11:24 Invoking user of the function with SECURITY DEFINER Madan Kumar <madankumar1993@gmail.com>
2018-11-22 11:45 ` Laurenz Albe <laurenz.albe@cybertec.at>
2018-11-24 20:54 ` raf <raf@raf.org>
2018-11-25 11:50 ` Madan Kumar <madankumar1993@gmail.com>
2019-04-10 15:19 ` Олег Самойлов <splarv@ya.ru>
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