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.

Content

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 main.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.2.0.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

pg_stage-0.2.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pg_stage-0.2.0.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.8

File hashes

Hashes for pg_stage-0.2.0.tar.gz
Algorithm Hash digest
SHA256 76e6a8dc5dbab220c38e80e25e71c156b3d077784a43dc2de451947548dc3251
MD5 b88b1f8cba3d7a2dfdfb781f3e3f3dee
BLAKE2b-256 a2dbe24629f3d653f874fbd1623d36a3d243f20376ea8e49c123b6fadbce577b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pg_stage-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.8

File hashes

Hashes for pg_stage-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7074b4b2c841e986d21c87d29fcbe5ab6261547441364b80a8c9ee0b339c48c7
MD5 eb4b4805577c8a1deac43827c068b3ce
BLAKE2b-256 ace12b7933e2a84b4617cf23e6a958fbe0e7ce537b386539ceaf9ea183bd70aa

See more details on using hashes here.

Supported by

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