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 1sJvKt-007N84-HC for pgsql-hackers@arkaria.postgresql.org; Wed, 19 Jun 2024 13:26: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 1sJvKq-00GOwJ-Sm for pgsql-hackers@arkaria.postgresql.org; Wed, 19 Jun 2024 13:26:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sJvKp-00GOuL-9G for pgsql-hackers@lists.postgresql.org; Wed, 19 Jun 2024 13:26:49 +0000 Received: from fout8-smtp.messagingengine.com ([103.168.172.151]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sJvKm-002TFK-EO for pgsql-hackers@postgresql.org; Wed, 19 Jun 2024 13:26:47 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id 0C13A138024A; Wed, 19 Jun 2024 09:26:42 -0400 (EDT) Received: from imap48 ([10.202.2.98]) by compute6.internal (MEProxy); Wed, 19 Jun 2024 09:26:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=compiler.org; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1718803602; x=1718890002; bh=mDeCj28rIbE7ubdpY3KNu+n8/5m43UmiZM5Sqe351WE=; b= o7dlXieoyQi8l6gqBBAOIhYjECRKKCP/5kDTy9xPbdLmX/lgbBvX/OwGhLLUCFs3 VgQFjYzuBqUtgpTHm9a1eivXVv6NL8OLcJvzOpqxWIdCSvWb31fX3B+0OxxbPmlr DPA+FvfklJrZcCnQ9U2FBCtN6JGH2BkRMu/7UPUU+KXejYMU8btuMMFGO2RYW4KP cspui2HL9VOwbGKO/o1jBMIUp4d/WzLtA1MlZXVJiym3ER3OEVdOAO/VDj+sBfDQ lq2baZAbBETMsmH9Qx52t8x7KLIfQAxSCXbCkcOsQdw/8x9qHCJ6by1chTIDndwR bPAOII/jtlrDQjZyjdwmag== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1718803602; x= 1718890002; bh=mDeCj28rIbE7ubdpY3KNu+n8/5m43UmiZM5Sqe351WE=; b=k 84g7EGsS+3b5SiHW8/pdIVT++32YYqFk1yghWsIfIHy83P4nRX39Ez7YjiTgOUjX OAll8foepo0XKgj2kWASeXFWORCoVKrSCdVu4PWCDWzVnSSaCmNwdrju16zfPyhF 5/beQ76whzljSkMF83L4w2NMsUnLw6Fuka8aS/bdxDJUyCAcGqfbhorkBAD31DPp SVdE7kvfYnp8COBCjjANNQqN/ztd5NpU3OjYeeek8qXwbZP7Mj+h0f5G7cRP9N0y szy34e3iw0FswMm9815zDH+QZ6Sso3JkIdx83EoLwDH+MxjPhzAsTysi4MOHdNKm sz9TmH656ogjvBol8mpKA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfeeftddgieefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefofgggkfgjfhffhffvvefutgfgse htqhertderreejnecuhfhrohhmpedflfhovghlucflrggtohgsshhonhdfuceojhhovghl segtohhmphhilhgvrhdrohhrgheqnecuggftrfgrthhtvghrnhepleettefgteekudfgke dvffdtveetudefhfffieeutefgffehtdeileehfeehtdeinecuffhomhgrihhnpehpohhs thhgrhdrvghsnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homhepjhhovghlsegtohhmphhilhgvrhdrohhrgh X-ME-Proxy: Feedback-ID: ic6394509:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 9713C31A0065; Wed, 19 Jun 2024 09:26:41 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-522-ga39cca1d5-fm-20240610.002-ga39cca1d MIME-Version: 1.0 Message-Id: <2c4c70ef-6567-4f5a-baa0-e16eb9430572@app.fastmail.com> In-Reply-To: References: <80b16434-b9b1-4c3d-8f28-569f21c2c102@app.fastmail.com> Date: Wed, 19 Jun 2024 15:26:03 +0200 From: "Joel Jacobson" To: "Ranier Vilela" Cc: pgsql-hackers Subject: Re: Add pg_get_acl() function get the ACL for a database object Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Ranier, Thanks for looking at this. I've double-checked the patch I sent, and it works fine. I think I know the cause of your problem: Since this is a catalog change, you need to run `make clean`, to ensure = the catalog is rebuilt, followed by the usual `make && make install`. You also need to run `initdb` to create a new database cluster, with the= new catalog version. Let me know if you need more specific instructions. Best, Joel On Wed, Jun 19, 2024, at 14:59, Ranier Vilela wrote: > Em qua., 19 de jun. de 2024 =C3=A0s 08:35, Joel Jacobson =20 > escreveu: >> Hello hackers, >>=20 >> Currently, obtaining the Access Control List (ACL) for a database obj= ect >> requires querying specific pg_catalog tables directly, where the user >> needs to know the name of the ACL column for the object. >>=20 >> Consider: >>=20 >> ``` >> CREATE USER test_user; >> CREATE USER test_owner; >> CREATE SCHEMA test_schema AUTHORIZATION test_owner; >> SET ROLE TO test_owner; >> CREATE TABLE test_schema.test_table (); >> GRANT SELECT ON TABLE test_schema.test_table TO test_user; >> ``` >>=20 >> To get the ACL we can do: >>=20 >> ``` >> SELECT relacl FROM pg_class WHERE oid =3D 'test_schema.test_table'::r= egclass::oid; >>=20 >> relacl >> --------------------------------------------------------- >> {test_owner=3DarwdDxtm/test_owner,test_user=3Dr/test_owner} >> ``` >>=20 >> Attached patch adds a new SQL-callable functoin `pg_get_acl()`, so we= can do: >>=20 >> ``` >> SELECT pg_get_acl('pg_class'::regclass, 'test_schema.test_table'::reg= class::oid); >> pg_get_acl >> --------------------------------------------------------- >> {test_owner=3DarwdDxtm/test_owner,test_user=3Dr/test_owner} >> ``` >>=20 >> The original idea for this function came from Alvaro Herrera, >> in this related discussion: >> https://postgr.es/m/261def6b-226e-4238-b7eb-ff240cb9c2c9@www.fastmail= .com >>=20 >> On Thu, Mar 25, 2021, at 16:16, Alvaro Herrera wrote: >> > On 2021-Mar-25, Joel Jacobson wrote: >> > >> >> pg_shdepend doesn't contain the aclitem info though, >> >> so it won't work for pg_permissions if we want to expose >> >> privilege_type, is_grantable and grantor. >> > >> > Ah, of course -- the only way to obtain the acl columns is by going >> > through the catalogs individually, so it won't be possible. I think >> > this could be fixed with some very simple, quick function pg_get_ac= l() >> > that takes a catalog OID and object OID and returns the ACL; then >> > use aclexplode() to obtain all those details. >>=20 >> The pg_get_acl() function has been implemented by following >> the guidance from Alvaro in the related dicussion: >>=20 >> On Fri, Mar 26, 2021, at 13:43, Alvaro Herrera wrote: >> > AFAICS the way to do it is like AlterObjectOwner_internal obtains d= ata >> > -- first do get_catalog_object_by_oid (gives you the HeapTuple that >> > represents the object), then >> > heap_getattr( ..., get_object_attnum_acl(), ..), and there you have= the >> > ACL which you can "explode" (or maybe just return as-is). >> > >> > AFAICS if you do this, it's just one cache lookups per object, or >> > one indexscan for the cases with no by-OID syscache. It should be = much >> > cheaper than the UNION ALL query. And you use pg_shdepend to guide >> > this, so you only do it for the objects that you already know are >> > interesting. >>=20 >> Many thanks Alvaro for the very helpful instructions. >>=20 >> This function would then allow users to e.g. create a view to show th= e privileges >> for all database objects, like the pg_privileges system view suggeste= d in the >> related discussion. >>=20 >> Tests and docs are added. > Hi, > For some reason, the function pg_get_acl, does not exist in generated = fmgrtab.c > > So, when install postgres, the function does not work. > > postgres=3D# SELECT pg_get_acl('pg_class'::regclass,=20 > 'atest2'::regclass::oid); > ERROR: function pg_get_acl(regclass, oid) does not exist > LINE 1: SELECT pg_get_acl('pg_class'::regclass, 'atest2'::regclass::... > ^ > HINT: No function matches the given name and argument types. You migh= t=20 > need to add explicit type casts. > > best regards, > Ranier Vilela --=20 Kind regards, Joel