What you will be able to do
- Decide when a secure view is worth its performance cost
- Design Dynamic Data Masking, conditional masking, tag-based masking and external tokenization for sensitive columns
- Restrict rows with a row access policy and a mapping table
- Enforce aggregate-only and no-projection access with aggregation and projection policies
- Use tags, tag lineage and data lineage to find and govern sensitive data
- Pick the Snowflake edition that handles PII, PHI and PCI DSS workloads
1.Secure views: hiding definitions and blocking leaky optimizations
Role grants decide which objects a user can reach. Data protection features decide what that user actually sees in the result. The oldest of these features is the secure view. A standard view leaks in two ways. Other users can read its definition. And some optimizer steps touch base-table data in ways that user code, such as a UDF, can observe. A secure view closes both. Its definition is shown only to users who hold the owning role, so SHOW VIEWS, GET_DDL and the Information Schema VIEWS view hide it from everyone else. Its internals also stay out of Query Profile, even for the owner.
Here is the optimizer leak in practice. widgets_view filters rows through a mapping table of roles to widget ids, and a user who can only see red widgets runs the query below. On a non-secure view, the optimizer may reorder the predicates and run the user's filter first. If any purple widget exists, the division by zero fails, and the error tells the user it exists. A secure view always applies its own filter before the user's, so the error never happens.
SELECT *
FROM widgets_view
WHERE 1/iff(color = 'Purple', 0, 1) = 1;This protection costs speed. Secure views can run more slowly, so use them only for views that exist to protect data, not for views that just make queries easier to write. Create one with the SECURE keyword in CREATE VIEW, or set and unset SECURE on an existing view with ALTER VIEW.
Checkpoint 1 of 7· Check yourself
A custom role ANALYTICS_DEV creates a secure view. ANALYTICS_DEV has not been granted to any other role. A user working as ACCOUNTADMIN then runs GET_DDL and SHOW VIEWS on that view. What does the user see?
Only users who hold the owning role can see a secure view's definition. ACCOUNTADMIN is not a superuser, and it does not inherit ANALYTICS_DEV, so it cannot see the definition. Having SELECT on the view or USAGE on its database and schema does not show the definition either.
“Note that ACCOUNTADMIN is not a superuser role.”Source: docs.snowflake.com
2.Column-level security with Dynamic Data Masking
A masking policy is a schema-level object attached to a column. At query time, Snowflake applies it to that column wherever the column appears. The stored data is never changed. Depending on the role and execution context, the same query returns the plain value, a partly masked value or a fully masked value. The return type must match the input type, and each column can have only one masking policy.
CREATE MASKING POLICY employee_ssn_mask AS (val string) RETURNS string ->
CASE
WHEN CURRENT_ROLE() IN ('PAYROLL') THEN val
ELSE '******'
END;Masking enforces segregation of duties. A security or privacy officer chooses which columns to protect, not the object owner. By default, an object owner can neither unset a masking policy nor see the masked values. A policy can also stop ACCOUNTADMIN and SECURITYADMIN users from seeing data they have no need to see. Secure views can't do this: they offer no segregation of duties, and protecting many columns with them means managing a large number of views and dashboards. A masking policy is written once and can be applied to thousands of columns. Changing its body with ALTER MASKING POLICY keeps every column protected while the update happens.
Two variations make masking easier to scale. Conditional masking adds more arguments to the policy, so the values in other columns decide whether the first column is masked. Tag-based masking attaches a policy to a tag with ALTER TAG my_tag SET MASKING POLICY my_masking_policy;. Any tagged column whose data type matches the policy signature is then protected, including columns in new objects that inherit the tag.
'******'. Owning a table doesn't bypass the masking policy on its column. Only the policy's own conditions decide what comes back, and this one shows the real value only to PAYROLL.
Checkpoint 2 of 7· Check yourself
A privacy team must protect SSN and phone-number columns in hundreds of tables. Table owners must not be able to remove the protection or see the raw values, and users working as ACCOUNTADMIN should not see the values unless they need to. Which design meets these requirements?
A masking policy separates duties. A security or privacy officer decides which columns are protected, owners can't unset the policy or see masked values, and the policy can block ACCOUNTADMIN and SECURITYADMIN. Secure views don't separate duties and mean managing many views. A managed access schema controls who can grant access, not what the results show. A column can have only one masking policy.
“A security or privacy officer decides which columns to protect, not the object owner.”Source: docs.snowflake.com
3.External tokenization
Some identifiers must never be stored in Snowflake as plaintext. External tokenization handles them. A third-party provider replaces each sensitive value with an undecipherable token before the data is loaded, so users only ever see tokens, even on columns with no policy. Authorized queries reverse the token at query time through a masking policy whose body calls an external function, a function Snowflake reaches through an API integration. That function makes a REST call to the provider. The provider checks its own tokenization policy and returns either the token or the real value, so the role mapping has to exist both in Snowflake and at the provider.
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;The privileges sit with the administrators, not the analysts. The policy owner needs USAGE on the external function, and the function's owner needs USAGE on its API integration. The role running the query needs neither. External functions are included in Standard Edition, but connecting a tokenization provider to Snowflake External Tokenization requires Enterprise Edition or higher. Use Dynamic Data Masking when plaintext may be stored in Snowflake. Use tokenization when the real value must never be there at all.
Checkpoint 3 of 7· Check yourself
Security engineers are setting up external tokenization for an SSN column. CREATE MASKING POLICY employee_ssn_detokenize fails with "Insufficient privileges to operate on function 'ssn_unprotect'". Which grant fixes the error?
The administrators hold the privileges, not the analysts. The policy owner needs USAGE on the external function its body calls, and the function's owner needs USAGE on the API integration. Roles that run queries need neither grant, and APPLY only lets a role set or unset the policy on a column.
“Verify the role creating the masking policy has the USAGE privilege on the UDF.”Source: docs.snowflake.com
4.Row-level security with row access policies
A row access policy is a schema-level object attached to a table or view. It decides which rows a SELECT returns, and which rows UPDATE, DELETE and MERGE statements can select. A simple policy can let one role see the rows. The usual design for a multi-tenant table is a mapping table that pairs each role with the tenant values it may see. The policy looks up that table, and a single policy can be attached to many tables and views, so every report and ad hoc query gets the same filter.
Snowflake evaluates the policy expression with the policy owner's role, not the role of the user running the query. Analysts therefore need no access to the mapping table. Keep one central mapping table in the same database as the protected table, especially if the policy calls IS_DATABASE_ROLE_IN_SESSION. Like masking, the policy applies to the object owner too. You can change it with ALTER ROW ACCESS POLICY without detaching it, and the table stays protected during the change.
Checkpoint 4 of 7· Check yourself
In a multi-tenant ORDERS table, a row access policy uses a mapping table to decide which tenant IDs each role can see. A user whose role maps only to tenant A runs an INSERT that writes a new row tagged with tenant B. What happens?
A row access policy controls which rows SELECT returns and which rows UPDATE, DELETE and MERGE select. It does not stop inserts, so the row is written. The user's queries then filter it out. The policy runs with the policy owner's role, so the user needs no access to the mapping table, and the policy never changes stored data.
“Row access policies do not currently prevent rows from being inserted, or prevent visible rows from being updated or deleted.”Source: docs.snowflake.com
5.Aggregation and projection policies
An aggregation policy makes queries against a table aggregate their results, and it sets a minimum group size. Rows from groups that are too small go into a remainder group whose grouping value is NULL, so no single record can be picked out. This suits a partner who should see metrics from shared data but must never isolate one customer.
CREATE AGGREGATION POLICY my_agg_policy
AS () RETURNS AGGREGATION_CONSTRAINT ->
AGGREGATION_CONSTRAINT(MIN_GROUP_SIZE => 5);When you assign the policy, you can add an ENTITY KEY, such as household_id. The minimum then counts distinct entities instead of rows, so five records from one household can't make up a group. A query must satisfy every policy on the table, and rows hidden by a row access policy are left out of the aggregates. If you attach the policy to a view, only the view is constrained, and the base table can still be queried without restriction. Snowflake treats every aggregation-constrained view as a secure view, even if it was not created as one.
A projection policy controls who can include a column in SELECT output. Unauthorized users can't return that sensitive field in their results. Projection policies are enforced after aggregation policies, and, like the other policy types, they can be attached through tags.
Checkpoint 5 of 7· Check yourself
A partner's role is limited by a row access policy to rows for the EU region. The same SALES table also has an aggregation policy with a minimum group size of 5. The partner runs SELECT city, COUNT(*) ... GROUP BY city. What do the counts reflect?
A query has to satisfy every policy on the table. The row access policy decides which rows the query returns, so rows it hides are left out of the aggregates. The aggregation policy then works on what remains, and any group smaller than the minimum goes into the NULL remainder group.
“Snowflake supports row-level security through the use of row access policies to determine which rows to return in the query result.”Source: docs.snowflake.com
6.Object tagging and data lineage
A tag is a key-value pair set on objects and columns. Querying tags lets data stewards find every column that holds a kind of sensitive data, and then decide whether to protect it with a row access policy or a masking policy. A tag can reach an object in four ways, and the apply_method column records which:
- MANUAL: someone set it with
CREATEorALTER. - INHERITED: it came from an ancestor in the securable object hierarchy. A tag on a table, for example, applies to its columns.
- PROPAGATED: it moved automatically to a dependent object, such as a view on a tagged table, or to a table created from tagged data with CTAS.
- CLASSIFIED: sensitive data classification set it on a column.
Inheritance only follows the container hierarchy. It does not pass from a table to a view to a materialized view, which is what propagation is for. You can override an inherited value by setting the tag on the object directly. An object can carry at most 50 tags. For monitoring, the Account Usage TAG_REFERENCES view leaves out inherited tags, while TAG_REFERENCES_WITH_LINEAGE includes both direct and inherited associations. Basic tagging works in every edition. Tag propagation and tag-based masking need Enterprise Edition or higher.
Data lineage shows where an object's data came from and where it goes. It records two kinds of relationship. Data movement happens when data is copied or materialized, as with CTAS, INSERT or MERGE. An object dependency exists when an object references another without copying its data, as a view references a table. In lineage terms, the source is upstream and the target is downstream. Lineage supports impact analysis before you change a table, and it supports compliance by tracking where sensitive data flows. In Snowsight, the Lineage tab also finds columns that share lineage with a tagged column but lack its tag, so you can apply the tag there. To audit who read what, use the Account Usage ACCESS_HISTORY view, which requires Enterprise Edition.
Checkpoint 6 of 7· Check yourself
After querying tag references, a data steward finds 40 columns tagged as holding SSNs. Analysts must still see every row in those tables, but they must not see the SSN values. What should the steward do next?
A tag only labels data so stewards can find it. It does not protect anything on its own. The requirement is to hide values in a column while keeping every row visible, and that is column-level security, so a masking policy is the right tool. A row access policy filters out whole rows, and propagating the tag just puts the label on more objects.
“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.”Source: docs.snowflake.com
7.Editions and compliance for PII, PHI and PCI data
The edition sets which controls an account has. Standard Edition includes the security baseline: SOC 2 Type II, MFA, federated authentication, network policies, automatic encryption, object-level access control and basic tags. Every policy type in this lesson needs Enterprise Edition or higher. Regulated data needs Business Critical.
| Feature | Minimum edition |
|---|---|
| Object-level access control, basic object tags, external functions | Standard |
| Column-level Security (masking policies) and Row-level Security (row access policies) | Enterprise |
| Aggregation policies and projection policies | Enterprise |
| Sensitive data classification and ACCESS_HISTORY auditing | Enterprise |
| Customer-managed keys through Tri-Secret Secure, and private connectivity | Business Critical |
| Support for PHI data (HIPAA and HITRUST CSF) and support for PCI DSS | Business Critical |
The design rule follows from the table. For PII, the controls you need arrive with Enterprise: masking, tokenization, row access, aggregation and classification. An account that will store PHI or cardholder data covered by PCI DSS must be Business Critical or higher, whatever policies it uses. Plan replication with editions in mind as well: replicating a database that contains an aggregation policy fails if any account approved for replication is on a lower edition.
Checkpoint 7 of 7· Check yourself
A healthcare company runs an Enterprise Edition account with masking policies, row access policies and classification on every table. It now wants to load patient records covered by HIPAA into that account. What is the right design decision?
Support for PHI data under HIPAA and HITRUST CSF is an edition feature. Enterprise gives the policy tooling, but PHI workloads need Business Critical or higher, whatever policies are applied. Standard is the lowest edition and does not include PHI support.
“Support for PHI data (in accordance with HIPAA and HITRUST CSF regulations).”Source: docs.snowflake.com
Practise it for real
Protect an email column so that only the ANALYST role sees real values, using a separate masking administrator role.
1.As USERADMIN, run CREATE ROLE masking_admin. Then, as SECURITYADMIN, grant it CREATE MASKING POLICY on your schema and APPLY MASKING POLICY on ACCOUNT.
Why: A dedicated policy administrator keeps masking decisions separate from table owners.
You should see: SHOW GRANTS TO ROLE masking_admin lists both privileges.
2.As masking_admin, create a masking policy on (val string) RETURNS string. Use a CASE that returns val when CURRENT_ROLE() is ANALYST and a fixed masked string otherwise.
Why: The policy body decides what each role sees when it queries.
You should see: The statement succeeds. If the return type doesn't match the input type, it fails with an argument and return type mismatch error.
3.Run ALTER TABLE user_info MODIFY COLUMN email SET MASKING POLICY with your policy name.
Why: Attaching the policy is a separate step that needs the APPLY privilege.
You should see: The policy appears in the POLICY_REFERENCES output for the table.
4.Run SELECT email FROM user_info once as ANALYST and once after USE ROLE PUBLIC.
Why: This checks the policy against an authorized role and an unauthorized one.
You should see: ANALYST sees plain-text emails and PUBLIC sees the masked string.
5.Try DROP MASKING POLICY on the policy while it is still attached.
Why: A policy can't be dropped while columns still use it, which stops a column being left unprotected by accident.
You should see: The drop fails because the policy is associated with one or more entities. Unset it from the column first, then drop it.
Stuck? Get a nudge
If attaching the policy fails with a 'does not exist or not authorized' error, the role running the ALTER is missing APPLY MASKING POLICY, or APPLY on that specific policy.
Sources
(17)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“They complement role-based access control (RBAC) by governing what data users actually see at query time, not just which objects they can access.”
↩︎ Secure views: hiding definitions and blocking leaky optimizations“Restricts which columns can be accessed or projected in queries, so only authorized users can view sensitive fields.”
↩︎ Aggregation and projection policies - 2.
“Secure views do not utilize these optimizations, ensuring that users have no access to the underlying data.”
↩︎ Secure views: hiding definitions and blocking leaky optimizations“With secure views, the view definition and details are visible only to authorized users”
↩︎ Secure views: hiding definitions and blocking leaky optimizations“If the view were not secure, then the Snowflake optimizer could re-order the predicates in the WHERE clauses.”
↩︎ Secure views: hiding definitions and blocking leaky optimizations“Secure views can execute more slowly than non-secure views.”
↩︎ Secure views: hiding definitions and blocking leaky optimizations - 3.
“At query runtime, the masking policy is applied to the column at every location where the column appears.”
↩︎ Column-level security with Dynamic Data Masking“A security or privacy officer decides which columns to protect, not the object owner.”
↩︎ Column-level security with Dynamic Data Masking“A column cannot be attached to multiple masking policies.”
↩︎ Column-level security with Dynamic Data Masking“Verify the role creating the masking policy has the USAGE privilege on the UDF.”
↩︎ 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 - 4.
“Secure views do not have SoD, which is a profound limitation to their utility.”
↩︎ Column-level security with Dynamic Data Masking“selectively protect the column data in a table or view based on the values in one or more different columns”
↩︎ Column-level security with Dynamic Data Masking“At query runtime, Snowflake uses the external function to make a REST API call to the tokenization provider”
↩︎ External tokenization“Object owners cannot view column data in which a masking policy applies.”
↩︎ Exam trap 1 - 5.
“the tagged column is automatically protected by the masking policy”
↩︎ Column-level security with Dynamic Data Masking“You can set a maximum of 50 tags on a single object, including tables and views.”
↩︎ Object tagging and data lineage“Your account must be Enterprise Edition or higher to use the following capabilities:”
↩︎ Object tagging and data lineage - 6.
“External Tokenization enables accounts to tokenize data before loading it into Snowflake and detokenize the data at query runtime.”
↩︎ External tokenization“even without applying a masking policy to a column in a table or view, users never see the real data value.”
↩︎ External tokenization“if you choose to integrate your tokenization provider with Snowflake External Tokenization, you must upgrade to Enterprise Edition or higher.”
↩︎ External tokenization - 7.
“the policy owner must have USAGE on the UDF or external function”
↩︎ External tokenization - 8.
“Snowflake evaluates the policy expression by using the role of the policy owner, not the role of the operator who executed the query.”
↩︎ Row-level security with row access policies“create a centralized mapping table and store the mapping table in the same database as the protected table.”
↩︎ Row-level security with row access policies“A single policy can be set on different tables and views at the same time.”
↩︎ Row-level security with 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 2“Row access policies do not currently prevent rows from being inserted, or prevent visible rows from being updated or deleted.”
↩︎ Checkpoint“Snowflake supports row-level security through the use of row access policies to determine which rows to return in the query result.”
↩︎ Checkpoint - 9.
“Adding a masking policy to a column fails if the column is referenced by a row access policy.”
↩︎ Row-level security with row access policies - 10.
“must contain at least the specified number of entities, not a specified number of rows.”
↩︎ Aggregation and projection policies“Projection policies are enforced after aggregation policies.”
↩︎ Aggregation and projection policies“Masking policies are enforced before aggregation policies.”
↩︎ Prediction - 11.
“Note that the value of state in the second group is NULL because it is a remainder group”
↩︎ Aggregation and projection policies“a row excluded from the query results based on the row access policy is not included when calculating the aggregated results.”
↩︎ Aggregation and projection policies“all aggregation-constrained views are treated as if they are secure views even if they are not.”
↩︎ Aggregation and projection policies“one or more of the accounts approved for replication are on lower editions”
↩︎ Editions and compliance for PII, PHI and PCI data“When an aggregation policy is applied to a view, the underlying table does not become aggregation-constrained.”
↩︎ Exam trap 3 - 12.
“A descendant of an object in the hierarchy inherits tags from its ancestors.”
↩︎ Object tagging and data lineage“Tag inheritance does not include propagation to nested objects.”
↩︎ Object tagging and data lineage - 13.
“The associated tag and Snowflake object are the result of both a direct association to an object and tag inheritance.”
↩︎ Object tagging and data lineage - 14.
“but does not include objects that inherited the tag”
↩︎ Object tagging and data lineage - 15.
“Object dependencies, when an object references a base object but does not materialize or copy data, such as when a view references a table.”
↩︎ Object tagging and data lineage“Facilitates compliance by tracking the flow of sensitive data.”
↩︎ Object tagging and data lineage - 16.
“Support for PHI data (in accordance with HIPAA and HITRUST CSF regulations).”
↩︎ Editions and compliance for PII, PHI and PCI data“Projection policies that restrict who can use a SELECT statement to project a column.”
↩︎ Editions and compliance for PII, PHI and PCI data“Audit the user access history through the Account Usage ACCESS_HISTORY view.”
↩︎ Editions and compliance for PII, PHI and PCI data
Also cited
“Note that ACCOUNTADMIN is not a superuser role.”
↩︎ Checkpoint