granting right to create and delete just one database

Started by Chris Withersalmost 7 years ago4 messagesgeneral
Jump to latest
#1Chris Withers
chris@withers.org

Hi All,

Is there any way to grant rights to a user such that they can drop and
re-create only a single database?

cheers,

Chris

#2Laurenz Albe
laurenz.albe@cybertec.at
In reply to: Chris Withers (#1)
Re: granting right to create and delete just one database

Chris Withers wrote:

Is there any way to grant rights to a user such that they can drop and
re-create only a single database?

No; what I'd do if I needed that is to create a SECURITY DEFINER function
that is owned by a user with the CREATEDB privilege.
This function can be called by a normal user that has the EXECUTE privilege
on the function.

Don't forget to "SET search_path" on such a function (as mentioned in the
documentation). It might also be a good idea to REVOKE EXECUTE on the
function from PUBLIC.

Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com

#3Chris Withers
chris@withers.org
In reply to: Laurenz Albe (#2)
Re: granting right to create and delete just one database

On 05/06/2019 09:52, Laurenz Albe wrote:

Chris Withers wrote:

Is there any way to grant rights to a user such that they can drop and
re-create only a single database?

No; what I'd do if I needed that is to create a SECURITY DEFINER function
that is owned by a user with the CREATEDB privilege.
This function can be called by a normal user that has the EXECUTE privilege
on the function.

Don't forget to "SET search_path" on such a function (as mentioned in the
documentation). It might also be a good idea to REVOKE EXECUTE on the
function from PUBLIC.

Thanks, that's a great idea! Is this pattern documented anywhere as a
complete finished thing?

cheers,

Chris

#4Laurenz Albe
laurenz.albe@cybertec.at
In reply to: Chris Withers (#3)
Re: granting right to create and delete just one database

Chris Withers wrote:

Is there any way to grant rights to a user such that they can drop and
re-create only a single database?

No; what I'd do if I needed that is to create a SECURITY DEFINER function
that is owned by a user with the CREATEDB privilege.

Thanks, that's a great idea! Is this pattern documented anywhere as a
complete finished thing?

I'm afraid that is left as an exercise to the reader.

Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com