pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
granting right to create and delete just one database
4+ messages / 2 participants
[nested] [flat]

* granting right to create and delete just one database
@ 2019-06-05 06:11  Chris Withers <chris@withers.org>
  0 siblings, 1 reply; 4+ messages in thread

From: Chris Withers @ 2019-06-05 06:11 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.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





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: granting right to create and delete just one database
@ 2019-06-05 08:52  Laurenz Albe <laurenz.albe@cybertec.at>
  parent: Chris Withers <chris@withers.org>
  0 siblings, 1 reply; 4+ messages in thread

From: Laurenz Albe @ 2019-06-05 08:52 UTC (permalink / raw)
  To: Chris Withers <chris@withers.org>; pgsql-general@lists.postgresql.org

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






^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: granting right to create and delete just one database
@ 2019-06-05 08:56  Chris Withers <chris@withers.org>
  parent: Laurenz Albe <laurenz.albe@cybertec.at>
  0 siblings, 1 reply; 4+ messages in thread

From: Chris Withers @ 2019-06-05 08:56 UTC (permalink / raw)
  To: Laurenz Albe <laurenz.albe@cybertec.at>; pgsql-general@lists.postgresql.org

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






^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: granting right to create and delete just one database
@ 2019-06-05 15:00  Laurenz Albe <laurenz.albe@cybertec.at>
  parent: Chris Withers <chris@withers.org>
  0 siblings, 0 replies; 4+ messages in thread

From: Laurenz Albe @ 2019-06-05 15:00 UTC (permalink / raw)
  To: Chris Withers <chris@withers.org>; pgsql-general@lists.postgresql.org

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






^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2019-06-05 15:00 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-06-05 06:11 granting right to create and delete just one database Chris Withers <chris@withers.org>
2019-06-05 08:52 ` Laurenz Albe <laurenz.albe@cybertec.at>
2019-06-05 08:56   ` Chris Withers <chris@withers.org>
2019-06-05 15:00     ` Laurenz Albe <laurenz.albe@cybertec.at>

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