pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Gabriel Furstenheim Milerud <furstenheim@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Enforcing users to write schemas when creating tables
Date: Wed, 20 Dec 2017 11:01:27 +0100
Message-ID: <1513764087.2590.13.camel@cybertec.at> (raw)
In-Reply-To: <CAJN3DWqK31jQeyz_P_d2Ztnv_kPKhx8+21ARS75gfg6kwS7MdA@mail.gmail.com>
References: <CAJN3DWqK31jQeyz_P_d2Ztnv_kPKhx8+21ARS75gfg6kwS7MdA@mail.gmail.com>

Gabriel Furstenheim Milerud wrote:
> I'm trying to enforce db users to write a schema when creating a table. That is:
> 
>      create table some_schema.my_table (a int); -- should succeed
>      create my_table (a int); -- should fail
> 
>  I don't know if that is possible.
> 
> What I've tried so far is to create a schema which is first in the search path and where the user has no permission to create tables. I've done the following (and failed):
> 
> 
>     create schema no_table_schema;
>     alter schema no_table_schema owner to another_user; -- just in case
>     revoke all on schema no_table_schema from my_user cascade;
>     set search_path = no_table_schema;
>    
>     create table test_table (a int); -- this should fail because user should not have permission in no_table_schema, but it does not
>     drop table no_table_schema.test_table; -- This succeeds, the table was created
> 
> One thing that might affect is that my_user is a superuser.
> 
> So I have two questions, first is how do I revoke create on a schema for a certain user. I guess there is something that I'm not doing properly.
> Then, is that enough my purpose? Or maybe there are easier ways to force users to provide schema when creating.

There is no way to deny a superuser access to a schema.
Don't use superusers for anything else than administration.

One way I can think of to force users to create tables with
schema qualified names is to set "search_path" to "pg_catalog".
Then only the temporary schema and the catalog schema can be
used without qualification.

Every user can use "SET search_path = ..." to change the setting,
but a script that does that documents at least where the table
*might* be created.

Yours,
Laurenz Albe




view thread (2+ messages)

Message-ID: <1513764087.2590.13.camel@cybertec.at>
Permalink:  ../1513764087.2590.13.camel@cybertec.at/
Also on:    postgresql.org/message-id/1513764087.2590.13.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, furstenheim@gmail.com
  Subject: Re: Enforcing users to write schemas when creating tables
  In-Reply-To: <1513764087.2590.13.camel@cybertec.at>
  References: <CAJN3DWqK31jQeyz_P_d2Ztnv_kPKhx8+21ARS75gfg6kwS7MdA@mail.gmail.com> <1513764087.2590.13.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