Docs menu

Docs

Quick start

Applies to prodmask Pro 1.0.0-beta.2

From production to a masked staging copy, in four steps. Run them against a replica of production where you can. Each step's output names tables, columns, counts and rules, never values from your data.

First, get your licence: sign up on prodmask.com with your email address and confirm it. The licence arrives by email; put it where prodmask looks for it (Your licence), and install prodmask (Install and verify).

The commands are for a Linux or macOS shell. In PowerShell, set each variable first, as in $env:PRODMASK_PASSWORD = '…', and write the command on one line.

1. Scan, and write a starter config

The free scan finds the personal data and secrets, and writes a starter prodmask.yml:

PRODMASK_PASSWORD='…' prodmask scan --dsn 'mysql://prodmask_ro@replica:3306/shop' --config-out prodmask.yml

Read prodmask.yml before you go on. It holds the scan's rules for each column it flagged, and the platforms it found. The full format is at https://github.com/ProdMask/ProdMask/blob/main/docs/config.md.

The scan also finds links between tables. A polymorphic link's type value, such as App\Models\Order, shows only when it reads as a class name or a plain word and no part of it looks like data. Otherwise the reports and prodmask.yml say (type hidden). The text report lists links only with --verbose; the Markdown and JSON reports always carry them.

2. Make a masking key

prodmask keys new --out prodmask.key

With a stable key, the same data gives the same copy every time, so test fixtures and bug reports keep working across refreshes. Keep the key out of your repository, as you'd keep a password. prodmask reads it from the variable PRODMASK_MASK_KEY by default:

export PRODMASK_MASK_KEY="$(cat prodmask.key)"

Or name the file in prodmask.yml: keys: { mode: stable, key_file: prodmask.key }. For a copy that never repeats, use keys: { mode: per_run } and no key.

A release that changes any fake raises the generators' version, which prodmask.lock records. prodmask copy says so: "the generators are version 2, and the lock's are version 1: fakes can differ", and prodmask plan says the same as it writes a new lock. Copies made after such a release can differ from earlier copies in the values whose fakes changed. The first beta's generators are version 2, and a released version's fakes never change. What the copy finds and replaces in kept text, such as a customer's email quoted in a post, can change in any release that improves detection: those replacements are fakes of the same kind, but which words get them can differ.

3. Plan

PRODMASK_SOURCE_PASSWORD='…' prodmask plan --source-dsn 'mysql://prodmask_ro@replica:3306/shop'

plan reads the source, read-only, decides how copies mask every table, column and key, and writes it to prodmask.lock. It prints the review queue: what could leak, what could break staging, and what it changed so the copy works. Commit prodmask.yml and prodmask.lock, and don't edit the lock by hand.

Each of plan's reads holds its table's metadata lock for up to --timeout, 60 seconds by default, and a schema change that waits for that lock makes later queries of the table wait too. So run plan against a replica, as above, or outside deploy windows.

Rules that give way in published content. In content and config rows, a rule under tables: that generates a value, such as a fake_* mask, redact or hash, gives way to the content default.

  • Secrets, password hashes, payment tokens and session data are cleared.
  • Customer details get fakes linked to nothing else.
  • Everything else is kept, with the customer details found in it replaced.

plan lists every rule that gave way. In the lock, the rule the content default gives such a column or key says why: d6b. To override the content default on purpose, write the rule under rules:, keep: or public:, which apply as written in every row.

Exit status 3 means something blocks the copy: the output names it, and the line of prodmask.yml that gives it, where one does, with what to write there. Change it, and run plan again.

A short unique column keeps its fakes. Some unique columns are too short for any fake or hash to keep 8,192 values apart, such as a code of one or two characters in a primary key or a unique index: a language or a country code. prodmask plan no longer stops there. It keeps prodmask's own fake for the column, and the copy keeps the values unique: it gives each value its own fake before it writes anything.

