🔒Data Masking
Also known as Dynamic Data Masking, Masking Policy, Data Redaction
Showing stars in place of a private value. The real one is still kept.
Think of it like
It is like a sticker on a photo. The photo is still there, but the face is hidden.
Example
Analysts at a bank can count customers by city, but card numbers show only the last four digits. The fraud team sees them in full.
Why it matters
Many people can use one table safely. No one has to make a copy for each role.
Definition
Example code
sql
CREATE MASKING POLICY email_mask AS (val STRING)
RETURNS STRING ->
CASE WHEN CURRENT_ROLE() IN ('SUPPORT') THEN val
ELSE '*****' END;
ALTER TABLE customers MODIFY COLUMN email
SET MASKING POLICY email_mask;Common mistake
Key takeaways
- 1Covered values. Stars or part of the value.
- 2By role. Allowed roles see the real value.
- 3Dynamic or static. On read, or in a covered copy.