Re: current_role of caller of a DEFINER function

From: walther(at)technowledgy(dot)de
To: Dominique Devienne <ddevienne(at)gmail(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: current_role of caller of a DEFINER function
Date: 2024-06-26 10:11:26
Message-ID: 0b7d3b22-3e98-4eca-bc14-9430c48c0217@technowledgy.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Dominique Devienne:
> 1) Is there any way to know the current_role of the caller of a
> DEFINER function. I fear the answer is no, but better be sure from
> experts here.

You can do something like this:

CREATE DOMAIN current_user_only AS text
CONSTRAINT current_user_only CHECK (VALUE = CURRENT_USER);

CREATE FUNCTION func(
calling_user current_user_only DEFAULT CURRENT_USER
) ... SECURITY DEFINER;

The default value will be evaluated in the context of the calling user,
the constraint forces it to never be set explicitly to something else.

Thus you can use calling_user inside your function.

Best,

Wolfgang

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dominique Devienne 2024-06-26 12:25:30 Re: current_role of caller of a DEFINER function
Previous Message Erik Wienhold 2024-06-26 10:06:29 Re: current_role of caller of a DEFINER function