CertSafari
    Snowflake SnowPro Advanced: Administrator (ADA-C02)· Lessons

    Domain 2 · Lesson 9/24

    Masking and row access policies in Snowflake

    Implement and manage data governance in Snowflake.

    21 min read
    6% of exam
    11 sources
    Published 20 Oct 2026
    Docs as of 18 Oct 2026

    What you will be able to do

    • Write a masking policy that returns full, partial or fixed-mask values by role, and attach, update or replace it on a column
    • Explain how external tokenization works and choose between it and dynamic data masking for a given compliance requirement
    • Write a row access policy, attach it to a table or view, and predict how it changes SELECT, DML, CTAS, cloning and materialized views
    • Decide when a row access policy is a better choice than a secure view
    • Identify where a tag adds governance value, configure a tag's allowed values and conflict handling, and trace changes to tag values over time

    Key concept

    Query-time policy enforcement — Masking policies and row access policies are schema-level objects. Snowflake evaluates them each time a query runs, so it rewrites column values or filters rows according to who is asking. The stored data never changes, and the policy, not the table's grants, decides what each role sees.

    1.Writing and attaching a masking policy

    Dynamic Data Masking protects a column without copying or changing its data. A masking policy is a schema-level object whose body is a SQL expression. When a query runs, Snowflake rewrites it so that the expression wraps the column everywhere the column appears: in projections, join predicates, WHERE clauses, ORDER BY and GROUP BY. Depending on the conditions in the body, the same query can return plain text to one role, a partial mask to another and a full mask to everyone else.

    Three privileges split the work so that the security or privacy officer chooses which columns are protected, not the object owner. CREATE MASKING POLICY on a schema controls who can write policies. APPLY MASKING POLICY on the account controls who can set and unset policies on columns, and ACCOUNTADMIN has it by default. It grants no table privileges. APPLY on one specific policy is optional and lets the policy owner hand set and unset operations for that policy to the owners of the tables. A common setup creates a MASKING_ADMIN custom role with USERADMIN and has SECURITYADMIN grant it the first two privileges.

    A masking policy that shows ANALYST the real value and gives every other role a full masksql
    CREATE OR REPLACE MASKING POLICY email_mask AS (val string) RETURNS string ->
      CASE
        WHEN CURRENT_ROLE() IN ('ANALYST') THEN val
        ELSE '*********'
      END;

    You attach the policy with ALTER TABLE IF EXISTS user_info MODIFY COLUMN email SET MASKING POLICY email_mask;, with the equivalent ALTER VIEW statement, or inline in CREATE TABLE or CREATE VIEW. When a requirement says different roles see different things, write a CASE with one branch per role. Each branch can return the value, NULL, a fixed string, a hash from SHA2 (hashes can collide), the output of a UDF, or a partial mask. Granting SELECT never unmasks anything. A role with SELECT on the table still sees whatever the policy body returns for that role. The body also needs to match the requirement: if the requirement names roles, test roles rather than a hard-coded list of user names.

    Three tiers in a single policy body: full value, the email domain only, and a fixed masksql
    CASE WHEN current_role() IN ('ANALYST') THEN val WHEN current_role() IN ('SUPPORT') THEN regexp_replace(val,'.+\@','*****@') -- leave email domain unmasked ELSE '********' END;

    CURRENT_ROLE() matches only the primary role in use. When role hierarchy or secondary roles should count, write the condition with IS_ROLE_IN_SESSION instead (see Context functions in secure objects). Use EXISTS when the body contains a subquery against an entitlement table. If the lookup is expensive, a memoizable function can cache the list of authorized roles.

    Several rules come up again and again in practice. The input and output data types must match: a policy on a TIMESTAMP cannot return the string '*MASKED*', so it returns a fabricated timestamp instead. A column can carry only one masking policy. Setting a second policy on it fails with 'Specified column already attached to another masking policy.' To change the rules, run ALTER MASKING POLICY … SET BODY, which updates the body in place while the column stays protected. Changing the signature needs a new policy. DROP and CREATE OR REPLACE both fail while the policy is attached anywhere. To swap one policy for another, you can UNSET and then SET, which leaves the data unprotected between the two statements. The FORCE keyword does the swap in a single statement instead. The documented example is on a tag: ALTER TAG security SET MASKING POLICY ssn_mask_2 FORCE;. The risk with FORCE runs the other way: if the new policy's conditions are stricter, users who could read the data before can suddenly no longer read it.

    Checkpoint 1 of 9· Check yourself

    The masking policy email_mask is already set on user_info.email and on 200 other columns. A new requirement says the SUPPORT role should see the email domain. What should the masking administrator do so the columns stay protected throughout?

    Checkpoint 2 of 9· Exam question

    A production table hr.emp has an ssn column. Role HR_ADMIN must see full values, role ANALYST must see only the last four digits, and every other role must see a fixed mask. Which approach is MOST appropriate?

    Checkpoint 3 of 9· Exam question

    A masking policy pii_mask is already attached to sales.customers.email. An engineer runs ALTER TABLE sales.customers MODIFY COLUMN email SET MASKING POLICY new_mask; and the statement fails. What is the MOST appropriate way to swap the policy in one statement?

    Sources1234

    2.External tokenization and when to choose it

    External tokenization never lets the sensitive value reach Snowflake. A third-party tokenization provider replaces each value with an undecipherable token before loading, so only tokens are stored. At query time, a masking policy calls an external function. The function makes a REST call to the provider, which evaluates a tokenization policy defined outside Snowflake and returns either the token or the original value. Because both sides take part, the role mapping has to exist in Snowflake and at the provider.

    The same PAYROLL rule as dynamic masking and as detokenization. Only the authorized branch differs.sql
    -- 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;

    In the tokenization policy, the ELSE branch returns val unchanged, and that is safe because val is already a token. Unauthorized users see the token even when no policy is attached at all. External functions are available in Standard Edition, but integrating a tokenization provider with Snowflake External Tokenization requires Enterprise Edition or higher. The policy owner needs USAGE on the external function, and the function's owner needs USAGE on its API integration. Users who query the column need neither.

    Dynamic data masking compared with external tokenization
    ConcernDynamic Data MaskingExternal Tokenization
    What is stored in SnowflakePlain-text valuesTokens produced by the provider before loading
    What a user sees if no policy is attachedPlain textOnly the token
    Authorized branch of the policyReturns valCalls an external function such as ssn_unprotect
    Extra componentsNone beyond the policyTokenization provider, external function, API integration
    Best fitPlain text may live in Snowflake and roles need full, partial or no visibilityCompliance requires that only an outside service can ever reveal raw values

    Checkpoint 4 of 9· Check yourself

    A compliance rule for payroll data says raw social security numbers must never be stored in Snowflake. Only an outside service may ever reveal them, and only to the PAYROLL role. Which design meets this rule?

    Checkpoint 5 of 9· Exam question

    A fintech company must keep raw card numbers out of Snowflake entirely, because its compliance team requires that only an external tokenization service can ever reveal them. Which feature MOST appropriately meets this requirement?

    Sources56

    3.Writing and attaching a row access policy

    A row access policy is a schema-level object that returns a BOOLEAN for each row. It controls which rows a SELECT returns and which rows UPDATE, DELETE and MERGE statements select. It cannot stop inserts, and it does not prevent visible rows from being updated or deleted. The simplest policy checks only the role, which costs almost nothing to evaluate.

    The shortest useful row access policy: only it_admin sees rowssql
    CREATE OR REPLACE ROW ACCESS POLICY rap_it
    AS (empl_id varchar) RETURNS BOOLEAN ->
      'it_admin' = current_role()
    ;

    The policy signature declares arguments, and attaching the policy binds table columns to those arguments: ALTER TABLE sales ADD ROW ACCESS POLICY security.sales_policy ON (region);. You can also use ALTER VIEW … ADD ROW ACCESS POLICY, or WITH ROW ACCESS POLICY … ON (…) in CREATE TABLE or CREATE VIEW. Larger policies often include an EXISTS subquery against a mapping table that lists which manager may see which region. Snowflake evaluates that body with the policy owner's role, so people who query the protected table need no access to the mapping table. Keep the mapping table in the same database as the protected table, and replace slow lookups with memoizable functions.

    The schema owner has CREATE ROW ACCESS POLICY automatically and can grant it to other roles. APPLY ON ROW ACCESS POLICY lets another role add or drop one specific policy. Future grants on row access policies are not supported. As a workaround, grant APPLY ROW ACCESS POLICY to a custom role. Transferring the policy's ownership away from SECURITYADMIN to a custom role keeps runtime evaluation at least-privilege, because the policy runs with its owner's rights. To change the logic, use ALTER ROW ACCESS POLICY: the table stays protected while the expression is updated.

    Checkpoint 6 of 9· Fill the gap

    Only the it_admin role should get rows back from the protected table, and every other role should get none. Which return type completes this row access policy?

    CREATE OR REPLACE ROW ACCESS POLICY rap_it
    AS (empl_id varchar) RETURNS  ?  ->
      'it_admin' = current_role()
    ;

    Sources74

    4.What changes once a row access policy is attached

    Once a policy is attached, every row of the object is protected. For each query, Snowflake builds a dynamic secure view of the object, binds the declared columns to the policy arguments, and returns only the rows where the policy evaluates to TRUE. EXPLAIN shows this as a DynamicSecureView operation on "<object_name> (+ RowAccessPolicy)". Neither EXPLAIN nor query history reveals the policy name, signature or body. Snowflake has to read the columns the policy is bound to even when the query does not reference them, so policies with fewer arguments run faster. On very large tables, clustering by the filtered attributes and enabling search optimization both help.

    Evaluation order matters when policies are combined. The row access policy runs before any masking policy on the same object. A single column cannot appear in both a row access policy signature and a masking policy signature, so adding a masking policy to a column that a row access policy references fails. Nested policies run from the inside out: the table's policy first, then the policy on each view built on top of it.

    How an attached row access policy affects other operations
    OperationEffect
    SELECTReturns only rows where the policy evaluates to TRUE
    UPDATE, DELETE, MERGEOnly visible rows are selected. INSERT is not prevented
    CREATE TABLE … AS SELECTNew table holds the filtered rows and has no policy
    CREATE TABLE … LIKENew table is empty and has no policy
    CREATE TABLE … CLONEClone maps to the same policies, or to cloned ones when the whole schema is cloned
    Materialized viewCannot be created on a policy-protected table, and a policy cannot be added to a table that already has one
    StreamPolicy cannot be attached to the stream, but applies when the stream reads the table

    Checkpoint 7 of 9· Match them up

    A row access policy is attached to the sales table. Match each operation run against sales to what you end up with.

    Tap a term, then the definition that fits it.

    Sources7

    5.Row access policy or secure view

    A secure view hides its definition from consumers and can include a WHERE clause that filters rows (see Views, secure views and materialized views). For row-level security, the key difference is where the filter is attached. A secure view filters only the queries that read the view. Anyone who can query the base table, including its owner, bypasses the filter. A row access policy is attached to the table itself and protects every row on every path. Snowflake effectively builds a secure view on the fly for each query, and it applies to the object owner as well.

    The other difference is how each one is managed. The filtering logic of a view lives inside that one view, so each view has to be maintained separately. One row access policy can be applied to tables across many databases and schemas. Its body can be changed without re-attaching it anywhere, and when the policy uses a mapping table, editing the mapping table's rows changes access without touching the policy at all. A central administrator, not the object owner, decides what is protected, which supports segregation of duties. You can also combine the two: a policy on the table and another on a view built over it are both evaluated, table policy first.

    Checkpoint 8 of 9· Check yourself

    Your governance team must restrict rows by sales region on 30 tables spread across three databases. Region assignments change every week. The team, not the table owners, has to decide what is protected, and weekly access changes should not require editing any view or policy. Which design fits?

    Sources7

    6.Tagging use cases and configuring and monitoring tags

    A tag pays off when one label has to drive several governance jobs at once. Once a tag such as governance.tags.pii sits on a database, schema, table or column (tag-based masking is covered with tagging itself), four kinds of work can read it:

    • Compliance tracking. After tracing where sensitive data moves, set tags on the stages, tables and columns that hold it so it can be tracked for regulations such as GDPR and CCPA.
    • Policy enforcement. Besides masking policies, a data movement policy can be set on a tag, and it then governs data movement operations on every column, table, schema or database that carries the tag.
    • Classification output. A classification profile's tag map turns a detected semantic category into your own tag, so a column found to hold EMAIL can receive tag_db.sch.pii = 'Confidential' automatically.
    • Trust signals. The system tag SNOWFLAKE.CORE.CERTIFICATION_STATUS = 'CERTIFIED' marks a table or view as the authoritative source for a business question.

    Configure a tag's own properties with ALTER TAG before it spreads across hundreds of columns, because they decide which values it accepts. ALLOWED_VALUES holds up to 5,000 strings, and SET ALLOWED_VALUES replaces the whole list in one atomic step. Removing a value does not touch objects that already carry it; it only stops new assignments. Dropping every allowed value blocks anyone from setting the tag at all, while UNSET ALLOWED_VALUES lets it take any string again. MULTI_VALUE = TRUE is one-way: once set, it can never be unset or set back to FALSE.

    Conflict handling is the setting most often left at its default, and the default is rarely what anyone wants. When propagated values collide and ON_CONFLICT is unset, Snowflake writes the literal string CONFLICT as the tag's value, so any rule that tests for 'sensitive' stops matching that column. ON_CONFLICT = ALLOWED_VALUES_SEQUENCE picks whichever value comes first in the allowed list, a fixed string always wins with that string, and MERGE keeps every value but works only on a multi-value tag. Changing PROPAGATE or ON_CONFLICT later has no effect on tags that were already propagated.

    Monitoring a tag means watching its values change, not only listing where it sits today. TAG_REFERENCES answers the second question; ACCESS_HISTORY answers the first, because its object_modified_by_ddl column records every set, unset and value change on an object or column, with the user who ran it. Flattening properties.columns.EMAIL.tags from that column gives one row per change. A typical trail: TABLE_ADMIN tags hr.tables.empl_info.email with governance.tags.data_category = 'sensitive' at 12:03, and at 12:04 DATA_ENGINEER changes it to 'public'. That quiet downgrade is the event a governance team needs to catch, and it bites immediately, since a tag change takes effect when the next SQL query that uses the tag runs.

    Checkpoint 9 of 9· Check yourself

    The tag governance.tags.data_category allows 'sensitive' and 'public'. A steward runs ALTER TAG … DROP ALLOWED_VALUES 'public'. Twenty columns already carry data_category = 'public'. What happens to those columns?

    Sources891011

    Sources

    (11)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “The column rewrite occurs at every place where the column specified in the masking policy appears in the query”
      ↩︎ Writing and attaching a masking policy
      “Currently, Snowflake does not support different input and output data types in a masking policy”
      ↩︎ Writing and attaching a masking policy
      “Users see masked data based on the execution context conditions defined in the masking policies.”
      ↩︎ Exam trap 1
    2. 2.
      “A column cannot be attached to multiple masking policies.”
      ↩︎ Writing and attaching a masking policy
      “Use an ALTER TABLE … MODIFY COLUMN or ALTER VIEW … MODIFY COLUMN statement to UNSET the policy first”
      ↩︎ Exam trap 2
      “can prohibit privileged users with the ACCOUNTADMIN or SECURITYADMIN role from unnecessarily viewing data.”
      ↩︎ Prediction
      “Policy <policy_name> cannot be dropped/replaced as it is associated with one or more entities.”
      ↩︎ Checkpoint
      “Dynamic Data Masking is a Column-level Security feature that uses masking policies to selectively mask plain-text data in table and view columns at query time.”
      ↩︎ Checkpoint
    3. 3.
      “Use the FORCE keyword to replace the policy in a single statement.”
      ↩︎ Writing and attaching a masking policy
    4. 4.
      “If role activation and role hierarchy are important, Snowflake recommends that the policy conditions use the IS_ROLE_IN_SESSION function for account roles”
      ↩︎ Writing and attaching a masking policy
      “policies are executed with owner’s rights”
      ↩︎ Writing and attaching a row access policy
    5. 5.
      “External Tokenization enables accounts to tokenize data before loading it into Snowflake and detokenize the data at query runtime.”
      ↩︎ External tokenization and when to choose it
      “if you choose to integrate your tokenization provider with Snowflake External Tokenization, you must upgrade to Enterprise Edition or higher.”
      ↩︎ External tokenization and when to choose it
    6. 6.
      “masking policies for External Tokenization require using Writing external functions in the masking policy body.”
      ↩︎ External tokenization and when to choose it
      “This means that sensitive data in Snowflake is not modified in an existing table (i.e. no static masking).”
      ↩︎ Key concept
    7. 7.
      “Rows selected by UPDATE, DELETE, and MERGE statements.”
      ↩︎ Writing and attaching a row access policy
      “Snowflake evaluates the policy expression by using the role of the policy owner, not the role of the operator who executed the query.”
      ↩︎ Writing and attaching a row access policy
      “When a database object has both a row access policy and one or more masking policies, Snowflake evaluates the row access policy first.”
      ↩︎ What changes once a row access policy is attached
      “A materialized view cannot be created from a table if a row access policy is added to the underlying table.”
      ↩︎ What changes once a row access policy is attached
      “Snowflake creates a dynamic secure view (i.e. a secure inline view) of the database object.”
      ↩︎ What changes once a row access policy is attached
      “If a policy is added to the database object, all rows are protected by the policy.”
      ↩︎ Row access policy or secure view
      “A central data administrator decides which objects to protect, not the object owner.”
      ↩︎ Row access policy or secure view
      “Row access policies do not currently prevent rows from being inserted, or prevent visible rows from being updated or deleted.”
      ↩︎ Exam trap 3
      “the same column cannot be specified in both a row access policy signature and a masking policy signature at the same time.”
      ↩︎ Exam trap 4
      “adding a row access policy means Snowflake must scan the table to count the number of rows that are accessible in the current context”
      ↩︎ Prediction
      “If a row access policy is set on the base table, the new table contains the filtered rows based on the row access policy definition.”
      ↩︎ Checkpoint
      “If using a mapping table, update the entitlement information in the mapping table referenced by the policy without having to change the policy.”
      ↩︎ Checkpoint
    8. 8.
      “set tags to ensure stages, tables, and columns with sensitive data can be tracked for compliance requirements”
      ↩︎ Tagging use cases and configuring and monitoring tags
      “Query the object_modified_by_ddl column to monitor how a tag is set on a column.”
      ↩︎ Tagging use cases and configuring and monitoring tags
      “and tag updates (e.g. set a tag, change a tag value) on the object or column.”
      ↩︎ Tagging use cases and configuring and monitoring tags
    9. 9.
      “When this tag is set on a column, table, schema, or database, the data movement policy governs data movement operations on the tagged object.”
      ↩︎ Tagging use cases and configuring and monitoring tags
      “The maximum number of tag values in this list is 5,000.”
      ↩︎ Tagging use cases and configuring and monitoring tags
      “After you set this property, you can’t unset it or set it to FALSE.”
      ↩︎ Tagging use cases and configuring and monitoring tags
      “These changes have no effect on tags that were previously applied to target objects as part of tag propagation.”
      ↩︎ Tagging use cases and configuring and monitoring tags
      “Any changes made to the tag go into effect when the next SQL query that uses the tag runs.”
      ↩︎ Tagging use cases and configuring and monitoring tags
      “If you don’t set this parameter and there is a conflict, the value of the tag is set to the string CONFLICT.”
      ↩︎ Exam trap 5
      “Changing or removing allowed values doesn’t affect values already assigned to objects.”
      ↩︎ Checkpoint
    10. 10.
      “With this tag mapping, a column with sensitive data can be automatically assigned a user-defined tag based on its classification.”
      ↩︎ Tagging use cases and configuring and monitoring tags
    11. 11.
      “Applies SNOWFLAKE.CORE.CERTIFICATION_STATUS = 'CERTIFIED' to a confirmed table or view, with permission checks and immediate verification.”
      ↩︎ Tagging use cases and configuring and monitoring tags

    Continue to part 2 of 2

    Tags, classification, access history and Trust Center in Snowflake

    Spotted a mistake, or was something unclear? Tell us.