Docs cipi.yml Web panel API MCP Guides Compare GitHub Telegram channel
  1. Docs
  2. Cipi Agent & AI
  3. Database anonymizer

Database anonymizer

Copy production data without personal data.

Cipi Agent & AI

The anonymizer gives you a copy of production that looks real but contains no real people. Developers, QA, staging and contractors get the same tables, volumes and relations, with e-mails, names, phones, addresses and notes replaced by Faker values. MySQL, MariaDB and PostgreSQL are supported.

It lives inside your Laravel app (cipi/agent), runs as a queued job, and is safe by construction: the raw dump is deleted as soon as it's processed, outputs are 0600, database passwords travel in the environment, never on a command line, and the download link expires.

Step 1 of 5Request

You ask for a dump in one of three ways: cipi-cli prod db anonymize myapp --email you@example.com from your laptop, a POST /cipi/db with the anonymizer token, or php artisan cipi:anonymize on the server.

The HTTP request returns {"status":"queued"} at once: the work happens in the background.

Use caseWhy it fits
Local developmentRealistic data on every laptop, no production e-mails
Staging and previewsProduction structure and volume, PII replaced
QA and demosReproduce bugs that depend on real relations, without GDPR risk
ContractorsShare a SQL file instead of production access

Anonymizer vs backups#

Anonymizer (cipi/agent)Backups (Cipi API)
ScopeOne Laravel app's databaseAny database on the server
OutputSQL with fake values in sensitive columnsFull compressed backup, real data
AuthCIPI_ANONYMIZER_TOKEN (per app)Sanctum token with dbs-manage
ForPeople who need realistic dataDisaster recovery, cloning

Use both: backups for operations, anonymized dumps for humans.

Requirements#

RequirementWhy
cipi/agent installedThe anonymizer is part of the agent
A queue workerPOST /cipi/db dispatches a job; without a worker nothing runs
mysqldump / mariadb-dump / pg_dumpFound on PATH, or set CIPI_MYSQLDUMP / CIPI_PG_DUMP
Laravel mail (MAIL_*)The download link only travels by e-mail
anonymization.json on the serverIn ~/.db/ (or ~/.cipi/), outside the repository

Setup#

As the app user on the server (SSH as the app user), or remotely with cipi-cli apps artisan myapp …:

bash
composer require cipi/agent                   # commit, push, deploy
php artisan cipi:service anonymize --enable
php artisan cipi:generate-token anonymize
php artisan cipi:init-anonymize --scan        # proposes a config from your schema
php artisan cipi:anonymize-audit              # config vs live database

--scan proposes a transformation for every column that looks like personal data (e-mails, names, phones, addresses, IPs, tokens, passwords, tax ids, card data, free text) and empties operational tables (sessions, jobs, failed_jobs, password_reset_tokens, personal_access_tokens, Telescope, Pulse). Foreign keys and timestamps are never touched. The file is written to ~/.db/anonymization.json with mode 0640 and is never deployed.

The audit fails on unknown tables, columns or transformations, warns about password columns not set to password, and lists uncovered columns that look personal, with a suggestion. Run it after every migration.

Configuration#

Lookup order: CIPI_ANONYMIZER_CONFIG, then ~/.db/anonymization.json, then ~/.cipi/anonymization.json.

json
{
  "transformations": {
    "users": {
      "name": "fakeName",
      "email": { "type": "fakeEmail", "unique": true, "consistent": true },
      "password": "password",
      "remember_token": "null",
      "phone": "mask:3,2"
    },
    "orders": {
      "customer_email": { "type": "fakeEmail", "consistent": true },
      "card_last_four": "numerify:####",
      "internal_notes": "fakeParagraph"
    }
  },
  "truncate": ["sessions", "jobs", "failed_jobs", "password_reset_tokens"],
  "options": { "faker_locale": "en_US", "consistent": true, "seed": "change-me" }
}

Keys under transformations are tables, nested keys are columns. Columns not listed are copied unchanged, which is how ids, enums and business fields survive. NULL stays NULL (except with fixed).

FlagEffect
consistentSame original, same fake value, across tables and runs with the same seed: users.email still joins orders.customer_email
uniqueNo duplicates in the column; default for fakeEmail, fakeSafeEmail, fakeUserName, fakeUuid, fakeToken, fakeIban
truncateKeeps the table, drops its rows
passwordEvery row gets the hash of options.password (computed once), so developers can log in

Transformations#

php artisan cipi:anonymize --transformations prints the catalogue.

