Engineering Guide · updated 2026-11-26
Data Masking for DPDP Readiness: A Developer's Guide
A staging test needs realistic behaviour, but it rarely needs a customer’s original contact details. Walk through one small PostgreSQL copy and see exactly what a developer can check before sharing it.
What Rule 6(1)(a) asks of a Data Fiduciary
Under India’s Digital Personal Data Protection Act, 2023, section 8(5) addresses reasonable safeguards against a personal data breach. Rule 6(1)(a) of the 2025 Rules gives examples of appropriate data security measures: encryption, obfuscation, masking and virtual tokens mapped to personal data. The safeguard covers processing by the Data Fiduciary, including processing on its behalf. The appropriate measures depend on the processing involved.
Under Rule 1(4), Rule 6 takes effect in May 2027, eighteen months after Gazette publication. Other parts of Rule 6 address safeguards such as access control and monitoring. Masking a staging copy addresses one engineering task within that wider responsibility.
Prepare a synthetic source and an empty target
Use two disposable PostgreSQL databases and a compatible pg_dump on the runner. In the source only, create this fictional customer with a setup role. Give the CLI source role read access. Set SUBVEIL_SOURCE_URL and SUBVEIL_TARGET_URL to the separate databases, and supply a secret SUBVEIL_MASK_KEY through your environment.
CREATE TABLE public.customers ( id integer PRIMARY KEY, email text NOT NULL, support_note text);INSERT INTO public.customers VALUES (1, '[email protected]', 'Synthetic support note');Generate and review the policy
In a fresh working directory run init, choosing PostgreSQL when prompted. Inspect its suggestions. A generic text column such as support_note can hold identifying details even when discovery returns no hint.
subveil init --schemas public --out subveil.yamlFor this one-table fixture, keep the generated connection and seed settings. Set the subset and table rules below in subveil.yaml. Copy the fixture table in full so the test exercises the row. Replace the entire free-text note and mask the email.
subset: full_tables: - public.customerstables: public.customers: columns: email: transformer: email domain: example.test support_note: transformer: redact value: "[REDACTED]"Plan the copy, pull and verify
Review the plan for unexpected tables and uncovered fields before pulling. Run verification against the resulting target with the same configuration and pull summary.
subveil plan --config subveil.yamlsubveil pull --config subveil.yamlsubveil verify --config subveil.yaml --strictVerification checks foreign keys, uniqueness, counts against the pull summary and known residual patterns in sampled text and JSON. Strict mode also fails on warnings or skipped checks. A passing sample can miss rare values, unexpected formats and identifying combinations. For this fixture, run the following query on the target and expect one copied row and one matching row.
SELECT count(*) AS copied, count(*) FILTER (WHERE email LIKE '%@example.test' AND support_note = '[REDACTED]') AS matchingFROM public.customers;Keep the receipt and interpret the result
Keep the reviewed policy version, pull receipt and verification result together. The receipt records the run, policy hash, counts and masked-column names. Offline receipts use the masking key for HMAC authentication. Cloud-linked receipts use the Cloud token for ingestion. A free-text reason can travel with the receipt, so use a ticket reference without personal details.
For this fixture, the strict run checks one row count, one unique constraint and two text columns. The fixture has no foreign keys, so a passing referential integrity result covers zero relationships.
The unchanged customer ID can still link records, and deterministic masks can link repeated inputs. Irreversible anonymization requires considering whether people can still be identified from the whole dataset and other available information. Neither a receipt nor a successful verification establishes that outcome or certifies DPDP compliance.
FAQ
Frequently asked questions
The rule lists examples of appropriate security measures. Choose controls for the data and processing involved, review the resulting copy and document the remaining risks.
Try it on your own database.
Run the free CLI on your own runner with PostgreSQL, MySQL or MariaDB.