Search by

tacticmedia / greenmask-bundle

janklan

Symfony bundle that generates a greenmask anonymization configuration from transformer attributes on Doctrine entity properties.

Package info

github.com/tacticmedia/greenmask-bundle

Type:symfony-bundle

pkg:composer/tacticmedia/greenmask-bundle

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

dev-main 2026-09-03 10:39 UTC

This package is auto-updated.

Last update: 2026-09-03 10:40:06 UTC


README

Packagist PHP License

Summary: Declare anonymisation rules on your Doctrine entities, and this bundle writes the dump.transformation section of your greenmask configuration. It removes the manual upkeep of rules for personally identifiable information (PII) and, with greenmask, gives a complete dump and restore process. Use it to take production data and restore it in a non-production environment, where sensitive data must not be present.

Greenmask anonymises a PostgreSQL dump by applying a named transformer to each column you list in its configuration file. Maintaining that list manually is the problem: it is separate from the entities, it names raw tables and columns, and it becomes outdated when somebody adds a field.

This bundle moves the declaration to the property:

use Doctrine\ORM\Mapping as ORM;
use TacticMedia\GreenmaskBundle\Attribute\Transformer;
use TacticMedia\GreenmaskBundle\Attribute\Transformer\PartialEnum;

#[ORM\Entity]
#[ORM\Table(name: 'user', schema: 'core')]
class User
{
    #[ORM\Column(name: 'display_name')]
    #[Transformer\Masking(PartialEnum::NAME)]
    private string $displayName;

    #[ORM\Column]
    #[Transformer\RandomEmail(preserve: ['admin@example.com'], domains: ['disabled.localhost'])]
    private string $email;
}

One command generates the greenmask configuration from the attributes:

bin/console greenmask:generate-config config/greenmask.dist.yml config/greenmask.yml
dump:
  transformation:
    -
      schema: core
      name: user
      transformers:
        -
          name: Masking
          params:
            type: name
            column: display_name
        -
          name: RandomEmail
          when: 'record.email != "admin@example.com"'
          params:
            domains:
              - disabled.localhost
            column: email

The generator reads Doctrine metadata only, so it needs no database connection and runs inside a Docker image build.

All 51 greenmask transformers have an attribute, and each attribute covers every parameter of its transformer. An argument you do not set is not written, so the greenmask default applies.

Requirements

  • PHP 8.3 or newer
  • Symfony 7.4 or 8.x
  • Doctrine ORM 3.4 or newer

Installation

composer require tacticmedia/greenmask-bundle

See Installation for bundle registration.

Documentation

  • Installation - requirements, Composer setup, bundle registration
  • Attributes - the index of all 51 transformer attributes, the arguments they share, and how to add your own
  • Generating the configuration - the command, the template contract, running it in a Docker build
  • Backup and restore - creating an anonymised dump and restoring it
  • Demo - a runnable application: seed, generate, dump, restore, compare

Contributions

Contributions and issues are welcome. Unreviewed LLM-generated content is not.

License

MIT. See LICENSE.

Maintainer

Tactic Media, a South Australian software development business, maintains this package.

We help businesses become more efficient by automating tasks that a human should not have to do.

See our website for what we do. If you think we can give your employees more time for creative work, contact us.