Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cwFKS-0006h4-8R for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Apr 2017 21:52:32 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cwFKR-0002fI-Mg for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Apr 2017 21:52:31 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cwFKQ-0002f9-Ss for pgsql-hackers@postgresql.org; Thu, 06 Apr 2017 21:52:31 +0000 Received: from 104-190-1-44.lightspeed.sndgca.sbcglobal.net ([104.190.1.44] helo=joeconway.com) by makus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cwFKO-0000Cq-26 for pgsql-hackers@postgresql.org; Thu, 06 Apr 2017 21:52:29 +0000 Received: from [72.214.29.243] (account jconway@joeconway.com HELO [192.168.4.41]) by joeconway.com (CommuniGate Pro SMTP 6.1.4) with ESMTPSA id 18320975; Thu, 06 Apr 2017 14:52:24 -0700 Subject: Re: partitioned tables and contrib/sepgsql To: Tom Lane References: <20170309144718.GE9812@tamriel.snowman.net> <81ddcddc-b9f6-9d80-19c4-c9270fc71fd5@joeconway.com> <426dde50-a6ef-d53c-0607-c0766afd6698@joeconway.com> <3b0f0a27-0ccf-7298-5365-87d685eeea42@joeconway.com> <19352.1491368287@sss.pgh.pa.us> <6d700f91-6bcb-9092-c897-501c7228975f@joeconway.com> <19727.1491408240@sss.pgh.pa.us> <1a7685fb-2aa8-8d01-4c50-c102335d3b12@2ndquadrant.com> <22437.1491412750@sss.pgh.pa.us> <1711d370-b578-7f8d-f4b5-f8662e! 5808fb@joeconway.com> <11037.1491492598@sss.pgh.pa.us> <623bcaae-11! 2e-ced0-8c22-a84f75ae0c53@joeconway.com> <4897.1491507340@sss.pgh.pa.us> Cc: Mike Palmiotto , Peter Eisentraut , Robert Haas , Stephen Frost , "pgsql-hackers@postgresql.org" From: Joe Conway Openpgp: id=4EA5B4659ED59CC9538139A5332B7E68B699434A Message-ID: <63551fd7-6cdf-d1d7-95dd-c3be0283790d@joeconway.com> Date: Thu, 6 Apr 2017 14:52:24 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <4897.1491507340@sss.pgh.pa.us> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="h4cPtfR9bghNkHCADKW2ReCef4FxB50tx" X-Pg-Spam-Score: -0.9 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --h4cPtfR9bghNkHCADKW2ReCef4FxB50tx Content-Type: multipart/mixed; boundary="K3VDLD1cppq5rb7pfCL0tfw8XjSk1ANLN"; protected-headers="v1" From: Joe Conway To: Tom Lane Cc: Mike Palmiotto , Peter Eisentraut , Robert Haas , Stephen Frost , "pgsql-hackers@postgresql.org" Message-ID: <63551fd7-6cdf-d1d7-95dd-c3be0283790d@joeconway.com> Subject: Re: [HACKERS] partitioned tables and contrib/sepgsql References: <20170309144718.GE9812@tamriel.snowman.net> <81ddcddc-b9f6-9d80-19c4-c9270fc71fd5@joeconway.com> <426dde50-a6ef-d53c-0607-c0766afd6698@joeconway.com> <3b0f0a27-0ccf-7298-5365-87d685eeea42@joeconway.com> <19352.1491368287@sss.pgh.pa.us> <6d700f91-6bcb-9092-c897-501c7228975f@joeconway.com> <19727.1491408240@sss.pgh.pa.us> <1a7685fb-2aa8-8d01-4c50-c102335d3b12@2ndquadrant.com> <22437.1491412750@sss.pgh.pa.us> <1711d370-b578-7f8d-f4b5-f8662e! 5808fb@joeconway.com> <11037.1491492598@sss.pgh.pa.us> <623bcaae-11! 2e-ced0-8c22-a84f75ae0c53@joeconway.com> <4897.1491507340@sss.pgh.pa.us> In-Reply-To: <4897.1491507340@sss.pgh.pa.us> --K3VDLD1cppq5rb7pfCL0tfw8XjSk1ANLN Content-Type: multipart/mixed; boundary="------------22721BCCFF000B5B68B81645" This is a multi-part message in MIME format. --------------22721BCCFF000B5B68B81645 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 04/06/2017 12:35 PM, Tom Lane wrote: > Joe Conway writes: >> Any thoughts on whether 0001a and 0001b ought to be backpatched? I'm >> thinking not given the lack of past complaints but it might make sense= >> to do. >=20 > I think 0001a absolutely needs to be, because it is fixing what is real= ly > an ABI violation: sepgsql_needs_fmgr_hook is supposed to return our not= ion > of bool, but as things stand it's returning _Bool (which is why the > compiler is complaining). Now we might get away with that on most > hardware, but on platforms where those are different widths, it's possi= ble > to imagine function-return conventions that would make it fail. >=20 > 0001b seems to only be needed for compilers that aren't smart enough > to see that tclass won't be referenced for RELKIND_INDEX, so it's > just cosmetic. Ok, committed/pushed that way. I found some missing bits in the 0002 patch -- new version attached. Will wait on new regression tests before committing, but I expect we'll have those by end of today and be able to commit the rest tomorrow. Joe --=20 Crunchy Data - http://crunchydata.com PostgreSQL Support for Secure Enterprises Consulting, Training, & Open Source Development --------------22721BCCFF000B5B68B81645 Content-Type: text/x-diff; name="0002-add-partitioned-table-support-to-sepgsql.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0002-add-partitioned-table-support-to-sepgsql.patch" Add partitioned table support to sepgsql The new partitioned table capability added a new relkind, namely RELKIND_PARTITIONED_TABLE. Update sepgsql to treat this new relkind exactly the same way it does RELKIND_RELATION. Issue raised by Stephen Frost and initial patch by Mike Palmiotto. Review by Tom Lane and Robert Haas, and editorializing by me. Discussion: https://postgr.es/m/flat/623bcaae-112e-ced0-8c22-a84f75ae0c53= %40joeconway.com diff --git a/contrib/sepgsql/dml.c b/contrib/sepgsql/dml.c index bc17089..b643720 100644 *** a/contrib/sepgsql/dml.c --- b/contrib/sepgsql/dml.c *************** check_relation_privileges(Oid relOid, *** 190,195 **** --- 190,196 ---- switch (relkind) { case RELKIND_RELATION: + case RELKIND_PARTITIONED_TABLE: result =3D sepgsql_avc_check_perms(&object, SEPG_CLASS_DB_TABLE, required, *************** check_relation_privileges(Oid relOid, *** 225,231 **** /* * Only columns owned by relations shall be checked */ ! if (relkind !=3D RELKIND_RELATION) return true; =20 /* --- 226,232 ---- /* * Only columns owned by relations shall be checked */ ! if (relkind !=3D RELKIND_RELATION && relkind !=3D RELKIND_PARTITIONED_= TABLE) return true; =20 /* diff --git a/contrib/sepgsql/label.c b/contrib/sepgsql/label.c index 1a8f884..6239800 100644 *** a/contrib/sepgsql/label.c --- b/contrib/sepgsql/label.c *************** exec_object_restorecon(struct selabel_ha *** 779,785 **** case RelationRelationId: relForm =3D (Form_pg_class) GETSTRUCT(tuple); =20 ! if (relForm->relkind =3D=3D RELKIND_RELATION) objtype =3D SELABEL_DB_TABLE; else if (relForm->relkind =3D=3D RELKIND_SEQUENCE) objtype =3D SELABEL_DB_SEQUENCE; --- 787,794 ---- case RelationRelationId: relForm =3D (Form_pg_class) GETSTRUCT(tuple); =20 ! if (relForm->relkind =3D=3D RELKIND_RELATION || ! relForm->relkind =3D=3D RELKIND_PARTITIONED_TABLE) objtype =3D SELABEL_DB_TABLE; else if (relForm->relkind =3D=3D RELKIND_SEQUENCE) objtype =3D SELABEL_DB_SEQUENCE; *************** exec_object_restorecon(struct selabel_ha *** 803,809 **** case AttributeRelationId: attForm =3D (Form_pg_attribute) GETSTRUCT(tuple); =20 ! if (get_rel_relkind(attForm->attrelid) !=3D RELKIND_RELATION) continue; /* no need to assign security label */ =20 objtype =3D SELABEL_DB_COLUMN; --- 812,819 ---- case AttributeRelationId: attForm =3D (Form_pg_attribute) GETSTRUCT(tuple); =20 ! if (get_rel_relkind(attForm->attrelid) !=3D RELKIND_RELATION && ! get_rel_relkind(attForm->attrelid) !=3D RELKIND_PARTITIONED_TABLE)= continue; /* no need to assign security label */ =20 objtype =3D SELABEL_DB_COLUMN; diff --git a/contrib/sepgsql/relation.c b/contrib/sepgsql/relation.c index ab98a9b..59a6d9b 100644 *** a/contrib/sepgsql/relation.c --- b/contrib/sepgsql/relation.c *************** sepgsql_attribute_post_create(Oid relOid *** 54,65 **** ObjectAddress object; Form_pg_attribute attForm; StringInfoData audit_name; =20 /* ! * Only attributes within regular relation have individual security ! * labels. */ ! if (get_rel_relkind(relOid) !=3D RELKIND_RELATION) return; =20 /* --- 54,66 ---- ObjectAddress object; Form_pg_attribute attForm; StringInfoData audit_name; + char relkind =3D get_rel_relkind(relOid); =20 /* ! * Only attributes within regular relations or partition relations hav= e ! * individual security labels. */ ! if (relkind !=3D RELKIND_RELATION && relkind !=3D RELKIND_PARTITIONED_= TABLE) return; =20 /* *************** sepgsql_attribute_drop(Oid relOid, AttrN *** 135,142 **** { ObjectAddress object; char *audit_name; =20 ! if (get_rel_relkind(relOid) !=3D RELKIND_RELATION) return; =20 /* --- 136,144 ---- { ObjectAddress object; char *audit_name; + char relkind =3D get_rel_relkind(relOid); =20 ! if (relkind !=3D RELKIND_RELATION && relkind !=3D RELKIND_PARTITIONED_= TABLE) return; =20 /* *************** sepgsql_attribute_relabel(Oid relOid, At *** 167,174 **** { ObjectAddress object; char *audit_name; =20 ! if (get_rel_relkind(relOid) !=3D RELKIND_RELATION) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("cannot set security label on non-regular columns"))); --- 169,177 ---- { ObjectAddress object; char *audit_name; + char relkind =3D get_rel_relkind(relOid); =20 ! if (relkind !=3D RELKIND_RELATION && relkind !=3D RELKIND_PARTITIONED_= TABLE) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("cannot set security label on non-regular columns"))); *************** sepgsql_attribute_setattr(Oid relOid, At *** 209,216 **** { ObjectAddress object; char *audit_name; =20 ! if (get_rel_relkind(relOid) !=3D RELKIND_RELATION) return; =20 /* --- 212,220 ---- { ObjectAddress object; char *audit_name; + char relkind =3D get_rel_relkind(relOid); =20 ! if (relkind !=3D RELKIND_RELATION && relkind !=3D RELKIND_PARTITIONED_= TABLE) return; =20 /* *************** sepgsql_relation_post_create(Oid relOid) *** 291,296 **** --- 295,301 ---- switch (classForm->relkind) { case RELKIND_RELATION: + case RELKIND_PARTITIONED_TABLE: tclass =3D SEPG_CLASS_DB_TABLE; break; case RELKIND_SEQUENCE: *************** sepgsql_relation_post_create(Oid relOid) *** 333,339 **** true); =20 /* ! * Assign the default security label on the new relation */ object.classId =3D RelationRelationId; object.objectId =3D relOid; --- 338,345 ---- true); =20 /* ! * Assign the default security label on the new regular or partitioned= ! * relation. */ object.classId =3D RelationRelationId; object.objectId =3D relOid; *************** sepgsql_relation_post_create(Oid relOid) *** 341,350 **** SetSecurityLabel(&object, SEPGSQL_LABEL_TAG, rcontext); =20 /* ! * We also assigns a default security label on columns of the new regu= lar ! * tables. */ ! if (classForm->relkind =3D=3D RELKIND_RELATION) { Relation arel; ScanKeyData akey; --- 347,356 ---- SetSecurityLabel(&object, SEPGSQL_LABEL_TAG, rcontext); =20 /* ! * We also assign a default security label on columns of a new table. */ ! if (classForm->relkind =3D=3D RELKIND_RELATION || ! classForm->relkind =3D=3D RELKIND_PARTITIONED_TABLE) { Relation arel; ScanKeyData akey; *************** sepgsql_relation_drop(Oid relOid) *** 413,425 **** { ObjectAddress object; char *audit_name; ! uint16_t tclass =3D 0; ! char relkind; =20 - relkind =3D get_rel_relkind(relOid); switch (relkind) { case RELKIND_RELATION: tclass =3D SEPG_CLASS_DB_TABLE; break; case RELKIND_SEQUENCE: --- 419,431 ---- { ObjectAddress object; char *audit_name; ! uint16_t tclass =3D 0; ! char relkind =3D get_rel_relkind(relOid); =20 switch (relkind) { case RELKIND_RELATION: + case RELKIND_PARTITIONED_TABLE: tclass =3D SEPG_CLASS_DB_TABLE; break; case RELKIND_SEQUENCE: *************** sepgsql_relation_drop(Oid relOid) *** 479,485 **** /* * check db_column:{drop} permission */ ! if (relkind =3D=3D RELKIND_RELATION) { Form_pg_attribute attForm; CatCList *attrList; --- 485,491 ---- /* * check db_column:{drop} permission */ ! if (relkind =3D=3D RELKIND_RELATION || relkind =3D=3D RELKIND_PARTITIO= NED_TABLE) { Form_pg_attribute attForm; CatCList *attrList; *************** sepgsql_relation_relabel(Oid relOid, con *** 521,531 **** { ObjectAddress object; char *audit_name; ! char relkind; uint16_t tclass =3D 0; =20 ! relkind =3D get_rel_relkind(relOid); ! if (relkind =3D=3D RELKIND_RELATION) tclass =3D SEPG_CLASS_DB_TABLE; else if (relkind =3D=3D RELKIND_SEQUENCE) tclass =3D SEPG_CLASS_DB_SEQUENCE; --- 527,536 ---- { ObjectAddress object; char *audit_name; ! char relkind =3D get_rel_relkind(relOid); uint16_t tclass =3D 0; =20 ! if (relkind =3D=3D RELKIND_RELATION || relkind =3D=3D RELKIND_PARTITIO= NED_TABLE) tclass =3D SEPG_CLASS_DB_TABLE; else if (relkind =3D=3D RELKIND_SEQUENCE) tclass =3D SEPG_CLASS_DB_SEQUENCE; *************** sepgsql_relation_setattr(Oid relOid) *** 585,590 **** --- 590,596 ---- switch (get_rel_relkind(relOid)) { case RELKIND_RELATION: + case RELKIND_PARTITIONED_TABLE: tclass =3D SEPG_CLASS_DB_TABLE; break; case RELKIND_SEQUENCE: --------------22721BCCFF000B5B68B81645-- --K3VDLD1cppq5rb7pfCL0tfw8XjSk1ANLN-- --h4cPtfR9bghNkHCADKW2ReCef4FxB50tx Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJY5riYAAoJEDfy90M199hlKVsP/R8CBEi+nMiH1ZR0t3iJQ/jt CNXo9kWgeNqMCP4OUDds8dKIu6X9fyVPI0txryasUWFPdS1EYNkwnxvdVt9+H3hC J3L3rnZt1h+0Inns9ZxBsYX5g+BjrPNX+k4NsI/b6nx+vJTYteis/JjZip7Se/Fs GyEpSrdCkzQZFAd/kyZNQ3sGuMrRw6eq0c58rHzrCL5ax8WlEZbUVPPZPK8EXd18 vXD+TdmROYEDvGICqWMDoI0hV+59eQULVEyuvt3LF2E5jCv0E7eUCUwpMqlTlWvz XiWDrbULb+asLYWPzZKkTd4+gVNF547DY6zLe4XZRLKZsWMAtJ6Fs00ig6szfy5k 0jY7nmgf7xhwFPwpRJOpL1f/a0lE7mbjfZe0kHfM2Xjb652jqVosSA4SjkrUEiUJ KjMdnESs5K+6Z1MpPyhw0fV90Ag838ptvQY5TVSKC2Bj/l9itKeDV3UoUoFF5W0n tgr4RjNLnlze6z968NWEiJEtGQlEtJwiw+BONbWWEB55JvJpFHlKuLOw2UgVDyra ddoTESp5URQOFwFZT210MNcDr2gok2DD4r9wyGwBm/7crbZW5omiRhDjbBC+RtNv RWcUTQTc7qCGK3dMWTDVVXRrF9PHs8RLmJy5EHHHsKnXm5OirtZJUElBL9pKrkjt xWcBa1LbQr8iqTidIbD6 =a0nY -----END PGP SIGNATURE----- --h4cPtfR9bghNkHCADKW2ReCef4FxB50tx--