EX-23: Dynamic Data Masking (DDM) for Customer PII
Track: Security & Privacy • Difficulty: Intermediate • Mastery Points: 150 PTS
Business Problem Scenario
Under GDPR Article 25 (Data Protection by Design) and purpose limitation principles, customer email addresses must be dynamically redacted for general analysts and reporting jobs, while certified members of the compliance team must view the raw email for anti-money laundering investigations. You must implement a dynamic masking user-defined function (UDF) in Unity Catalog.
Engineering Objective
Write the SQL function CREATE OR REPLACE FUNCTION gov.mask_email(email STRING). • Function Logic & Privileges: - Check whether the executing user is a member of user group 'compliance_officers'. - If true, return raw email; otherwise return masked email redacting username characters with asterisks (using regexp_replace). • Catalog Attachment Note: In Unity Catalog, masking functions are attached to columns via ALTER TABLE silver.crm_customers ALTER COLUMN email SET MASK gov.mask_email;. Key Concepts: - Dynamic Data Masking (DDM): Runtime redaction applied during query evaluation based on user session role. - GDPR Article 25: Principle of data protection by design and default requiring technical controls embedded into data platforms.
Target Table: gov.mask_email function, silver.crm_customers (crm_id STRING, full_name STRING, email STRING)
Verification & Architecture Insights
Dynamic masking applies at query execution inside Unity Catalog, preventing PII leaks without mutating physical parquet files on disk.