Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eRbCC-0006FG-AA for pgsql-general@arkaria.postgresql.org; Wed, 20 Dec 2017 10:01:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eRbCB-0007ji-O4 for pgsql-general@arkaria.postgresql.org; Wed, 20 Dec 2017 10:01:51 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eRbCB-0007jZ-Ab for pgsql-general@lists.postgresql.org; Wed, 20 Dec 2017 10:01:51 +0000 Received: from mx2.mailbox.org ([80.241.60.215]) by makus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eRbC7-00053C-P0 for pgsql-general@lists.postgresql.org; Wed, 20 Dec 2017 10:01:49 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id 60FB74D2F1; Wed, 20 Dec 2017 11:01:42 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de [80.241.56.117]) (amavisd-new, port 10030) with ESMTP id d4HhrCZmNFgY; Wed, 20 Dec 2017 11:01:29 +0100 (CET) Message-ID: <1513764087.2590.13.camel@cybertec.at> Subject: Re: Enforcing users to write schemas when creating tables From: Laurenz Albe To: Gabriel Furstenheim Milerud , pgsql-general@lists.postgresql.org Date: Wed, 20 Dec 2017 11:01:27 +0100 In-Reply-To: References: Organization: Cybertec Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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