Skip to content
Database anonymizer
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
docker
src
tests
.gitignore
.travis.yml
LICENSE
README.md
composer.json
phpunit.mysql.xml.dist

README.md

Database anonymizer

Build Status codecov Scrutinizer Code Quality

Why ?

General Data Protection Regulation (GDPR) imposes strict rules in the domain of information storage and treatment. You must not treat the users' personal data unless there is a strong necessity. In case you want to dump a production database in order to use it during development you cannot store or use peronal data in a dumped database anymore. You must delete or anonymize personal information before importing a production database in your developpment setting.

How ?

Launch one command provided by our database anonymizer before dumping a production database and it will replace personal information with random but meaningful data. The good point is that you can specify the fields to anonymize and how they will be anonymized:

webnet_fr_database_anonymizer:  # required part of configuration
  tables:
    users:                      # table name
      primary_key: [id]         # indicate primary key
      fields:
        email:                  # field's name to anonymize
          generator: email      # chose the one of dozens generators
          unique: ~             # any option to pass to generator
        first_name:             # another field to anonymize
          generator: first_name # generator

primary_key entry is optional and can be inferred automatically. You can indicate a composite primary key or any column with a unique non-null value.

What generators are available ?

Name Class Example Options
constant Constant value, 3.1459
address Address 9, chemin Manon Begue 03427 Bouvier uniuqe, locale
city City Loiseau uniuqe, locale
country Country Pays-Bas uniuqe, locale
post_code PostCode 14594 uniuqe, locale
street_address StreetAddress 5, impasse Lagarde uniuqe, locale
email Email laure58@tele2.fr uniuqe, locale
datetime DateTime 2019-03-11 02:14:50 uniuqe, format
first_name FirstName Julien uniuqe, locale
lorem Lorem Dolores qui rerum explicabo ab animi sed eveniet facere... uniuqe, max_nb_chars (default is 200)
password Password ~'KknuLr_ uniuqe
phone_number PhoneNumber +33 7 77 82 00 38 uniuqe, locale

No PHP in your environment ?

Then take advantage of Docker.

  1. Install Docker.

  2. Place the docker/Dockerfile in an empty folder. Delete unnecessary extension installation (MySQL, PostgreSQL, SQL Seriver) to speed up the docker build.

  3. Create the anonymizer configuration in, say, config.yaml.

  4. Build an image.

docker build -t webnetfr/anonymizer .
  1. Run anonymization.
docker run --volume <absolute_path_to_local_config>:<absolute_path_to_config_in_container> \
    webnetfr/anonymizer \
    php vendor/bin/database-anonymizer --no-interaction --url <database url> <path_to_config_in_container>

Where:

  • <absolute_path_to_local_config>
  • <absolute_path_to_config_in_container> is a path for your configuraion in the container accessible by anonymizer. I suggest you to always use /var/www/anonymizer/config.yaml
  • <database url> is the URL to your database (e.g. mysql://user:password@host:port/name). Check out the command options if you prefer to pass the host, port, user, password values in separate options.
  • <path_to_config_in_container> is the same as <absolute_path_to_config_in_container> but you can indicate the path relative to /var/www/anonymizer. That said you can simply put config.yaml if you used /var/www/anonymizer/config.yaml in <absolute_path_to_config_in_container>.

Imagine you downloaded the docker/Dockerfile into an empty folder and created conf.yml next to it. Your command may be:

docker run --volume $(pwd)/conf.yaml:/var/www/anonymizer/config.yaml \
    webnetfr/anonymizer \
    php vendor/bin/database-anonymizer -n -Umysql://root:pass@localhost/db config.yaml

Tip: check out the variety of different options Docker provides you with. For example you may add the --net=host option to share your machine's network with the container.

Tip: you can run and connect to the container with this command :

docker run --volume $(pwd)/conf.yaml:/var/www/anonymizer/config.yaml -it \
    webnetfr/anonymizer bash
You can’t perform that action at this time.