Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jSkbG-0001TO-5u for pgsql-admin@arkaria.postgresql.org; Sun, 26 Apr 2020 16:57:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jSkbE-00011Q-Si for pgsql-admin@arkaria.postgresql.org; Sun, 26 Apr 2020 16:57:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jSkbE-0000ym-If for pgsql-admin@lists.postgresql.org; Sun, 26 Apr 2020 16:57:48 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jSkbD-0003rc-5l for pgsql-admin@postgresql.org; Sun, 26 Apr 2020 16:57:48 +0000 Received: by mail-wm1-x342.google.com with SMTP id e26so16890973wmk.5 for ; Sun, 26 Apr 2020 09:57:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding:content-language; bh=Nh2nNFvULvCNEPH/v0YPSIkS3toLOEMur+1Z9hwllBs=; b=s8EEAHTkpq0jqClWDWepZAgrc2L663nvlLi20PN2/bO8nkjXZLQGHT+mO81fZrHi/4 LgO/XGGuM7feQBuVbRcrDzuISIZzCsUiD31CF/yaveKs3JUhGa/jVm2RqyLahwatz6y5 Yx72wJiCOBzDQ3X/ZFxhOsJEdtQd9ft08Ozc+TtxgxKdh70UZSHVDwD8OMWLCgpsYcdq nqvmtZysJqS6xduJxnZE1rsyI8P3j8gg2GYTYeCePkw8eolc0wQwOA09jt4/TsfB7qhW gt9PYWuvsZk91YOsrqE7xmkL1J0GlOC6SWy0Du6qcYZu81TQEc7dzpx75l1apaME0RH4 hb2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding:content-language; bh=Nh2nNFvULvCNEPH/v0YPSIkS3toLOEMur+1Z9hwllBs=; b=hn/JRpaj6wFjPlP7uNX2froye2yD0JD9hTQ1QL5uvjQP0P4YHf+QsUyTQasqENiU8I HnfLqB2uVO1rimxqsfX/u1UYDNIaK1wiktQ5ZCIzELpOcr2t8IK6iQs5tkEL+cMcwP3N xqIxAZljt4mAjg1pmc7F2deuN5MsUNR+aVW4v+UNfobxfp/uxeZhwQvz0VyEllXUdMNN 5P4PyjCXJi5CgeMMTX35eP4EaN5MEQ+Zt9cpMjgpNjQ+oC2NI4LetvjueZVxfYYp8egh +JUGGTgC5hbXoM5UFx81s66XyIJdHLGM5U6ynXg04iA2lu+EuUi4g5cyq4EyUXMpqyHI PV5g== X-Gm-Message-State: AGi0PuZLfftdStbwVmHMwqMmk+MY6xvqG5z3iCH9ap0Pz4lp4fxSyWoU jYOKCZwsHdkJtQtWGqAUlS07MQfB X-Google-Smtp-Source: APiQypKlJ38byJaCgLEwDMMZ5RacOm67TuOG4VnVPvJACervEhHcQdE08z5y1kONRdykr5fzX871HQ== X-Received: by 2002:a05:600c:2046:: with SMTP id p6mr21809941wmg.177.1587920265054; Sun, 26 Apr 2020 09:57:45 -0700 (PDT) Received: from [192.168.1.212] (ip-5-186-124-33.cgn.fibianet.dk. [5.186.124.33]) by smtp.gmail.com with ESMTPSA id z22sm11514696wma.20.2020.04.26.09.57.44 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 26 Apr 2020 09:57:44 -0700 (PDT) To: pgsql-admin@postgresql.org From: Bo Victor Thomsen Subject: Setting up a database with minimum access rights Message-ID: Date: Sun, 26 Apr 2020 18:58:07 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Dear all - I have a problem with the setup of access rights based on schemas. The objective is to have a schema with default access rights to tables assigned to the schema. And to strip the "public" user group for all rights. So if you create a table in a certain schema ("data_schema") it will be generated with the rights defined using a "ALTER DEFAULT ..." command to the schema. But I can't get it to work... Here is the pertinent commands used: -- Remove all access rights for "public" REVOKE ALL ON SCHEMA public, data_schema FROM PUBLIC; REVOKE ALL ON DATABASE greenadm FROM PUBLIC; -- Create necessary ressource role CREATE ROLE greenadm_read; -- Access to database "greenadm" for role "greenadm_read" GRANT CONNECT, TEMP ON DATABASE greenadm TO greenadm_read; -- Access to schema for the ressource role GRANT USAGE ON SCHEMA public, data_schema TO greenadm_read; -- Default read access rights for ressource role ALTER DEFAULT PRIVILEGES IN SCHEMA public, data_schema GRANT SELECT  ON TABLES    TO greenadm_read; ALTER DEFAULT PRIVILEGES IN SCHEMA public, data_schema GRANT SELECT  ON SEQUENCES TO greenadm_read; ALTER DEFAULT PRIVILEGES IN SCHEMA public, data_schema GRANT EXECUTE ON FUNCTIONS TO greenadm_read; -- And a login user... CREATE ROLE loki WITH LOGIN PASSWORD 'sneaky' VALID UNTIL '2021-01-01' INHERIT; GRANT greenadm_read TO loki; After execution of the above commands, I create a table in schema "data_schema" using the "postgres" superuser. But I can't access the created table with user "loki" However, if I execute these command after the table creation: GRANT SELECT  ON ALL TABLES    IN SCHEMA public, data_schema TO greenadm_read; GRANT SELECT  ON ALL SEQUENCES IN SCHEMA public, data_schema TO greenadm_read; GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public, data_schema TO greenadm_read; it works as expected with read acces to user "loki".  it seem that the problem is related to the "ALTER DEFAULT..." commands I simply can't phantom what I'm doing wrong. (it's probably some newbie error :-/ ) -- Med venlig hilsen / Kind regards Bo Victor Thomsen