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.ymldump:
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: emailThe 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.
- PHP 8.3 or newer
- Symfony 7.4 or 8.x
- Doctrine ORM 3.4 or newer
composer require tacticmedia/greenmask-bundleSee Installation for bundle registration.
- 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 and issues are welcome. Unreviewed LLM-generated content is not.
MIT. See LICENSE.
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.