tacticmedia/greenmask-bundle

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

Maintainers

Package info

github.com/tacticmedia/greenmask-bundle

Type:symfony-bundle

pkg:composer/tacticmedia/greenmask-bundle

Transparency log

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2026-08-23 05:25 UTC

This package is auto-updated.

Last update: 2026-08-24 05:07:41 UTC


README

Packagist PHP License

TL;DR: Declare anonymisation rules directly on your Doctrine entities, and let this bundle write the dump.transformation section of your greenmask configuration for you. No more PII headaches. Turnkey dump and restore solution. Great for grabbing production data and restoring it in non-production environment where sensitive stuff does not belong.

Greenmask anonymises a PostgreSQL dump by applying a named transformer to each column you list in its configuration file. Maintaining that list by hand is the problem: it lives far away from the entities, it names raw tables and columns, and it goes stale the moment 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 turns the attributes into a greenmask configuration:

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, each covering the transformer's full parameter surface. Anything you leave alone is not written, so greenmask's own defaults keep applying.

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

Non-LLM-slop contributions and issues are most definitely welcome.

License

MIT. See LICENSE.

One more thing

This package is brought to you by Tactic Media, a South Australian software development business.

We love to help businesses become more efficient by automating tasks that shouldn't have been done by a human in the first place.

Head over to our website to check out what we do, and if you think we can help you give your employees more time to spend on something more creative, let's talk