Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tceS0-001gW5-Eu for pgsql-bugs@arkaria.postgresql.org; Tue, 28 Jan 2025 05:47:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tceRy-00GgPe-9u for pgsql-bugs@arkaria.postgresql.org; Tue, 28 Jan 2025 05:47:50 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tceRy-00GgPV-20 for pgsql-bugs@lists.postgresql.org; Tue, 28 Jan 2025 05:47:50 +0000 Received: from smtp80.iad3b.emailsrvr.com ([146.20.161.80]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tceRv-001t1u-2Q for pgsql-bugs@lists.postgresql.org; Tue, 28 Jan 2025 05:47:48 +0000 X-Auth-ID: xof@thebuild.com Received: by smtp11.relay.iad3b.emailsrvr.com (Authenticated sender: xof-AT-thebuild.com) with ESMTPSA id B1673400E7; Tue, 28 Jan 2025 00:47:46 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51\)) Subject: Re: Evidence of Ownership Issues During Restoration of Extension Member Objects From: Christophe Pettus In-Reply-To: Date: Mon, 27 Jan 2025 21:47:15 -0800 Cc: pgsql-bugs@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: References: To: AKASH X-Mailer: Apple Mail (2.3776.700.51) X-Classification-ID: e812c832-5afe-4a1f-b3ba-493fb0a23e4f-1-1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Jan 27, 2025, at 21:29, AKASH wrote: > =E2=80=A2 Create a database, install the pg_trgm extension, create = a role (app_user), and change ownership of the similarity function to = app_user. > =E2=80=A2 Export the database pg_dump to create a dump file. > =E2=80=A2 Restore the dump into a target environment where it = app_user does not exist. > =E2=80=A2 Ownership of the similarity function reverts to the = restoring user. > =E2=80=A2 Applications dependent on app_user permissions fail with = permission errors. It's not clear to me exactly why you need to have different parts of an = extension owned by different roles. I believe the correct analogy is = that a table is owned by a single role, but that does not prevent it = from being accessed and used by other roles that have appropriate = permissions. Similarly, there's no need for individual components of = extensions to have different owners. You can grant the right = permissions to the roles that need access to the extension without = having to grant them ownership. If you want more fine-grained access = control, where some roles can use some components of an extension and = others can't, it's best to wrap the extension functions or views in = user-defined wrappers, and then grant permissions appropriately onto = those. In your particular example, that's not a PostgreSQL bug, but a bug in = your process. You need to make sure that the target system has the = correct roles before restoring into it. PostgreSQL doesn't (and I feel = safe to say never will) create roles on the fly, and dumping and = restoring global objects like roles is a separate step from a = pg_dump/pg_restore.=