22
33#include "catalog/pg_inherits.h"
44#include "catalog/pg_namespace.h"
5+ #include "catalog/pg_type.h"
56#include "fmgr.h"
67#include "miscadmin.h"
78#include "utils/acl.h"
@@ -144,26 +145,38 @@ bool is_aid_column(Oid relation_oid, AttrNumber attnum)
144145 "Anonymization label `%s` not supported on objects of type `%s`", \
145146 seclabel, getObjectTypeDescription(object))
146147
147- static void verify_pg_features (Oid relation_id )
148+ static void verify_pg_features (Oid relation_oid )
148149{
149- if (has_subclass (relation_id ) || has_superclass (relation_id ))
150+ if (has_subclass (relation_oid ) || has_superclass (relation_oid ))
150151 FAILWITH ("Anonymization over tables using inheritance is not supported." );
151152}
152153
154+ static bool is_aid_type_supported (Oid relation_oid , AttrNumber attnum )
155+ {
156+ switch (get_atttype (relation_oid , attnum ))
157+ {
158+ case INT4OID :
159+ case INT8OID :
160+ case TEXTOID :
161+ case VARCHAROID :
162+ return true;
163+ default :
164+ return false;
165+ }
166+ }
167+
153168static void object_relabel (const ObjectAddress * object , const char * seclabel )
154169{
155170 if (!superuser ())
156- FAILWITH_CODE (ERRCODE_INSUFFICIENT_PRIVILEGE , "only a superuser can set anonymization labels" );
171+ FAILWITH_CODE (ERRCODE_INSUFFICIENT_PRIVILEGE , "Only a superuser can set anonymization labels" );
157172
158173 if (seclabel == NULL )
159174 return ;
160175
161176 if (is_personal_label (seclabel ) || is_public_label (seclabel ))
162177 {
163178 if (is_personal_label (seclabel ))
164- {
165179 verify_pg_features (object -> objectId );
166- }
167180
168181 if (object -> classId == RelationRelationId && object -> objectSubId == 0 )
169182 return ;
@@ -173,7 +186,13 @@ static void object_relabel(const ObjectAddress *object, const char *seclabel)
173186 else if (is_aid_label (seclabel ))
174187 {
175188 if (object -> classId == RelationRelationId && object -> objectSubId != 0 )
189+ {
190+ if (!is_aid_type_supported (object -> objectId , object -> objectSubId ))
191+ FAILWITH_CODE (ERRCODE_FEATURE_NOT_SUPPORTED ,
192+ "AID label can not be set on target column because the type is unsupported" );
176193 return ;
194+ }
195+
177196 FAIL_ON_INVALID_OBJECT_TYPE (seclabel , object );
178197 }
179198 else if (is_anonymized_trusted_label (seclabel ) || is_anonymized_untrusted_label (seclabel ) || is_direct_label (seclabel ))
0 commit comments