The review queue lists such a column under "Changed so the copy works", with:

  • how many different values the copy keeps apart in that column alone, such as at least 31 for one character, or 1,000 for two, and about half as many where the column's rule keeps some values as they are;
  • that the column's values are replaced, so codes your app looks up, such as en or GR, won't match in staging;
  • if the column holds codes, not customer details, the line to keep it as it is, such as keep: [ "languages.code" ]. Where the column is one end of a key that joins other tables, the line names every end, since keeping one end alone stops plan with text_key_kinds. Where keeping would keep a secret, or customer details at another end, the review queue gives no line.

The JSON carries the same facts on the entry, as exact_mode, floor and keep.

A unique index that holds another. A unique index that holds every column of another unique index or of the primary key no longer stops plan on its fakes, since the smaller index keeps it unique: two IP address columns in a unique index beside a unique index on the first, for one. The copy still keeps it unique, and creates it as it is.

What plan couldn't read. plan says what went wrong as it read the database. It does so as warnings with their own codes: in the text, in the JSON's warnings and on stderr, in a full plan and under --check and --update.

  • scan_sample: the scan couldn't sample all of a table, named, with why, such as "timed out", so what it found there may be partial.
  • scan_keys: the scan couldn't read all the keys of a key/value table, and plan reads them again itself.
  • source_read_only: the database server can't mark the session read-only. plan still only reads.
  • source_no_timeout: the server has no time limit on a statement, so a slow read goes on running on the server after plan stops waiting for it.
  • source_user_can_write: the user plan reads with can change the database. plan still only reads, but a user that can only read is safer. In CI, the user that runs your migrations usually can change the database. A second user that can only read, for --check, clears this warning.
  • source_dsn_variables: the source's DSN sets session variables, or a character set or collation other than utf8mb4's, which plan doesn't use: "the source DSN's session variables aren't used: sql_big_selects; plan's session sets its own, so the DSN can drop them". It names each, or counts one whose name isn't a plain word, and never gives a value. Database users says more.
  • scan_other and plan_preset_other: counts of the scan's other warnings, which this release doesn't word, so that none is lost.

If the server doesn't keep the session read-only at all, plan refuses to read, and says so. If you reach the server through a proxy, connect to the server itself.

Entries of prodmask.yml that matched nothing. plan lists each entry of prodmask.yml that matched nothing in the database, by its line:

  • a table under tables: or classes: that the database doesn't have;
  • a column or key that a table doesn't have;
  • a pattern under rules:, keep: or public: that matches nothing;
  • a view under views: keep_cross_schema: that the copy doesn't leave out.

Such an entry covers nothing, so a typo there can leave a value unmasked without anything failing. The list is in the review queue, in the JSON as review.unused, and on stderr. It never changes the exit status. Where plan can't be sure which keys a table has, as --check without the masking key often can't, it doesn't list key entries. So an empty list there doesn't mean every key entry matched.

For WordPress and Magento, point the copy at staging's address, or it still links to production:

rewrite_urls:
  - {from: "https://shop.example", to: "https://staging.example"}

Give the site's own address exactly as WordPress stores it, with its www. or without. Where no entry covers it, the copy warns, as in "no entry of rewrite_urls rewrites siteurl in wp_options, so staging may send its visitors to production; add an entry for that address, or set WP_SITEURL in staging's wp-config.php". Staging would then send its visitors to production, its admin login included. Add an entry for that exact address, or set WP_HOME or WP_SITEURL in staging's wp-config.php. For Magento, the warning names a base URL path, such as web/secure/base_url in core_config_data, and asks for an entry.

4. Copy

PRODMASK_SOURCE_PASSWORD='…' PRODMASK_TARGET_PASSWORD='…' prodmask copy \
  --source-dsn 'mysql://prodmask_ro@replica:3306/shop' \
  --target-dsn 'mysql://prodmask_rw@staging-db:3306/shop_staging' --allow-host staging-db

The copy follows the lock. It reads the source in one consistent snapshot, builds the copy aside, and checks it before anything is in place: the values it kept are read for this run's customers' details and live secrets, except text the masking already read whole and left as it was, and dates, key numbers and lists, which the check only counts; and the target must hold every row it wrote. A copy that fails that check exits with status 5, and staging stays as it was. A copy that passes prints what it did, and what it didn't check. Its summary says how many kept values the check read again, how many more the masking had read whole, and how many dates, key numbers and lists it doesn't read; the three add up to the values the copy kept, unless the copy warns of a fault in prodmask.

