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
- 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.execute()
- Add comments to a column or table:
COMMENT ON COLUMN table_1.first_name IS 'anon: {"mutation_name": "first_name"}';
- Run pg_dump and redirect the stream to the running script process:
pg_dump -d database | python3 test_obf.py > dump.sql
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pg_stage-0.1.5.tar.gz
.
File metadata
- Download URL: pg_stage-0.1.5.tar.gz
- Upload date:
- Size: 15.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a06e45a5759903be33a83509166c107ea28be71ca05d03d2e463d389215f7188 |
|
MD5 | 541fe2b6f2839c3dabd848172f60789e |
|
BLAKE2b-256 | f43dcc6009e87701e9888421db386610f12bc560f3e818c459ffdd751ae21ab5 |
File details
Details for the file pg_stage-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: pg_stage-0.1.5-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7ba63429e18436466e17e64fe7a20e62a3d50881193c1505e0de4047eb8e855 |
|
MD5 | e9f76250741619d221df0f50bf9232d1 |
|
BLAKE2b-256 | 0971ff89ef352d5c706fae0c10baae2cff42372186d8b83f0d39148ec1fce506 |