Secure Views and Governance Odds & Ends
A secure view hides its own SQL and stops the optimizer from leaking rows the view filters out. Policies protect the data, a secure view protects the logic.
The problem
A regular view hides its base tables behind a name, but two things still leak. Anyone with access can read its definition with GET_DDL or SHOW VIEWS, including the filter logic and the table names. And the optimizer, the part of Snowflake that decides in which order to run the steps of a query, is free to reorder the user's WHERE conditions (also called predicates) and the view's own filter. A curious user can exploit that to learn about rows the view excludes.
How it works: the probe a secure view blocks
Youness gives ANALYST SELECT on the view TEAM_DIRECTORY, not on the EMPLOYEES table behind it. The view shows the employees of the reader's own department, which for Alice is BI. Suppose it were a standard view. Alice adds a condition built to fail on one value: WHERE 1/IFF(city = 'Lisbon', 0, 1) = 1. For a Lisbon row, IFF returns 0 and the division fails. If the optimizer tests her condition before the view's department filter, it also runs on other departments' rows. A "Division by zero" error then tells her that someone in Lisbon exists, although she can't see that row. A user-defined function (UDF, a function she writes herself) can run the same kind of test on anything. With a secure view, Snowflake applies the view's filter first, so her condition only ever sees rows she is entitled to. The definition is also hidden from her. Figure 3.16 puts the two orders side by side.
STANDARD VIEW · ORDER CHOSEN BY THE OPTIMIZER
4 STORED ROWSEMPLOYEESAna · BI · ParisLéo · BI · ParisRui · Finance · LisbonEva · HR · Lyon
STEP 1Alice’s conditionon all 4 rows: Lisbon row divides by zero
LEAKError"Division by zero" so a hidden Lisbon employee exists
STEP 2 · NEVER REACHEDView filterdepartment = BI
SECURE VIEW · VIEW FILTER ALWAYS FIRST
4 STORED ROWSEMPLOYEESAna · BI · ParisLéo · BI · ParisRui · Finance · LisbonEva · HR · Lyon
STEP 1View filterdepartment = BI, 2 rows left
STEP 2Alice’s conditiontested on 2 BI rows
RESULTAna, Léono error, nothing learned
CREATE SECURE VIEW hr_db. core. team_ directory AS SELECT employee_name, department, city FROM hr_db. core. employees WHERE department = (SELECT department FROM hr_db. core. user_ department WHERE user_name = CURRENT_USER( )); GRANT SELECT ON VIEW hr_db. core. team_ directory TO ROLE analyst; -- the view, not the table -- ANALYST already holds USAGE on HR_DB, HR_DB.CORE and BI_WH (grant sheet)-- Alice's probe: harmless against a secure viewSELECT * FROM hr_db. core. team_ directory WHERE 1/IFF(city = 'Lisbon', 0, 1) = 1;
Expected result. Alice sees her department's directory. For her, GET_DDL, SHOW VIEWS and the INFORMATION_SCHEMA views don't display the definition; only roles granted the view's owner role see it. Her probe returns BI rows and never an error that depends on hidden rows.
The mental model: three protections, three different jobs
Figure 3.17 runs one query against the same small SALES table under each protection, used alone. Compare what Alice gets back.
| id | region | |
|---|---|---|
| 1 | EUROPE | lea@… |
| 2 | AMERICAS | sam@… |
| 3 | APAC | ken@… |
| 4 | EUROPE | ana@… |
| id | region | |
|---|---|---|
| 1 | EUROPE | *****@… |
| 2 | AMERICAS | *****@… |
| 3 | APAC | *****@… |
| 4 | EUROPE | *****@… |
| id | region | |
|---|---|---|
| 1 | EUROPE | lea@… |
| 4 | EUROPE | ana@… |
SELECT GET_DDL('VIEW', 'sales_eu');definition not shown to AliceLimits and traps
The cost of a secure view is performance. The optimizations it skips are real, so a secure view over a large table can be slower than the same standard view. Use a standard view unless the definition or the excluded data is itself sensitive. Secure views are available in every edition. Options claiming secure views "encrypt data in transit" or "run faster" get it backwards.
Sharing note: by default a share accepts only secure views and other secure objects (SECURE_OBJECTS_ONLY = TRUE). A share explicitly created with SECURE_OBJECTS_ONLY = FALSE can carry non-secure views too, as Part 5 explains, but Snowflake recommends secure views whenever possible.
Which one to use
| Need | Best fit | Why |
|---|---|---|
| Hide rows by role, on every path to a table | Row access policy | Attaches to the base table. Querying the table directly can't bypass it |
| Hide column values by role | Masking policy | Follows the column everywhere |
| Hide a view's SQL and block optimizer probing | Secure view | Only a view has a definition to hide |
| Expose a curated subset through a share | Secure view, often with policies on the base tables | Consumers can't see how the subset was defined |
Other governance words
| Feature | What it does |
|---|---|
| Object tagging | Attaches key-value labels to objects and columns, for example pii = 'email'. A tag's ALLOWED_ list restricts which values it may take (up to 5,000), so labels stay consistent. Tags are the hook for tag-based masking. |
| Data classification | Detects likely sensitive columns (email, name, national ID…) and can label them with Snowflake's built-in system tags, SEMANTIC_ |
| ACCESS_ | A view in SNOWFLAKE. |
| Aggregation policy | Queries on the table must aggregate. Groups with fewer rows than the minimum are merged into one remainder group whose grouping key is NULL. With a minimum of 5, SELECT city, COUNT(*) … GROUP BY city works and SELECT * is refused. |
| Projection policy | A column may be used in WHERE or JOIN but can't appear in the result. WHERE email = 'x@y. works, SELECT email is refused. |
- Secure view = hidden definition + no optimizer leaks, at some performance cost, in every edition.
- For row or column restrictions on a table, policies beat views because they apply on every path.
- Shares accept secure objects by default. Tag ALLOWED_VALUES holds up to 5,000 values. ACCESS_HISTORY answers "who read what."