TransformationOutput
fakeName, fakeFirstName, fakeLastName, fakeUserNameNames
fakeEmail, fakeSafeEmailE-mail (fakeSafeEmail uses example.com)
fakeCompany, fakeJobTitleCompany, job title
fakeAddress, fakeStreetAddress, fakeCity, fakeState, fakePostcode, fakeCountry, fakeCountryCodePostal data
fakePhoneNumberPhone
fakeDate, fakeDateTimeY-m-d, Y-m-d H:i:s
fakeUrl, fakeDomainURL, domain
fakeParagraph, fakeSentence, fakeText[:len], fakeWordFree text
fakeIban[:CC], fakeCreditCardNumberBanking data in test ranges
fakeIpv4, fakeIpv6, fakeMacAddress, fakeUserAgentNetwork identifiers
fakeUuid, fakeToken[:len], fakeIdentifierUUID, hex token, tax-id-like value
fakeLatitude, fakeLongitude, fakeNumber[:digits], fakeBooleanNumbers
numerify:###, lexify:???, bothify:?#Patterns (# digit, ? letter)
passwordHash of options.password
null, empty, fixed:value, redactNULL, '', a constant, [REDACTED]
hash[:len], mask:first,last, keepSeeded SHA-256, partial mask (j*******om), unchanged

Options#

OptionDefaultMeaning
hash_algorithmautoApp Hash driver, or bcrypt, argon2id, argon2i, argon2d
passwordpasswordPlaintext behind every password column
faker_localeen_USe.g. it_IT, de_DE
consistentfalseDefault for all columns
seednullKeep it private; change it for a different dataset
gzipfalse.sql.gz output
connectionnullAnother config/database.php connection
dump_args[]Extra dump flags, one per entry

Anonymization is opt-in per column. PII in a JSON column, a blob or a column you forgot is copied verbatim. Watch metadata, settings and audit tables.

Delivery by e-mail#

The API never returns the download URL: the e-mail is the only channel, and it goes only to the email in the request (no CC, no fallback). Success sends a signed link valid for CIPI_ANONYMIZER_TTL minutes (default 15); failure sends the error and the job id.

It uses your app's Laravel mail (MAIL_*), not the server's cipi smtp. Test it before the first export:

bash
php artisan tinker --execute="Mail::raw('test', fn (\$m) => \$m->to('you@example.com')->subject('Mail test'));"

{"status":"queued"} only means the job was queued. If nothing arrives, check storage/logs/laravel.log and php artisan queue:failed. The file may already be in storage/cipi/.

HTTP API#

MethodEndpointAuthPurpose
POST/cipi/dbBearer tokenValidate the config, queue a job ({"email", "gzip"})
POST/cipi/db/userBearer tokenFind users.id from a production e-mail (ids survive anonymization)
GET/cipi/db/{token}Signed URLDownload; expires after the TTL
bash
curl -sS -X POST "$APP_URL/cipi/db" \
    -H "Authorization: Bearer $CIPI_ANONYMIZER_TOKEN" \
    -H "Accept: application/json" -H "Content-Type: application/json" \
    -d '{"email": "developer@example.com"}'
{"status":"queued","email":"developer@example.com","link_valid_minutes":15}

curl -sS -L -o anonymized.sql "<signed url from the e-mail>"
HTTPMeaningFix
403Bad or missing tokencipi:generate-token anonymize
404Service disabled or no configcipi:service anonymize --enable, cipi:init-anonymize
400Invalid anonymization.json (all errors listed)Fix it; cipi:anonymize-audit prints the same list
422Missing emailSend {"email": "…"}
410Download link expiredRequest a new dump
500DB error or dump tool missingLaravel logs, CIPI_MYSQLDUMP / CIPI_PG_DUMP

From your laptop#

cipi-cli drives the same flow through the Cipi API: you name the app, it reads APP_URL, CIPI_ROUTE_PREFIX and the anonymizer token from the app's .env, and calls the agent. No SSH, no token in your shell history.

bash
cipi-cli prod db anonymize myapp --email dev@example.com
→ Requesting anonymized dump of 'myapp' via https://myapp.example.com/cipi/db
✓ Anonymization job queued for 'myapp'

cipi-cli db anonymize download "<signed url>" -o myapp.sql
✓ Saved myapp.sql (24.5 MB)

cipi-cli db anonymize download "<signed url>" -o - | mysql -u root myapp_local

Every failure names its fix (service disabled, token missing, custom or Node app, redirect to another host: pass --url). The API token needs apps-view and apps-env, plus apps-artisan for remote setup.

On the server, without HTTP#

bash
php artisan cipi:anonymize                    # → storage/cipi/anonymized_<timestamp>.sql
php artisan cipi:anonymize --gzip
php artisan cipi:anonymize <config> <output.sql>
php artisan cipi:anonymize --check            # validate + audit, no dump

Writes the file directly (no e-mail), reports rows transformed per table, tables emptied and warnings, and exits non-zero on failure. Good for cron and scripts.

Security checklist#

  • Keep CIPI_ANONYMIZER_TOKEN in a secrets manager; rotate it after team changes; disable the service when unused.
  • Tell recipients the shared password, and never use a real one in options.password.
  • Use consistent: true with a private seed.
  • Run cipi:anonymize-audit after every migration.
  • Any API token with apps-env can read the anonymizer token: scope tokens.
  • Verify a dump: grep for a known production e-mail. It must not appear.
  • Never commit anonymization.json: it maps your schema.