Skip to main content

Anonymization of data in pg_dump

Project description

pg_stage

A utility for generating a database dump, the data in which will be obfuscated. This dump can be used in development and stage servers without fear of their theft.

How does it work?

The utility processes the output of the pg_dump command line by line and decides whether to obfuscate data at the level of comments to a table or column.

Usage example

  1. You need to create a file with approximately the following contents:
# main.py
from pg_stage.obfuscator import Obfuscator


obfuscator = Obfuscator(locale='ru_RU')
obfuscator.run()
  1. Add comments to a column or table:
COMMENT ON COLUMN table_1.first_name IS 'anon: {"mutation_name": "first_name"}';
  1. Run pg_dump and redirect the stream to the running script process:
pg_dump -d database | python3 test_obf.py > dump.sql
  1. After that you will get the obfuscated data in the table

Supported types of obfuscation

You can see the current list here.

Why did I write my utility?

I also adhere to the rule that you do not need to place third-party plugins in the working database for its security (most utilities are in the form of database extensions).

Also, in similar utilities, I could not find the functionality for uniform obfuscation of data in related tables. This prompted me to write my own utility that will be able to obfuscate data in related tables with the same result by a foreign key.

Example:

COMMENT ON COLUMN table_1.first_name IS 'anon: {"mutation_name": "first_name", "relations": [{"table_name": "table_1", "column_name": "last_name", "from_column_name": "id", "to_column_name": "id"}]}';

where relations - links on tables where it is necessary to obfuscate fields according to the current field.

Thanks for the inspiration

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pg_stage-0.1.8.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pg_stage-0.1.8-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file pg_stage-0.1.8.tar.gz.

File metadata

  • Download URL: pg_stage-0.1.8.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for pg_stage-0.1.8.tar.gz
Algorithm Hash digest
SHA256 7154179966bc3bd0f3a1eb040b2db89c7021fd951258c4a80f05a0a24e2e7cc9
MD5 055e052ab5242dd40c371d664bb04490
BLAKE2b-256 6811c9b1efeda59e7d6b214531615229aed1d134c412e058fc95b7221a71d6c0

See more details on using hashes here.

File details

Details for the file pg_stage-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: pg_stage-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for pg_stage-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 686859bdd989a9fdbad3ba644bfafcdb08f725aef51bbbb73d7449a06cedd333
MD5 4921099629444f07864c5b4ac4639cdc
BLAKE2b-256 24eab63ab5bb41d25e32d787174fb254e71b6c33aaf446ce0c41cac6da085fdb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page