What you will be able to do
- Design a masking policy, including a conditional policy that masks a column based on another column's value in the same row
- Explain how External Tokenization differs from Dynamic Data Masking
- Use tags to classify data, and predict how tag inheritance and tag-based masking protect columns
- Resolve precedence and materialized-view conflicts between directly assigned and tag-based masking policies
- Describe how a row access policy filters rows at query time, including with a mapping table
- Explain how a privacy policy and its privacy budget restrict queries to noisy aggregates
Key concept
Query-time policy evaluation — Masking, row access and privacy policies are schema-level objects that Snowflake evaluates every time a query runs. The stored data never changes. What a user sees depends on the context of their query, such as their current role.
1.Masking policies and External Tokenization
Column-level security in Snowflake means attaching a masking policy to a column, so that the value a query returns depends on who is asking. A masking policy is a schema-level object with one data type, one or more conditions and one or more masking functions. Snowflake applies it when the query runs and never rewrites the stored value. One policy written for email addresses can protect thousands of email columns across databases and schemas, as long as each column's data type matches the policy signature.
Conditions use context functions such as CURRENT_ROLE() (with INVOKER_ROLE for views and INVOKER_SHARE for shares), conditional expressions, or a lookup against a custom entitlement table. The masking function can be a built-in such as SHA2 or REGEXP_REPLACE, a UDF, or an external function. Depending on the conditions, a user sees the full value, a partially masked value, an obfuscated value or a token.
Policies split the people who govern data from the people who own it. By default, the role with OWNERSHIP on a table cannot unset a masking policy on it and cannot see the protected column data. Secure views can also restrict access, but they offer no segregation of duties, and every new audience means another view and another set of dashboards to maintain.
| Feature | What is stored in Snowflake | What the policy body does |
|---|---|---|
| Dynamic Data Masking | Plain-text values | Returns the value, or a masked version of it, based on the conditions |
| External Tokenization | Tokens produced by a third-party provider before loading | Calls an external function that makes a REST API call to the provider, which returns tokenized or detokenized data |
-- Dynamic Data Masking
CREATE MASKING POLICY employee_ssn_mask AS (val string) RETURNS string ->
CASE
WHEN CURRENT_ROLE() IN ('PAYROLL') THEN val
ELSE '******'
END;
-- External Tokenization
CREATE MASKING POLICY employee_ssn_detokenize AS (val string) RETURNS string ->
CASE
WHEN CURRENT_ROLE() IN ('PAYROLL') THEN ssn_unprotect(VAL)
ELSE val -- sees tokenized data
END;External Tokenization also needs the role mapping to exist on both sides, in Snowflake and at the tokenization provider. Otherwise the provider cannot decide which roles get detokenized values. In either feature, the input and output types in the signature must match. You can change a policy in place with ALTER MASKING POLICY without unsetting it, so the column stays protected while its definition changes.
Checkpoint 1 of 9· Fill the gap
PAYROLL must see the real SSN, and the values were tokenized by a third-party provider before loading. Which function completes the External Tokenization policy?
-- Dynamic Data Masking
CREATE MASKING POLICY employee_ssn_mask AS (val string) RETURNS string ->
CASE
WHEN CURRENT_ROLE() IN ('PAYROLL') THEN val
ELSE '******'
END;
-- External Tokenization
CREATE MASKING POLICY employee_ssn_detokenize AS (val string) RETURNS string ->
CASE
WHEN CURRENT_ROLE() IN ('PAYROLL') THEN ? (VAL)
ELSE val -- sees tokenized data
END;External Tokenization uses the same policy structure as Dynamic Data Masking. The difference is that its body calls an external function, here ssn_unprotect. That function makes a REST call to the tokenization provider, which returns the detokenized value. SHA2 and REGEXP_REPLACE only hash or rewrite the token that is stored, and INVOKER_ROLE is a context function, not a way to detokenize.
Source: docs.snowflake.comSources1
2.Conditional masking on another column's value
A conditional masking policy decides whether to mask a column based on the values of one or more other columns in the same row. A single-argument policy receives only the value it masks, so it can branch on the session (who is querying) but not on the row. When the rule depends on the row, such as a salary visible only to members of the row's own department, add the deciding column as a second argument. Conditional columns are listed after the first argument, and you can add more than one.
CREATE MASKING POLICY email_visibility AS (email varchar, visibility string) RETURNS varchar -> CASE WHEN CURRENT_ROLE() = 'ADMIN' THEN email WHEN VISIBILITY = 'PUBLIC' THEN email ELSE '***MASKED***' END;Every column named in the policy must be in the same table or view. Snowflake evaluates each argument at query time, so fewer arguments perform better. A column can appear in a masking policy signature or a row access policy signature, but not both, and the same rule covers conditional columns. A row access policy also answers a different question: it decides which rows come back, not what a column value looks like.
A column holds one masking policy at a time, and Snowflake does not merge the conditions of two policies. To switch policies, either unset the old one and set the new one in two statements, or replace it in one statement with FORCE. The two-statement route leaves the column unprotected between the UNSET and the SET. FORCE avoids that gap, but it can lock out users if the new conditions are stricter.
Checkpoint 2 of 9· Check yourself
In an HR table, everyone should still get every row back, but the salary value should appear only to members of that row's own department. Everyone else sees it masked. What should the policy administrator set on the salary column?
The rule depends on another value in the same row, so the policy needs department as a conditional column after the masked salary argument. A single-argument policy only knows who is querying, not the row's contents. A row access policy decides which rows come back, not how a value looks. A column holds only one masking policy, and Snowflake never merges conditions from two policies.
“selectively protect the column data in a table or view based on the values in one or more different columns”Source: docs.snowflake.com
Checkpoint 3 of 9· Exam question
A finance schema owner writes a masking policy on the SALARY column that must reveal the raw value only to members of the same DEPARTMENT as the row being read, while every other role sees a fixed placeholder string. What masking policy design accomplishes this?
Correct answer: A — Pass DEPARTMENT as a second column argument so the masking policy branches its logic on that row's own value
- A. A conditional masking policy accepts a second column argument, such as DEPARTMENT, so the masking logic can branch on that column's value for each row rather than applying one blanket rule. This is the documented mechanism for row-dependent masking.
- B. Snowflake does not merge multiple masking policies assigned to the same column; only one masking policy can be assigned to a given column at a time, so this design is not supported.
- C. A row access policy filters which rows are returned at all and operates independently of masking; it does not give a masking policy visibility into DEPARTMENT for the conditional check requested here.
- D. A masking policy signature must declare every column it references as an argument; a single-argument signature has no way to receive DEPARTMENT values, so an embedded subquery cannot substitute for the missing argument.
Sources1
3.Object tags, inheritance and propagation
A tag is a schema-level object that you assign to other objects with a string value. Snowflake stores each assignment as a key-value pair. One tag can go on many object types at once, for example a warehouse and a table, with the same value everywhere or a different value on each. Tags on tables, views and columns let data stewards find sensitive data. Tags on warehouses group resource usage by cost center or project.
Tags are inherited down the securable object hierarchy. A tag on a table applies to every column in it, and a warehouse inherits the tags on its account. Tags can also propagate automatically: to a view built on a tagged table, or to a table created with CTAS from a tagged one. Classification can set tags on sensitive columns, and CREATE TABLE ... LIKE or CLONE copies them. The apply_method column records which of these routes produced a given tag.
SELECT tag_name, tag_value, apply_method, level, domain FROM TABLE(my_db.INFORMATION_SCHEMA.TAG_REFERENCES('my_table', 'TABLE'));An object can carry up to 50 tags. Separately, the columns of one table can carry up to 50 distinct tags between them. Every account can create and set tags, but tag propagation and tag-based masking need Enterprise Edition or higher. The other edition requirements are in Snowflake editions (Standard, Enterprise, Business Critical, VPS). Tags and their assignments replicate from a primary database to its secondary (see replication groups and failover groups), so classifications stay in place after failover. For administration, a tag_admin custom role can create and apply every tag (centralized), or create the tags while each team applies them (decentralized).
Checkpoint 4 of 9· Match them up
Each object below ended up with a tag without anyone setting the tag on it directly. Match each object to the route that put the tag there, as apply_method would record it.
Tap a term, then the definition that fits it.
Tags set on a table pass down to its columns through inheritance. A view built on a tagged table gets the tag through automatic propagation because it depends on that table. Classification sets tags on the sensitive columns it finds. CLONE and LIKE copy the source table's tags. The apply_method column shows which of these routes produced each tag.
“Tags can be propagated when an object depends on another object (for example, a view based on a tagged table)”Source: docs.snowflake.com
Sources2
4.Tag-based masking policies
A tag-based masking policy is a masking policy assigned to a tag instead of to a column. Any column carrying that tag, whether set directly or inherited, is protected automatically when its data type matches the policy signature. A tag holds at most one policy per data type, so you can attach one STRING policy and one NUMBER policy to the same tag. Set that tag on a table and every matching column is protected, including columns added later, much like a future grant.
ALTER TAG security SET MASKING POLICY my_masking_policy;When a column has both a directly assigned masking policy and a tag-based one, the directly assigned policy wins. A schema-level tag sets the default, and a column-level policy overrides it. Snowflake raises no conflict error and does not mask the value twice: exactly one policy decides what the query returns.
Materialized views behave differently depending on how the masking policy got onto the column. Over a tag-based policy, Snowflake will not create a materialized view at all. Over a directly assigned policy, it will. Learn both cases, because each is the other's wrong answer.
| Situation | Policy assigned directly to the column | Tag-based masking policy |
|---|---|---|
| Create a materialized view over the table | Created, but contains only unprotected columns. Including a protected column fails with Unsupported feature 'CREATE ON MASKING POLICY COLUMN' | Cannot be created |
| Policy added after the materialized view exists | Setting the policy fails because one or more materialized views exist on the table | The materialized view is invalidated and cannot be queried until you unset the policy and recreate or resume the view |
Tag-based masking has a few more restrictions. While a policy is assigned to a tag, you cannot drop the policy, the tag, or the schema or database that contains either one. You cannot assign a policy to a system tag. A table with a column protected by a tag-based policy cannot be used as a mapping table.
Checkpoint 5 of 9· Check yourself
A governance team assigns a STRING masking policy to the tag pii and sets pii on the CUSTOMERS table. The table has the columns email (STRING), phone (STRING) and balance (NUMBER). A week later, someone adds a STRING column called notes. No policy is set directly on any column. Which columns are masked now?
Every column inherits the table-level tag, including columns added later, but the tag-based policy protects only columns whose data type matches its signature. balance is a NUMBER and the tag has no NUMBER policy, so its values show unmasked. The three STRING columns are masked.
“When the data type of a column matches the data type in the masking policy signature, the tagged column is automatically protected”Source: docs.snowflake.com
Checkpoint 6 of 9· Exam question
A column named SSN has a masking policy assigned directly to it via CREATE TABLE, and the same column also inherits a different masking policy through a tag applied at the schema level. When a restricted role queries that column, which masking policy governs the returned value?
Correct answer: A — The directly assigned column-level masking policy takes precedence over the schema-level tag-based masking policy
- A. When a column carries both a directly assigned masking policy and a tag-based masking policy, Snowflake applies the directly assigned policy and ignores the tag-based one for that column. This precedence rule is documented explicitly for resolving such conflicts.
- B. Tag propagation determines which objects a tag-based policy reaches, but it does not grant tag-based policies priority over a policy assigned straight to the column; precedence runs the opposite direction.
- C. Snowflake resolves this conflict deterministically through precedence rather than by rejecting the query, so no error is raised when both a direct and a tag-based policy target the same column.
- D. Masking policies are not chained or stacked on a single column; only one policy signature is ever evaluated per column read, so sequential double-masking does not occur.
Checkpoint 7 of 9· Exam question
A table has a tag-based masking policy assigned to one of its columns through a tag at the database level. What limitation applies if an analyst tries to create a materialized view selecting from that table?
Correct answer: A — Materialized views cannot be created over a table that has a tag-based masking policy on any underlying column
- A. Snowflake does not permit creating a materialized view over a table where an underlying column carries a tag-based masking policy; the CREATE MATERIALIZED VIEW statement is rejected. This is a documented limitation distinct from ordinary views.
- B. The limitation blocks creation of the materialized view entirely rather than allowing creation with the masked column omitted; there is no partial-schema workaround for this restriction.
- C. Because the materialized view cannot be created at all while the tag-based policy is attached, there is no refresh cycle to describe re-evaluating the policy.
- D. The restriction applies specifically to materialized views, not standard views; ordinary views over tag-masked columns are supported and evaluate the policy normally.
5.Row access policies
A row access policy is row-level security: a schema-level object whose expression returns BOOLEAN for each row. It filters SELECT results and the rows that UPDATE, DELETE and MERGE select. It does not stop INSERTs, and it does not stop updates or deletes of rows the user can already see. One policy can be attached to many tables and views, either at creation or later.
CREATE OR REPLACE ROW ACCESS POLICY rap_it
AS (empl_id varchar) RETURNS BOOLEAN ->
'it_admin' = current_role()
;At query time, Snowflake does the following:
- Checks whether the object has a row access policy. If it does, every row is protected.
- Builds a dynamic secure view of the object.
- Binds the columns named when the policy was attached to the policy's parameters and evaluates the expression.
- Returns only the rows for which the expression is TRUE.
The expression runs with the policy owner's role, not the querying user's. That is why a policy can look up a mapping table the user has no access to. For example, a table mapping Alice to WW, Bob to NA and Simon to EU lets each sales manager see revenue rows for their own region, and Alice sees all of them. Keep the mapping table in the same database as the protected table. To change who sees what, update the mapping table instead of the policy. External tables cannot serve as mapping tables.
Each mapping lookup costs performance compared with a plain CASE on CURRENT_ROLE(). Every bound column must be scanned, so keep arguments few, and consider a memoizable function in place of the table reference. Even SELECT COUNT(*), normally answered from metadata, becomes a table scan once a row access policy is attached. When policies are nested, the table's policy runs first, then the policies of the views built on it in order. ALTER ROW ACCESS POLICY changes the expression while the policy stays attached. Future grants on row access policies are not supported, so grant APPLY ROW ACCESS POLICY to a custom role instead.
Checkpoint 8 of 9· Put it in order
When an analyst queries a table that has a row access policy attached, Snowflake decides which rows they get back. Put the steps Snowflake follows at query time in order.
- 1.Check whether a row access policy is set on the object; if so, every row is protected by it
- 2.Return only the rows for which the policy expression evaluates to TRUE
- 3.Create a dynamic secure view (a secure inline view) of the object
- 4.Bind the columns named when the policy was attached to the policy's parameters and evaluate the expression
Snowflake first finds out whether the object is protected at all. It then wraps the object in a dynamic secure view and evaluates the BOOLEAN expression against the bound columns. Only after that can it filter the output down to the rows where the expression is TRUE.
“Snowflake generates the query output for the user, and the query output only contains rows based on the policy definition evaluating to TRUE.”Source: docs.snowflake.com
Sources4
6.Privacy policies and privacy budgets
A privacy policy protects a table or view with differential privacy. Analysts can still learn about the population, but not about any individual in it. When the policy resolves to a privacy budget for the querying user, three things happen. Non-aggregated SELECTs are refused, noise is added to aggregate results, and the privacy budget caps how many queries the user can run. Masking a patient ID would break joins and per-person grouping. Differential privacy keeps both available.
CREATE OR REPLACE PRIVACY POLICY policy_db.diff_priv_policies.patients_policy AS () RETURNS privacy_budget ->
CASE
WHEN CURRENT_ROLE() = 'ACCOUNTADMIN' THEN no_privacy_policy()
WHEN CURRENT_ROLE() IN ('DP_TUTORIAL_ANALYST')
THEN privacy_budget(budget_name => 'clinical_analysts')
ELSE privacy_budget(budget_name => 'default')
END;Every query reveals a measurable amount of information, called privacy loss, and the loss adds up. The budget sets how much total loss is acceptable. Once a user reaches the limit, their queries fail until the budget window resets the total to zero. Loss is charged per aggregate function, not per query. SUM(age), COUNT(age) costs twice as much as SUM(age) alone, at the MAX_BUDGET_PER_AGGREGATE rate each. GROUP BY costs nothing, and COUNT(*) returns an exact, free answer because row counts are treated as public.
The policy is attached with ADD PRIVACY POLICY ... ENTITY KEY (patient_id), which names the column that identifies the individual being protected. Privacy domains declare the range of possible values for a column, and wider ranges mean more noise. A table-level policy needs an ELSE branch and returns no_privacy_policy() rather than NULL to exempt a role. Analysts call SNOWFLAKE.DATA_PRIVACY.ESTIMATE_REMAINING_DP_AGGREGATES to see roughly how many aggregates they have left.
Checkpoint 9 of 9· Check yourself
Researchers need statistics across the whole patient population. They join and group on patient_id, but they must not be able to learn anything about any single patient. Which control fits?
Differential privacy lets researchers learn about the population but not about individuals, and it keeps joins and per-person grouping working. Masking patient_id changes the value researchers see, which breaks those joins. A row access policy only decides which rows come back, so researchers could still read individual records. A secure view that drops patient_id makes joining and grouping on it impossible.
“the masking policy conditions determine whether unauthorized users see masked, partially masked, obfuscated, or tokenized data”Source: docs.snowflake.com
Sources
(7)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“uses masking policies to selectively mask plain-text data in table and view columns at query time”
↩︎ Masking policies and External Tokenization“masking policies for External Tokenization require using Writing external functions in the masking policy body”
↩︎ Masking policies and External Tokenization“Secure views do not have SoD, which is a profound limitation to their utility.”
↩︎ Masking policies and External Tokenization“Ensure all columns specified in the CREATE MASKING POLICY statement reside in the same table or view.”
↩︎ Conditional masking on another column's value“the same column cannot be specified in both a masking policy signature and a row access policy signature at the same time”
↩︎ Conditional masking on another column's value“could lead to a data leak because the column data is unprotected in the time interval between the UNSET and SET operations”
↩︎ Conditional masking on another column's value“a masking policy that is directly assigned to a column takes precedence over a tag-based masking policy”
↩︎ Tag-based masking policies“the materialized view only contains columns that are not protected by a masking policy”
↩︎ Tag-based masking policies“sensitive data in Snowflake is not modified in an existing table (i.e. no static masking)”
↩︎ Key concept“Object owners cannot view column data in which a masking policy applies.”
↩︎ Exam trap 1“The second column is a conditional column to evaluate whether the first column should be masked.”
↩︎ Prediction“selectively protect the column data in a table or view based on the values in one or more different columns”
↩︎ Checkpoint“the masking policy conditions determine whether unauthorized users see masked, partially masked, obfuscated, or tokenized data”
↩︎ Checkpoint - 2.
“Snowflake stores the tag and its string value as a key-value pair.”
↩︎ Object tags, inheritance and propagation“if a tag is set on a table, the tag will be inherited by all columns in that table”
↩︎ Object tags, inheritance and propagation“Your account must be Enterprise Edition or higher to use the following capabilities:”
↩︎ Object tags, inheritance and propagation“Snowflake replicates tags and their assignments within the primary database to the secondary database.”
↩︎ Object tags, inheritance and propagation“the tagged column is automatically protected by the masking policy”
↩︎ Tag-based masking policies“Tags can be propagated when an object depends on another object (for example, a view based on a tagged table)”
↩︎ Checkpoint“When the data type of a column matches the data type in the masking policy signature, the tagged column is automatically protected”
↩︎ Checkpoint - 3.
“A tag can support one masking policy for each data type.”
↩︎ Tag-based masking policies“A materialized view cannot be created if the underlying table is protected by a tag-based masking policy.”
↩︎ Exam trap 2“The table is protected by the tag-based masking policy set on the target schema or database”
↩︎ Prediction - 4.
“Snowflake evaluates the policy expression by using the role of the policy owner, not the role of the operator who executed the query.”
↩︎ Row access policies“The row access policy that is applicable to the table is always executed first.”
↩︎ Row access policies“Snowflake does not support using external tables as a mapping table in a row access policy.”
↩︎ Row access policies“Row access policies do not currently prevent rows from being inserted, or prevent visible rows from being updated or deleted.”
↩︎ Exam trap 3“Snowflake generates the query output for the user, and the query output only contains rows based on the policy definition evaluating to TRUE.”
↩︎ Checkpoint - 5.
“the user cannot run non-aggregated SELECT queries, noise is added to the results”
↩︎ Privacy policies and privacy budgets - 6.
“A privacy budget sets a limit on how much privacy loss is acceptable.”
↩︎ Privacy policies and privacy budgets“Snowflake considers the number of rows in the privacy-protected table to be public.”
↩︎ Privacy policies and privacy budgets - 7.
“The privacy budget is calculated per aggregate function, not per query.”
↩︎ Privacy policies and privacy budgets