Skip to content

Commit 1553c56

Browse files
Merge pull request #418 from diffix/cristian/misc
Reject unsupported column types during AID labeling.
2 parents 1d385dd + 88d65e0 commit 1553c56

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## Version 1.0.3
4+
- Reject unsupported column types during AID labeling.
5+
36
## Version 1.0.2
47
- Allow casts between `int4` and `int8`.
58
- Allow more metadata discovery queries.

docs/admin_guide.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ CALL diffix.mark_personal('transactions', 'sender_acct', 'receiver_acct');
7979
```
8080
labels the table `transactions` as personal, and labels the `sender_acct` and `receiver_acct` columns as AID columns.
8181

82+
The currently supported types for AID columns are: `integer`, `bigint`, `text` and `varchar`.
83+
8284
The procedure `diffix.unmark_table(table_name)` clears the labels for the table and all its AID columns.
8385

8486
## Settings

src/auth.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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+
153168
static 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))

test/expected/admin.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ SET pg_diffix.strict = true;
3737
SET pg_diffix.top_count_max = 3;
3838
NOTICE: [PG_DIFFIX] Bounds must differ by at least 1. Set other bound to make it valid.
3939
SET pg_diffix.top_count_max = 4;
40+
-- Reject unsupported column types during AID labeling
41+
SECURITY LABEL FOR pg_diffix ON COLUMN test_customers.discount IS 'aid';
42+
ERROR: [PG_DIFFIX] AID label can not be set on target column because the type is unsupported
4043
-- Restriction on users with access level below `direct`
4144
SET ROLE diffix_test;
4245
SET pg_diffix.session_access_level = 'anonymized_trusted';

test/sql/admin.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ SET pg_diffix.strict = true;
2020
SET pg_diffix.top_count_max = 3;
2121
SET pg_diffix.top_count_max = 4;
2222

23+
-- Reject unsupported column types during AID labeling
24+
SECURITY LABEL FOR pg_diffix ON COLUMN test_customers.discount IS 'aid';
25+
2326
-- Restriction on users with access level below `direct`
2427
SET ROLE diffix_test;
2528
SET pg_diffix.session_access_level = 'anonymized_trusted';

0 commit comments

Comments
 (0)