The copy also switches off what would let staging reach real people: scheduled jobs, mail, payment gateways' live modes and webhooks. Staging accounts get one staging password, printed on a terminal, or written to --staging-password-file elsewhere, such as in CI. Git Bash's window on Windows doesn't count as a terminal, so give --staging-password-file there too.

To write a dump instead, give --dump shop.sql.gz in place of --target-dsn.

If a migration changed the source's schema since the plan, the copy masks the new tables and columns by prodmask.yml and prodmask's own rules, and warns of each. It names each new column your prodmask.yml keeps in customer rows, with the line that keeps it: check what that column holds, then run prodmask plan --update and commit the lock.

A new site, or a new shop, since the plan. Some changes since the plan bring neutralisers the lock doesn't have. For those, the copy stops with exit status 3 before it writes anything.

  • A site gains what brings a neutraliser.

    • What counts:

      • a WordPress site the lock has gains WooCommerce's order tables, and becomes a shop;
      • it gains a table a neutraliser acts on, such as webhooks or scheduled actions;
      • a table prefix gains posts, postmeta or options, and becomes a site.
    • The copy names each table, with every neutraliser it brings:

      the source's schema changed since prodmask.lock was written in a way that brings neutralisers prodmask.lock doesn't have; run prodmask plan:
        wp_3_wc_webhooks, where wc_webhooks acts
        wp_3_woocommerce_order_items makes wp_3_ a shop, where wc_braintree, wc_gateways, wc_memberships_emails, wc_mollie, wc_ppcp_data, wc_square, wc_staff_emails, wc_tracking, wc_woopayments, wcs_duplicate_site and wp_recipients act
    • Run prodmask plan, or prodmask plan --update against a database that has those tables, such as a CI database restored with them.

  • prodmask.yml keeps a switch column of a new site. A site the lock doesn't have is copied as customer data. A line of prodmask.yml that keeps a column there that a neutraliser would act on could let a live setting reach staging:

    the source has a site prodmask.lock doesn't have, and prodmask.yml keeps a column of it where a neutraliser would act, which can hold a live switch; run prodmask plan:
      wp_9_options.option_value (line 12)
      wp_9_wc_webhooks.status, in config rows by prodmask.yml's classes:
    • The columns it guards are the names and values of the new site's options and postmeta. At a new shop, it also guards the status of its webhooks and scheduled actions, unless the lock already has a neutraliser for those tables.
    • Run prodmask plan, which records the site and its neutralisers. An exact keep of such a column then blocks the plan with neutralise_kept, naming its line, so take that line out first.

Otherwise a new site only warns, once per site:

the source has a site prodmask.lock doesn't have, wp_9_, with 15 tables: they're copied as added tables are until prodmask plan --update records the site and its neutralisers; it's a shop, so the copy adds its staff emails set off and Subscriptions' staging lock, as prodmask plan does
  • At a new shop, the copy adds the four rows plan adds at a shop:

    • woocommerce_new_order_settings, woocommerce_cancelled_order_settings and woocommerce_failed_order_settings, each with enabled set to no;
    • wc_subscriptions_siteurl, Subscriptions' staging lock, so Subscriptions stops renewals by itself.

    The check after the copy fails a copy that lacks one. A row that can't go in, as where the table has no integer primary key, isn't added, and the copy warns: "wp_9_options has no row for woocommerce_new_order_settings, which wc_staff_emails can't add there, so a missing switch stays missing". The new-site warning then leaves out its part after the semicolon.

  • New tables of webhooks and scheduled actions. The lock's neutralisers for them also act on new tables of those names, at a new site and at a site the lock has, even where prodmask.yml keeps the column. Active webhooks are disabled and pending actions cancelled there.

  • A neutraliser the lock lacks, as after an upgrade to a release with a new one, gets a warning, once per neutraliser: "prodmask.lock has no entry for this build's neutraliser wc_tracking at wp_options and wp_2_options; a plan against a database that has these tables adds it". Run a plan against a database that has those tables.

