liveBook · Manning

Masking policy

As explained in Snowflake Data Engineering

A masking policy is a data-access rule that transforms or obscures sensitive column values for unauthorized users.

A masking policy is a schema-level Snowflake object that transforms sensitive column values at query runtime. Authorized roles receive the original value; other roles receive masked, partially masked, or obfuscated output. section 10.3

Apply a masking policy through an incremental governance workflow:

  • Grant a role privileges to create masking policies on a schema and apply them at the account level. section 10.3
  • Create a policy with a typed column argument, a return type, and a conditional masking function based on CURRENT_ROLE(). section 10.3
  • Attach the policy to the sensitive column with ALTER VIEW ... MODIFY COLUMN ... SET MASKING POLICY. section 10.3
  • Query the protected object with functional roles to verify that authorized users see source values while unauthorized users see masked output. section 10.3
use role DATA_ENGINEER;
use warehouse BAKERY_WH;
use database BAKERY_DB;
use schema DG;

create masking policy ADDRESS_MASK 
as (addr varchar) 
returns varchar ->
  case
    when current_role() in ('DATA_ENGINEER') then addr
    else '***'
  end;

The executable definition preserves HOME_ADDRESS for DATA_ENGINEER and returns three asterisks for other roles. section 10.3

How Snowflake Data Engineering covers it

How deep it goes
Defines schema-level runtime behavior, creates and applies a policy, and tests role-specific results without masking stored table data.
Examples
Masks the bakery EMPLOYEE view's HOME_ADDRESS column for DATA_ANALYST_BREAD while preserving it for DATA_ENGINEER.
What it assumes
Assumes Snowflake roles, schemas, views, columns, and query execution; grants and role conditions are demonstrated in the workflow.
What you can do after
Apply it via Snowflake SQL to protect a sensitive column and verify role-dependent query results.
How it connects
Connects role-based access control, row access policies, data governance, and secure multitenant data access.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Snowflake Data Engineering. The section links point to the parts of the book it draws on.