The package rapidly anonymizes large amounts of sensitive data throughout the database.
You can install the package through the composer:
composer require indeev/laravel-rapid-db-anonymizer
In any model that contains sensitive data use Anonymizable;
trait and const ANONYMIZABLE = [];
constant.
class Customer
{
use Anonymizable;
const ANONYMIZABLE = [
'name' => [
'faker' => ['provider' => 'firstName'],
],
];
// ...
}
ANONYMIZABLE
is defined as an array of 'column_name' => [what_to_do]
values.
Truncate table
const ANONYMIZABLE = ['truncate'];
Replace column value with faker's provider (without parameters)
const ANONYMIZABLE = [
'name' => [
'faker' => ['provider' => 'firstName'],
],
// next columns
];
Replace column value with faker's provider (with parameters)
const ANONYMIZABLE = [
'secret_code' => [
'faker' => ['provider' => 'randomNumber', 'params' => [6, true]],
],
// next columns
];
Replace with exact value
- if value of setTo is an array type, it is converted to json string. For instance
['foo' => 'bar']
is converted to{"foo":"bar"}
. - if value of setTo is
null
, it is converted to NULL. Pay special attention that column is set as nullable.
const ANONYMIZABLE = [
'favorite_politician' => [
'setTo' => 'CONFIDENTIAL',
],
'favorite_numbers' => [
'setTo' => [7, 13],
],
'favorite_meals' => [
'setTo' => null,
],
// next columns
];
Replace also NULL values
By default, NULL values are skipped. If you also want to anonymize them, you must add anonymizeNull
to the column with a value true
.
const ANONYMIZABLE = [
'shipping_address' => [
'faker' => ['provider' => 'address'],
'anonymizeNull' => true,
],
// next columns
];
To run anonymization for the entire database (all models with Anonymizable trait) use
php artisan db:anonymize
To run anonymization over a specific model use command with --model=
option
php artisan db:anonymize --model=\\App\\Models\\VerificationCode
To run anonymizing specific columns in the entire database use command with --columns=
option. Individual column names must be separated by comma
php artisan db:anonymize --columns=name,surname
Use a combination of the previous two options to anonymize specific columns above a specific model
php artisan db:anonymize --model=\\App\\Models\\User --columns=name,surname
composer test
You can export config file by:
php artisan vendor:publish --provider="Indeev\LaravelRapidDbAnonymizer\LaravelRapidDbAnonymizerServiceProvider"
In config, you can modify:
- Chunk size (default: 500) - all 500 rows are updated by one query
- Forbidden environments (default: production, prod)
- Custom model directory (default: app/Models)
- Custom model namespace (default: \App\Models)
- Faker's locale (default: en_US)
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email katerinak@indeev.eu instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
This package was generated using the Laravel Package Boilerplate.