tacticmedia / greenmask-bundle
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
Requires
- php: >=8.3
- doctrine/doctrine-bundle: ^2.13 || ^3.0
- doctrine/orm: ^3.4
- symfony/config: ^7.4 || ^8.0
- symfony/console: ^7.4 || ^8.0
- symfony/dependency-injection: ^7.4 || ^8.0
- symfony/filesystem: ^7.4 || ^8.0
- symfony/http-kernel: ^7.4 || ^8.0
- symfony/yaml: ^7.4 || ^8.0
Requires (Dev)
- ext-pdo_sqlite: *
- ergebnis/composer-normalize: ^2.52
- friendsofphp/php-cs-fixer: ^3.95.19
- phpstan/phpstan: ^2.2.8
- phpstan/phpstan-doctrine: ^2.0.28
- phpstan/phpstan-phpunit: ^2.0.18
- phpstan/phpstan-symfony: ^2.0.20
- phpunit/phpunit: ^13.3
- rector/rector: ^2.6.3
- roave/security-advisories: dev-latest
- symfony/framework-bundle: ^7.4 || ^8.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-03 10:40:06 UTC
README
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.