Data Security and Privacy Engineering

Protecting data end to end: classification, encryption at rest and in transit, key management and HSMs, tokenisation vs encryption vs masking, RBAC vs ABAC and row and column security, DLP, privacy by design, pseudonymisation and anonymisation, PETs, data residency, retention and erasure, and monitoring.

On this page

Simple definition#

Data security protects the confidentiality, integrity and availability of data against unauthorised access, change or loss. Privacy engineering makes sure personal data is collected and used only for legitimate, stated purposes, minimised, and handled according to people’s rights.

The problem#

Data is copied into events, lakes, caches, logs, backups, test environments and now embeddings and prompts. Every copy is a breach waiting to happen. Regulators (GDPR, India’s DPDP Act, PCI DSS, banking secrecy rules) impose heavy fines and reporting duties. The goal is to reduce where sensitive data lives and protect what remains with layered controls.

Step 1: classify#

Level Examples Typical controls
Public Product brochures Integrity only
Internal Org charts, internal docs Authentication
Confidential Customer names, account balances, transactions Encryption, RBAC/ABAC, masking, logging
Restricted Card numbers (PAN), authentication data, Aadhaar or national IDs, health data, keys Tokenisation, HSM, strict need-to-know, segregated environments

Automate discovery and tagging (catalog classifiers, cloud DLP and data security posture management (DSPM) tools), and propagate tags through lineage.

Step 2: protect data in each state#

State Controls
In transit TLS 1.3 everywhere; mTLS service to service; no plaintext Kafka, JDBC or internal HTTP
At rest Disk, database and object-storage encryption with customer-managed keys where required
In use Field- and application-level encryption, tokenisation, masking; confidential computing (TEEs) for highly sensitive processing

Keys: envelope encryption#

Envelope encryption with KMS / HSM
flowchart LR
    APP["Application"] -->|"1 generate data key"| KMS["KMS / HSM<br/>master key never leaves"]
    KMS -->|"2 plaintext DEK + DEK encrypted under KEK"| APP
    APP -->|"3 encrypt data with DEK,<br/>discard plaintext DEK"| STORE["Store ciphertext + encrypted DEK"]
    STORE -.->|"4 decrypt: send encrypted DEK to KMS"| KMS
  • Key encryption keys (KEKs) live in a KMS or HSM (FIPS 140-3). Data encryption keys (DEKs) encrypt the data.
  • Rotate keys, separate duties (key admins are not data admins), log every key use, and consider BYOK or HYOK for regulated workloads.
  • Plan crypto-agility for post-quantum migration. See security architecture.

Tokenisation vs encryption vs masking#

Technique What it does Reversible? Use for
Encryption Ciphertext via key Yes, with the key Storage and transport; fields that are needed back
Tokenisation Replaces the value with a random token; mapping in a secure vault (or vaultless format-preserving tokens) Only via the token service PAN (shrinks PCI scope), national IDs, account numbers in analytics
Format-preserving encryption (FPE) Ciphertext keeps the format (16 digits stays 16 digits) Yes Legacy systems that validate formats
Static masking Irreversibly replaces values in copies No Test and dev data
Dynamic masking Masks at query time based on the user Underlying data unchanged Analysts see XXXX-1234; fraud team sees the full value
Hashing (salted, keyed) One-way digest No Joins on identifiers without revealing them

Access control: RBAC, ABAC and fine-grained security#

  • RBAC: permissions by role (analyst, fraud-investigator). Simple, but suffers role explosion.
  • ABAC / policy-based: decisions from attributes of the user (department, clearance, location), the data (classification, region, owner) and the context (purpose, time, device). It scales better.
  • Row-level security: an analyst in India sees only Indian customers.
  • Column-level security and masking: a PII column is masked unless the user has purpose fraud-investigation.
  • Tag-based policies in the catalog (Unity Catalog, Polaris, Lake Formation, Snowflake, Immuta, Privacera) apply one rule to every table tagged pii.
  • Policy as code: OPA/Rego or Cedar, reviewed and tested like software.
  • Just-in-time, time-boxed access with approval for restricted data, plus regular access recertification.