When a short column holds more values than its fakes. If the source holds more different values in such a column than its fakes can keep apart, the copy stops before it writes a row, and names the column: how many different values the source holds there, how many its fakes keep apart, and what to do: widen what makes them short, or add the keep: line above if it holds codes. What to widen is the column itself; or, at one end of a key, the key's narrowest end, since every end's fakes are made to fit it, which the copy names; or the index's prefix, where that is shorter than the column. The review queue's count is for the column alone: where another such column of the same kind holds some of the same values, a value takes one fake in both, and each column can hold fewer, which the copy's words say too.

copy's exit statuses: 0, the copy is in place; 1, an error; 2, bad usage; 3, the lock refuses the copy, with what to do; 4, no valid licence; 5, the copy failed verification.

A copy can also stop with exit status 1 when its own writing goes wrong. Its line then ends "this is a fault in prodmask, report it", as in "people.email: the copy wrote the cell with no outcome, so the run stops; this is a fault in prodmask, report it", or "people.email: the copy kept a value in a customer row under the rule fake_email, which doesn't keep, so the run stops; this is a fault in prodmask, report it". No line of prodmask.yml causes it, and no command clears it. The line names the table and the column, never a value: send it to support@prodmask.com.

In CI

To run Pro in CI, download a release from your account, verify it as the install page says, and keep the archive where your CI can fetch it, such as a private artifact store; put the licence in a CI secret.

When a pull request's migration adds tables or columns, run prodmask plan --check against the migrated CI database, never production. It fails when the migration adds a column or a named key that no rule masks, and names it. In tables such as wp_postmeta and wp_usermeta, it only counts new keys unless CI has your masking key: the output says "counted, not named", and the check passes. Give CI the key as a secret if you want those keys judged too; that's a trade, since whoever can read your CI's secrets can then use the key. Add a rule to prodmask.yml, run prodmask plan --update to bring the lock in line, and commit both. Run a full plan against production when the output says "Full plan due".

When --check can't list a table's keys. plan --check reads the keys of each key/value table in the database your pull request migrated, such as wp_usermeta and wp_options.

  • If that read fails, it tries once more. A read that works on the second try passes, with a line on stderr that says so: "listed the keys of wp_usermeta on the second try (the first read: …)".
  • If the second try fails too, the check fails, with exit status 3: the keys it couldn't read could be any, so it can't say none of them needs a rule.
    • The JSON names each such table, with the reason, under check.listing_failed.
    • The text gives each table a line such as "wp_usermeta: listing the CI database's keys failed twice: …; raise --timeout and run it again", where the read ran out of time. Otherwise the line ends "run it again once the CI database answers".
  • If the connection to the database is lost on both tries, the run stops with exit status 1.

When plan can't count a table's parents. To decide which keys of a key/value table hold personal data, plan counts how many people or records each key's rows belong to.

  • If that count fails, plan warns: "couldn't count the parents of wp_postmeta's keys (…); every key it doesn't exempt counts as data".
  • --check then passes those keys, as it passes keys it can only count. So in rows of published content, such as a shop's product details in wp_postmeta, a new key that no rule covers keeps its value in the copy.
  • So when you see that warning, give any new key there a rule, or run the check again.

Upgrading prodmask

"update prodmask". prodmask stops with exit status 3, and ends its message with "update prodmask", when a file needs a newer prodmask than the one you ran:

  • prodmask.lock was written by a newer prodmask;
  • prodmask.yml is for a newer prodmask.

This happens when two machines, or a laptop and CI, run different releases. Install the newer release where it failed. Nothing was copied or written.

"run prodmask plan". prodmask copy stops with exit status 3 and says "run prodmask plan" when the lock is from an older release that left out things the copy now needs. prodmask plan --check and prodmask plan --update say "run a full prodmask plan" for the same lock. Run prodmask plan once against your source, without --check or --update, and commit the new lock. It keeps your fakes as they were. Every lock written before the beta needs this once.

After going back to an older release. prodmask copy keeps working with the lock the newer release wrote. A new plan needs the newer release: an older one refuses to replace that lock, so it can't drop what the newer release decided. prodmask plan --check still runs, and warns that it judged the lock by the older release's rules.