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 1pom10-0005SV-2a for pgsql-bugs@arkaria.postgresql.org; Tue, 18 Apr 2023 14:09:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pom0y-0005bD-4J for pgsql-bugs@arkaria.postgresql.org; Tue, 18 Apr 2023 14:09:00 +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 1pom0x-0005b2-Kb for pgsql-bugs@lists.postgresql.org; Tue, 18 Apr 2023 14:08:59 +0000 Received: from mail-yb1-xb29.google.com ([2607:f8b0:4864:20::b29]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1pom0q-003e1H-Q4 for pgsql-bugs@lists.postgresql.org; Tue, 18 Apr 2023 14:08:58 +0000 Received: by mail-yb1-xb29.google.com with SMTP id a11so6770662ybm.3 for ; Tue, 18 Apr 2023 07:08:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1681826930; x=1684418930; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:to :from:date:from:to:cc:subject:date:message-id:reply-to; bh=FRXY3NQPaAyD+jR6/inF2Z9n/TkYUblF2/bmtCWmQLo=; b=GjSVEKXMV0+vWBUmdwVQYmw77LPCOrYjBRvD/0ihCtIYWWds+xdmgvMfbxr9smaLW5 gOCtMOZKbcm4xRhsiwslPjaWNqk81nEZ5/sAuyAsqAURyOpRCMtTPsW4NG+OY3UaYdis hvgiN6QuhsCHkNkWj/siw1yaAF+mqpLmMXgjE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681826930; x=1684418930; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:to :from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=FRXY3NQPaAyD+jR6/inF2Z9n/TkYUblF2/bmtCWmQLo=; b=QvO4rv+DwhW9zjWgvG/oQf90MzFMBFQi81fkBlE4Ocbu+PqJoq0LJ349aoZ30+zaga X3QenuDti2+LC1VNBvg2xCxlqKBQFHIbci12ocrggpqG1S5jKZ2A0cVI5bUepM8WCHPY M4kN6HX6tJry/GoKpQsBFuhlk+AOClSAljEG2kxOPqvw/GmZVbERTHOEOcXfVNJeY3aK 2MuEaMJJ0jTjmAMttJfnbcUqEYO+d+y1glmAY9Yfike6HJj902a0rHvn7FDXgvp+FhSW 4r/P3Jr01yyCn3RUXdr8QrX+Ij0wNmZ2q1VIBDGkRKxzt/JyYxiIYuPzjtBbuFcvwrhX 9rtA== X-Gm-Message-State: AAQBX9cV+MswO+qM/+xxHtynj4+pToONK1Pl+Zu3gGJJvRTqvhEHu/XW FTD1gnXusfzyW0HIemFSt5ToGA== X-Google-Smtp-Source: AKy350Z6Fps/UuNdNLnEYnDxWVkzIQjGl8i1K3/Y4pfCoD0gC1asYWqgS8C7D0TBGCwNLI+dQ2eGGA== X-Received: by 2002:a25:fc6:0:b0:b8b:d724:ccd5 with SMTP id 189-20020a250fc6000000b00b8bd724ccd5mr16313675ybp.56.1681826930468; Tue, 18 Apr 2023 07:08:50 -0700 (PDT) Received: from rfd.leadboat.com ([2600:1702:a20:5750::2e]) by smtp.gmail.com with ESMTPSA id u41-20020a25ab2c000000b00b7767ca7487sm3407393ybi.36.2023.04.18.07.08.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Apr 2023 07:08:49 -0700 (PDT) Date: Tue, 18 Apr 2023 07:08:46 -0700 From: Noah Misch To: moray.henderson@om.org, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17901: Unexpected 'permission denied' error depending on which template used to create database Message-ID: <20230418140846.GA1477639@rfd.leadboat.com> References: <17901-93eacb513e503f43@postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <17901-93eacb513e503f43@postgresql.org> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Apr 17, 2023 at 11:33:28AM +0000, PG Bug reporting form wrote: > In PostgreSQL 15.2 a user with 'CREATEDB NOINHERIT' permission can create a > new database and tables from template1, but receives 'permission denied' > when creating tables in a database created from template0. Is that expected > behaviour? (I'm a little hazy on exactly how 'noinherit' is supposed to be > used: I... inherited it!) > > The cluster was initialised with ICU locales: > .\initdb --locale-provider icu --icu-locale en-GB --locale en-GB-x-icu -A > md5 -U postgres -W -D 'C:\ProgramData\PostgreSQL\15\data' > I do not believe template1 has been modified from its default since the > cluster was initialised. > > postgres=> SELECT * FROM version(); > version > ------------------------------------------------------------ > PostgreSQL 15.2, compiled by Visual C++ build 1914, 64-bit > (1 row) > postgres=# CREATE ROLE dbadmin LOGIN CREATEDB NOINHERIT PASSWORD > 'Passw0rd'; > CREATE ROLE > postgres=# \c - dbadmin > Password for user dbadmin: > You are now connected to database "postgres" as user "dbadmin". > postgres=> CREATE DATABASE d0 TEMPLATE template0; > CREATE DATABASE > postgres=> CREATE DATABASE d1 TEMPLATE template1; > CREATE DATABASE > postgres=> \c d1 > You are now connected to database "d1" as user "dbadmin". > d1=> CREATE TABLE t (i int); > CREATE TABLE > d1=> \c d0 > You are now connected to database "d0" as user "dbadmin". > d0=> CREATE TABLE t (i int); > ERROR: permission denied for schema public > LINE 1: create table t (i int); It is expected. Your d0 public schema has permissions like this: [local] test=# \dn+ public List of schemas Name │ Owner │ Access privileges │ Description ────────┼───────────────────┼────────────────────────────────────────┼──────────────────────── public │ pg_database_owner │ pg_database_owner=UC/pg_database_owner↵│ standard public schema │ │ =U/pg_database_owner │ Role dbadmin is automatically a member of pg_database_owner while in a database it owns. Since role dbadmin is NOINHERIT, the privileges of pg_database_owner don't normally apply. The privileges are accessible with SET ROLE, so do this: \c d0 dbadmin SET ROLE pg_database_owner; GRANT ALL ON SCHEMA public TO dbadmin; SET ROLE dbadmin; CREATE TABLE t (i int); Regarding d1 behaving differently, I'm guessing this instance was upgraded from v14 or earlier. In d1, "\dn+ public" will look different, because it has the access privileges migrated from the earlier version. The v14 access privileges were more permissive.