Skip to content

Commit 02f4939

Browse files
committed
Missing anonymization rule raises exception
* this is to prevent leaking sensitive date stored in columns with type the library cannot anonymize * added anonymization for inet Postgres type
1 parent 15d5045 commit 02f4939

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

pgantomizer/anonymize.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
'numeric': 'floor(random() * 10)',
2121
'character varying': lambda column, pk_name: "'{}_' || {}".format(column, pk_name),
2222
'text': lambda column, pk_name: "'{}_' || {}".format(column, pk_name),
23+
'inet': "'111.111.111.111'"
2324
}
2425

2526

@@ -28,6 +29,10 @@
2829
'ANONYMIZED_DB_PORT')
2930

3031

32+
class MissingAnonymizationRuleError(Exception):
33+
pass
34+
35+
3136
def get_table_pk_name(schema, table):
3237
return schema[table].get('pk', DEFAULT_PK_COLUMN_NAME) if schema[table] else DEFAULT_PK_COLUMN_NAME
3338

@@ -103,7 +108,7 @@ def anonymize_column(cursor, schema, table, column, data_type):
103108
))
104109
logging.debug('Anonymized {}.{}'.format(table, column))
105110
else:
106-
logging.warning('No rule to anonymize type "{}"'.format(data_type))
111+
raise MissingAnonymizationRuleError('No rule to anonymize type "{}"'.format(data_type))
107112

108113

109114
def anonymize_db(schema, db_args):
@@ -116,7 +121,11 @@ def anonymize_db(schema, db_args):
116121
"WHERE table_schema = 'public' AND table_name = '{}'".format(table_name[0]))
117122
for column_name, data_type in cursor.fetchall():
118123
prepare_column_for_anonymization(conn, cursor, table_name[0], column_name, data_type)
119-
anonymize_column(cursor, schema, table_name[0], column_name, data_type)
124+
try:
125+
anonymize_column(cursor, schema, table_name[0], column_name, data_type)
126+
except MissingAnonymizationRuleError:
127+
drop_schema(db_args)
128+
raise
120129

121130

122131
def load_anonymize_remove(dump_file, schema, leave_dump=False, db_args=None):

0 commit comments

Comments
 (0)