Greenmask Documentation

repository·main·Indexed 23 days ago

https://github.com/greenmaskio/greenmask

A stateless logical dump tool for PostgreSQL that supports data masking, obfuscation, and transformation. Greenmask provides a CLI for performing logical dumps, restoring databases, and managing dumps via S3 or directory storage. It includes features for data integrity validation, transformer inspection, and secure secret handling through environment variable interpolation.

Tokens
119.4K
Snippets
249
Records
454
Agent score
82%

What's inside Greenmask

  1. What is Greenmask?

    main

    Greenmask is an open-source CLI utility designed for logical PostgreSQL database backup dumping, anonymization, synthetic data generation, and restoration. It is built using ported PostgreSQL libraries to ensure reliability and is designed to be stateless, meaning it does not require any changes to your existing database schema.

    Key characteristics include:

    • Statelessness: Operates as a logical dump without impacting the source schema.
    • Backward Compatibility: Dumps created by Greenmask are compatible with standard PostgreSQL utilities like pg_restore.
    • Type Safety: Uses database drivers for encoding/decoding to ensure data integrity and format preservation.
    • Parallelism: Supports parallel execution for both dumping and restoration to increase performance.
    • Cross-platform: Built in Go, making it easy to execute on any platform without dependencies.
  2. Overview of Greenmask Standard Transformers

    main
    Standard transformers in Greenmask are ready-to-use data anonymization methods that require minimal configuration. They allow you to transform sensitive data into anonymized formats using predefined behaviors. These transformers can be applied to columns during the data anonymization process to ensure compliance and security without needing custom code for common data types.
  3. Overview of Advanced Transformers in Greenmask

    main

    Advanced transformers are modifiable anonymization methods in Greenmask that allow users to implement custom logic for data masking. Unlike standard transformers, these can be adjusted using custom functions to meet specific requirements.

    Currently available advanced transformers include:

    • Json: Used to modify JSON content using delete and set operations.
    • Template: Executes a user-provided Go template and applies the resulting string to a specified column.
    • TemplateRecord: Modifies entire records by executing a Go template and applying changes via the PostgreSQL driver.
  4. Overview of Standard Transformers in Greenmask

    main
    Standard transformers are ready-to-use data transformation methods in Greenmask that require minimal to no customization. They are used to mask, replace, or generate synthetic data for various data types (e.g., strings, dates, numbers, locations, and PII) during the data processing pipeline. These transformers can be applied to specific fields to ensure data privacy or to create realistic test datasets.
  5. Understand the Greenmask configuration structure

    main

    Greenmask configuration is organized into six primary sections:

    • common: Settings applicable to both dump and restore commands.
    • log: Configuration for the logging subsystem.
    • storage: Settings defining where dump data is stored.
    • dump: Settings for the dump command, including pg_dump options and transformation parameters.
    • restore: Settings for the restore command, including pg_restore options and restoration scripts.
    • custom_transformers: Definitions for custom transformers that communicate via stdin and stdout.
  6. Configure storage options in Greenmask

    main

    Greenmask extends the traditional pg_dump directory format by introducing a storages abstraction, allowing backups to be sent to locations other than the local filesystem.

    Supported storage types:

    • s3: Supports any S3-compatible storage system (e.g., AWS S3, MinIO, etc.).
    • directory: The standard local filesystem directory.
  7. Use INSERT commands with error handling and conflict management

    main

    By default, Greenmask uses COPY for restoration. You can use the --inserts flag to use INSERT commands instead. This is slower but allows for advanced error handling:

    1. Error Exclusion: When combined with an error and constraint exclusion list in your configuration, you can skip specific errors and continue the restoration.
    2. Conflict Handling: Use --on-conflict-do-nothing to add ON CONFLICT DO NOTHING to statements (works for unique/exclusion constraints).
    3. Identity Columns: Use --overriding-system-value to allow inserting data into GENERATED ALWAYS AS IDENTITY columns.

    Warning: INSERT commands are significantly slower than COPY.

  8. Restore tables in topological order

    main

    Use the --restore-in-order flag to ensure that dependent tables are not restored until the tables they depend on have been restored. This is useful when the schema already exists with foreign keys.

    Note on Cycles: Greenmask cannot guarantee order if the schema contains cyclic dependencies. In such cases, you must temporarily remove the foreign key constraints to break the cycle, restore the data, and then re-add the constraints.

  9. Configure gender_mapping and fallback_gender for dynamic mode

    main

    When using RandomPerson in dynamic mode (where gender is derived from another column), you can control how values are interpreted:

    gender_mapping

    A dictionary that maps values found in the source column to specific genders. The default mapping is:

    {
      "Male": [
        "male",
        "M",
        "m",
        "man",
        "Man"
      ],
      "Female": [
        "female",
        "F",
        "f",
        "w",
        "woman",
        "Woman"
      ]
    }

    fallback_gender

    Specifies the gender to use if the value in the source column is not found in the gender_mapping. This is required only when the gender parameter is used in dynamic mode. Default is Any.

  10. How Greenmask transformers work

    main

    Transformers in Greenmask are methods applied to anonymize sensitive data. They are categorized into several functional groups that determine how data is generated, how parameters are sourced, and how transformations are applied to specific datasets.

    Key categories include:

    • Dynamic parameters: Transformers that use input parameters to generate random data.
    • Transformation engines: The underlying generation mechanism, which can be Hash (deterministic) or random (randomization).
    • Parameters templating: Generating static parameter values from templates.
    • Parameters env vars interpolation: Injecting environment variable values into transformer parameters during the dump process.
    • Transformation conditions: Logic that determines if a transformer should be applied to a specific row or column.
    • Transformation Inheritance: A mechanism to define transformations once and apply them to partitioned tables or tables with foreign keys.
    • Standard transformers: Basic transformers requiring only input parameters.
    • Advanced transformers: Complex transformers that can be customized using custom functions.