Data loss prevention and monitoring#

  • DLP on egress paths: email, web uploads, endpoints, and GenAI prompts, where sensitive data pasted into external AI tools is a major leak vector.
  • Database activity monitoring and query logs sent to the SIEM; alerts on unusual volumes, new access paths or bulk exports.
  • DSPM continuously discovers sensitive data and risky exposure across cloud stores.
  • Canary tokens in sensitive datasets detect exfiltration.

Privacy by design#

The GDPR principles (Article 5), mirrored by India’s DPDP Act 2023:

  1. Lawfulness, fairness and transparency (DPDP: notice and consent, or legitimate uses)
  2. Purpose limitation: use data only for the stated purpose
  3. Data minimisation: collect only what is needed
  4. Accuracy
  5. Storage limitation: retention schedules, deletion
  6. Integrity and confidentiality
  7. Accountability: prove it

Engineering patterns:

  • Purpose-tagged data and purpose-based access (“marketing” cannot read data collected for “fraud”).
  • Consent records as data, checked by services (consent management platforms; under DPDP, Consent Managers registered with the Data Protection Board).
  • Data subject rights workflows: access, correction, erasure, portability, with lineage to find every copy.
  • Pseudonymisation (replace identifiers; re-identification possible with a separately held key) is still personal data under GDPR. Anonymisation (irreversible, with no reasonable means to re-identify) is outside GDPR’s scope, but true anonymisation is hard.
  • DPIAs (data protection impact assessments) for high-risk processing.

Privacy-enhancing technologies (PETs)#

PET Use
Differential privacy Publish statistics without revealing individuals
Synthetic data Realistic test and ML data without real people (validate privacy and utility)
Federated learning Train models without centralising data
Secure multi-party computation / homomorphic encryption Compute on encrypted data jointly, for example cross-bank fraud analytics
Data clean rooms Controlled joint analysis between organisations
Trusted execution environments Process sensitive data in hardware-isolated enclaves

Residency, retention and erasure#

  • Data residency and localisation: payment data in India must be stored only in India (RBI 2018 directive). The EU GDPR restricts transfers outside the EU/EEA (adequacy decisions, SCCs, EU–US Data Privacy Framework). DPDP allows transfers except to countries the government restricts. Design regional data planes.
  • Retention: define per data class (for example 5–10 years for financial records versus months for marketing data). Enforce it with table TTLs and lifecycle policies.
  • Erasure: delete across copies (lineage helps), handle backups by expiry, and use crypto-shredding for immutable stores (event logs, Kafka topics, Iceberg snapshots: expire snapshots and delete keys).

Common mistakes#

Quick check#

Tokenisation vs encryption? Encryption transforms data with a key and is reversible by anyone with the key. Tokenisation replaces data with a random token whose mapping lives in a secured vault, so systems that hold only tokens are out of scope.

What is envelope encryption? Data is encrypted with a data key, and the data key is encrypted with a master key held in a KMS or HSM. Only the encrypted data key is stored with the data.

RBAC vs ABAC? RBAC grants by role. ABAC decides using attributes of the user, the data and the context, so it is finer-grained and scales better.

Is pseudonymised data covered by GDPR? Yes. It is still personal data because re-identification is possible with additional information.

How do you erase personal data from immutable event stores? Crypto-shredding: encrypt per subject and delete the key. Also expire snapshots and copies.

What does RBI’s 2018 data localisation directive require? Payment system data must be stored only in India.

Summary#

  • Classify, then minimise where sensitive data lives: tokenise early, mask by default.
  • Encrypt in transit and at rest with managed keys; use envelope encryption with an HSM or KMS.
  • Enforce fine-grained, policy-as-code access (ABAC, row and column security) in the catalog.
  • Build privacy in: purpose, consent, minimisation, retention, erasure, PETs, residency.

References#