Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eh72X-0006CT-J1 for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Feb 2018 05:04:01 +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 1eh72W-0008Eg-JY for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Feb 2018 05:04:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eh72W-0008EW-9n for pgsql-hackers@lists.postgresql.org; Thu, 01 Feb 2018 05:04:00 +0000 Received: from mail-it0-x242.google.com ([2607:f8b0:4001:c0b::242]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eh72S-00022E-8s for pgsql-hackers@postgresql.org; Thu, 01 Feb 2018 05:03:59 +0000 Received: by mail-it0-x242.google.com with SMTP id 68so2298566ite.4 for ; Wed, 31 Jan 2018 21:03:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=de17n8qb/17H0XMwM5IB9kmamGUx+xANFCGqtAK0o2Y=; b=Xv/OxQk4ENoF8u1jOqOMpuuAn6wVI+EQ6iR5XwHNynHgUWHMU8fRU9dxDqakVHtYO4 ll5Sbwio99wVyEEJXNdCM0he3N2zTAoF8JchEUI7bGDzsPC9lnTiciorn4J5NpG5pg2J J6fW96rZ5Bq4md7nzQ8MRCqMZSAYShnr9ufhk7yYo8TH2VYxhROySjonJ93bZPVKeoyu 1EynayoUV18Wki3AkrY31y2XoLHSiaRrcPGfQLyTbSihm9vA/6ST4zDmQ2Sals41kcqt pj2qTAJKLrja341diN27DyMjuGaCB3dZeE5eJwYyGP16vAesGFa7IWF4EKtEC2SCkPU/ /22w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=de17n8qb/17H0XMwM5IB9kmamGUx+xANFCGqtAK0o2Y=; b=AdwuSylp3y7g0UVAt/w1A9EVl6C+qSepf72fHufTvM4zQqYafjli5UNk5iijdCUEHk 4Cv1lD82dZyhNAs2z9jv+c0qXRTa/DM3aIwkPMxC5gcAtW4lih2t9x+VJPpzfTkkMSdt EUI4msquMNzEnvuWOd1fg/qA4Pbuk4fTy1Y2004Nitn+gowswHoOLJ4okSMqNv1IfKPZ H6gxu13hdF5aG3lECqZyOXcXzvc4MDpIaFyXXf8REoGoYYfXz5ek2GwycSzHUPAu+ECW ToC/h2idsstIWwNZbdFsb/Lrqm8IAfXpqb2B4LvnYJ+lHph4opXgTtC18LIEeo2mCE/v OW8A== X-Gm-Message-State: AKwxytfaAQdjyzTPHv+v8BPOkr0HSVXTCiDHw6rCHg7OqXbc87motO+W hBbULlii3p59JRvzH2ObAKU= X-Google-Smtp-Source: AH8x226YsuAt012FSTGZkLgbwWMvsVcz8v2IUmJWaNgbHkxvhcuXt2owJX/YI6YjJ1sItkYJcL9m4Q== X-Received: by 10.36.105.17 with SMTP id e17mr39295075itc.84.1517461434485; Wed, 31 Jan 2018 21:03:54 -0800 (PST) Received: from paquier.xyz (c137162.net61215.cablenet.ne.jp. [61.215.137.162]) by smtp.gmail.com with ESMTPSA id i22sm8597068ioo.39.2018.01.31.21.03.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Jan 2018 21:03:53 -0800 (PST) Date: Thu, 1 Feb 2018 14:03:48 +0900 From: Michael Paquier To: Peter Eisentraut Cc: Jaime Casanova , pgsql-hackers Subject: Re: [HACKERS] generated columns Message-ID: <20180201050348.GA6398@paquier.xyz> References: <1bc948f8-3bab-6c54-50af-c0723a75b85f@2ndquadrant.com> <20180116063546.GA3679@paquier.xyz> <48502d9b-60c4-5b10-40a2-e34f562132b4@2ndquadrant.com> <20180119051804.GC12826@paquier.xyz> <2e3d5147-16f8-af0f-00ab-4c72cafc896f@2ndquadrant.com> <20180131131804.GB1586@paquier.xyz> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="aM3YZ0Iwxop3KEKx" Content-Disposition: inline In-Reply-To: <20180131131804.GB1586@paquier.xyz> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --aM3YZ0Iwxop3KEKx Content-Type: multipart/mixed; boundary="FL5UXtIhxfXey3p5" Content-Disposition: inline --FL5UXtIhxfXey3p5 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jan 31, 2018 at 10:18:04PM +0900, Michael Paquier wrote: > On Thu, Jan 25, 2018 at 10:26:55PM -0500, Peter Eisentraut wrote: >> On 1/19/18 00:18, Michael Paquier wrote: >>> +SELECT a, c FROM gtest12; -- FIXME: should be allowed >>> +ERROR: permission denied for function gf1 >>=20 >> This is quite hard to fix and I would like to leave this for a future >> release. >=20 > I have been looking at that case more closely again, and on the contrary > I would advocate that your patch is doing the *right* thing. In short, > if the generation expression uses a function and the user has only been > granted access to read the values, it seems to me that it we should > require that this user also has the right to execute the function. Would > that be too user-unfriendly? I think that this could avoid mistakes > about giving access to unwanted functions when willing to just give a > SELECT right as the function could be doing more operations. Attached is the SQL file I used with test cases for the review. I forgot to attach it yesterday. > Hm. Identity columns and default columns are part of rowtypes. STORED > columns can alsobe part of a row type with little effort, so in order to > be consistent with the all the existing behaviors, it seems to me that > virtually-generated columns should be part of it as well. I have > compiled in the attached SQL file how things behave with your > patch. Only virtually-generated columns show a blank value. The tests used are attached. -- Michael --FL5UXtIhxfXey3p5 Content-Type: application/x-sql Content-Disposition: attachment; filename="generated_cases.sql" Content-Transfer-Encoding: quoted-printable -- Triggers with new and old rows=0ACREATE FUNCTION trigger_show_row() RETU= RNS trigger=0ALANGUAGE plpgsql=0AAS $$=0ABEGIN=0A IF tg_op IN ('DELETE', '= UPDATE') THEN=0A RAISE INFO '%: old =3D %', TG_NAME, OLD;=0A END IF;=0A= IF tg_op IN ('INSERT', 'UPDATE') THEN=0A RAISE INFO '%: new =3D %', TG= _NAME, NEW;=0A END IF;=0A IF tg_op =3D 'DELETE' THEN=0A RETURN OLD;=0A= ELSE=0A RETURN NEW;=0A END IF;=0AEND $$;=0Acreate table tab_generated= (a int,=0A b int generated always as identity,=0A c int default 0,=0A d= int GENERATED ALWAYS AS (c * 2));=0Acreate trigger tab_before=0A after in= sert or update or delete=0A on tab_generated for each row=0A execute proc= edure trigger_show_row();=0Acreate trigger tab_after=0A before insert or u= pdate or delete=0A on tab_generated for each row=0A execute procedure tri= gger_show_row();=0Ainsert into tab_generated values (1);=0Aupdate tab_gener= ated set a =3D 2 where a =3D 1;=0Adelete from tab_generated where a =3D 2;= =0A=0A-- ACLs with virtual column using functions=0ACREATE FUNCTION dummy_i= nt(integer) RETURNS integer=0AAS 'select $1;'=0ALANGUAGE SQL=0AIMMUTABLE ST= RICT;=0ACREATE TABLE tab_generated_acl (=0A a int PRIMARY KEY,=0A b int G= ENERATED ALWAYS AS (dummy_int(a)));=0AREVOKE ALL ON FUNCTION dummy_int(int)= FROM PUBLIC;=0AINSERT INTO tab_generated_acl VALUES (1);=0ACREATE ROLE pop= o;=0AGRANT SELECT (a, b) ON tab_generated_acl TO popo;=0ASET ROLE popo;=0A-= - should not work as no permission to use function=0ASELECT * FROM tab_gene= rated_acl;=0ARESET role;=0A-- With default expression=0ACREATE TABLE tab_de= fault_acl (=0A a int PRIMARY KEY,=0A b int DEFAULT (dummy_int(1)));=0AGRA= NT INSERT (a, b) ON tab_default_acl TO popo; = = =0ASET ROLE popo;=0A-- should not work as no permission to = use function=0AINSERT INTO tab_default_acl VALUES (1);=0A --FL5UXtIhxfXey3p5-- --aM3YZ0Iwxop3KEKx Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAlpyn7QACgkQnvQgOdby QH1n0w/+JLTcH7hgoZZItJNnwAr2hlVonG8tOSVWpPGX1FotMPAFlaGhUMUmLfcy GyPZG1/K1cC3RtWsJsyuT+h8/Ml382uUedBMEKntcf4OUgVZYZhoCTCIFCB3Jcb4 zzHdzOJ/G09u7Ybne3rOOxIg71pCJMAAvPfdG8DAg5rRd78J0lA0z4hutXJE6Pss M1SbWzaprJOXamQ0uqehSNyY6ekqIx7aU0mlB9BNITaUgDu8YeARRsPC0uNObKaf ncgvNwTOMnyVMe427hiuU80yPhHLoP3hQHl7j4urAQVodeUJLnBkKF7EMvulzFgN A4XPyVicMTd03S/+msX19XLrqQgeceiQj9KQU/WUinFZ03SlgdUXkRVHhCQ3DloB TAVsAKANCc1n83WQPcGuO1HUncmrumK5X4UK7su6j0u/2UDLf/5UJVbi3Y5RYOTg h8nUQkvIM7BjUk+Ipuud/MnVW3HY6wC9bG7GcqyKIjoNg6KUM9c5yWaQDn1ms3pT +je7DOdDZqIBz2EpAuZPc24/Z8m9MS0BqSTtY6dYoS+WiNo6gn0uwSWbKqGqclDr n3FQ92UC2boeb/BqUsDf1mjb+syn+KQrEpjNJPKdXDuRrqT2x/ixtlnIvxfUsS3D R0ZdgtGu/kA0EGitUJv4C7xhBdXziJStUGKeYoGGSxKshNsa8yM= =YEIN -----END PGP SIGNATURE----- --aM3YZ0Iwxop3KEKx--