Module 19 · Lesson 2 of 9Detailed study · about 39 min

Snowflake secure views and consumer-specific data protection

Share sales totals without exposing raw orders or contact fields. Test account-based denials and cross-account policy context.

Before you beginReview the provider and consumer model

Why a secure view is worth using for a partner boundary

Both partners need totals by day. Neither needs an email address, a customer ID or the other partner’s region. A regular view can hide columns by selecting a subset, but its definition is visible more broadly and optimizer rewrites can expose facts about hidden rows. A secure view limits access to the definition for the ordinary reader and avoids those optimizations. Its SQL still needs the right column list and filters.

An authorized owner or permitted metadata administrator may still access the definition. Secure views can run more slowly than regular views, and some scan detail is hidden from readers for privacy. Measure representative queries before changing the design. For simple internal query reuse with no privacy boundary, a regular view may be enough.

Secure view as the only published sales surface Privilege checks keep private objects out of the import. The view filters by account and returns daily totals.
  1. Private sourceAggregate approved data to Secure daily view
  2. Private entitlementsCheck consumer account to Secure daily view
  3. Secure daily viewGrant SELECT to the share to India partner
Private source
Sales and customers.
Private entitlements
Account locator and allowed region.
Secure daily view
Four published columns.
India partner
Only India sales totals.

Prepare the fictional customer and sales inputs

This lab uses new objects in LS_M19_SHARE_LAB. Use the provider role and warehouse from the direct share lesson. If you already created them, check the exact starting state and skip setup. The fixture represents one order per row and assumes one currency. The baseline totals are EU 200 and IN 150.

SQL · configuration template
-- Provider account. The role will own the objects it creates.
USE ROLE M19_SHARE_ADMIN;
USE WAREHOUSE <provider_lab_warehouse>;
CREATE DATABASE LS_M19_SHARE_LAB;
CREATE SCHEMA LS_M19_SHARE_LAB.CORE;
CREATE SCHEMA LS_M19_SHARE_LAB.PARTNER;

CREATE TABLE LS_M19_SHARE_LAB.CORE.CUSTOMERS
  (CUSTOMER_ID NUMBER NOT NULL, CUSTOMER_NAME VARCHAR, EMAIL VARCHAR);
INSERT INTO LS_M19_SHARE_LAB.CORE.CUSTOMERS VALUES
  (101,'Asha Rao','asha@example.invalid'),
  (102,'Luc Martin','luc@example.invalid'),
  (103,'Meera Shah','meera@example.invalid');

CREATE TABLE LS_M19_SHARE_LAB.CORE.SALES
  (SALE_ID NUMBER NOT NULL, CUSTOMER_ID NUMBER NOT NULL, REGION VARCHAR NOT NULL,
   SALE_DATE DATE NOT NULL, NET_AMOUNT NUMBER(10,2) NOT NULL);
INSERT INTO LS_M19_SHARE_LAB.CORE.SALES VALUES
  (701,101,'IN','2026-01-06',100),
  (702,102,'EU','2026-01-06',200),
  (703,103,'IN','2026-01-06',50);

SELECT REGION, COUNT(*) AS ORDER_COUNT, SUM(NET_AMOUNT) AS NET_SALES
FROM LS_M19_SHARE_LAB.CORE.SALES GROUP BY REGION ORDER BY REGION;

Create the provider role and confirm both accounts →

Create a secure view with a fail-closed account filter

Use the provider as M19_SHARE_ADMIN. Capture the partner locators from each verified account. The entitlement map has no wildcard. The provider’s own locator is mapped to both regions so the owner can preview expected totals. The view checks for a matching locator and region with EXISTS. A duplicated map row does not inflate sales, and a missing entitlement shows no rows.

A SELECT list with four explicit fields omits names, contacts, order IDs and customer IDs. GROUP BY returns one row for each allowed day and region. The consumer receives SELECT on the view, never on the CORE schema, map or base tables.

Set the approved regions by account

SQL · configuration template
-- Provider account as M19_SHARE_ADMIN.
CREATE TABLE LS_M19_SHARE_LAB.CORE.PARTNER_ENTITLEMENT
  (ACCOUNT_LOCATOR VARCHAR NOT NULL, REGION VARCHAR NOT NULL);

-- The current provider can preview both regions in an unsimulated session.
INSERT INTO LS_M19_SHARE_LAB.CORE.PARTNER_ENTITLEMENT
SELECT CURRENT_ACCOUNT(), COLUMN1 FROM VALUES ('IN'),('EU');

INSERT INTO LS_M19_SHARE_LAB.CORE.PARTNER_ENTITLEMENT VALUES
  ('<verified_india_consumer_locator>','IN'),
  ('<verified_europe_consumer_locator>','EU');

Create the shared view

SQL · runnable example
-- Provider account as M19_SHARE_ADMIN.
CREATE SECURE VIEW LS_M19_SHARE_LAB.PARTNER.SALES_DAILY AS
SELECT S.REGION, S.SALE_DATE, COUNT(*) AS ORDER_COUNT,
       SUM(S.NET_AMOUNT) AS NET_SALES
FROM LS_M19_SHARE_LAB.CORE.SALES S
WHERE EXISTS (
  SELECT 1 FROM LS_M19_SHARE_LAB.CORE.PARTNER_ENTITLEMENT E
  WHERE E.ACCOUNT_LOCATOR = CURRENT_ACCOUNT() AND E.REGION = S.REGION
)
GROUP BY S.REGION, S.SALE_DATE;

Predict allowed results, then test denied access

Run the simulation as the secure view owner in a new provider worksheet. Use the verified locator and reset the session afterward. Repeat for Europe. A mapped account sees only its rows. If you have a separate approved same-region test account without an entitlement, the modeled result is empty. This session test checks filtering, while the two-account capstone checks account invitations, imported roles and the real read boundary.

In that consumer account, request a different region and expect zero rows. Try to select EMAIL from the secure view and expect an invalid column. Try to read CORE.CUSTOMERS and expect access failure. Those three outcomes test different boundaries. Never add a raw-table grant just to fix an expected denial.

Expected same-day sales before the correction
Expected contextREGIONSALE_DATEORDER_COUNTNET_SALES
Provider previewEU2026-01-061200.00
Provider previewIN2026-01-062150.00
India account onlyIN2026-01-062150.00
Europe account onlyEU2026-01-061200.00
Unknown entitlementNo rows
SQL · configuration template
-- Provider account, in a dedicated worksheet as the view owner.
ALTER SESSION SET SIMULATED_DATA_SHARING_CONSUMER = '<verified_india_consumer_locator>';
SELECT * FROM LS_M19_SHARE_LAB.PARTNER.SALES_DAILY ORDER BY REGION, SALE_DATE;
ALTER SESSION UNSET SIMULATED_DATA_SHARING_CONSUMER;

Run the actual consumer checks →

Use the right context when sharing policy-protected data

A row access policy filters records and a masking policy can substitute individual values. Both can coexist with shared data where supported, but a provider policy that relies on CURRENT_ROLE or CURRENT_USER can receive NULL when a consumer queries across the share. CURRENT_ACCOUNT can identify the consuming account. For finer local access, use a shared database role with IS_DATABASE_ROLE_IN_SESSION, then grant that imported database role to approved consumer account roles. The role name used in the condition is relative to the database of the protected object. Check ownership, edition and support before binding the policy.

Use the account-filtered secure view here because the contract is account-wide and the partner needs only totals. Do not assume the SECURE keyword or a hidden email column prevents all inference from small groups. If small cohorts are sensitive, agree on a minimum output size and test it with neighboring groups. Module 18 handles implementation of row and masking policies in depth.

Module 18 · Protect query results with governance policies →

Interview practice

Explain the decision and the evidence you would use to test it.

What does SECURE change in a view?

It restricts definition visibility and avoids certain optimizer behaviors that could expose hidden rows. I still have to specify and test exactly what data the view should return.

Why do you use EXISTS in the entitlement filter?

I only need proof that the account may read the region. EXISTS checks membership without multiplying orders if the map accidentally has a duplicate.

How do you handle a policy that expects a provider-only role?

I check which context functions work across the share. I use an account-based rule for the account boundary and a shared database role when the provider must distinguish approved roles inside that consumer. I then run actual allow and deny tests.

Words used in this lesson
Secure view
A view that limits definition visibility and prevents certain optimizations that could expose hidden data.
Entitlement
An approved account-to-region record.
Consumer simulation
A provider-side test of a secure view using a consumer account context.

See how it works

Choose a step to explore the idea at your own pace.

Open the interactive explanation
Interactive explainer1 / 1

Snowflake secure views and consumer-specific data protection

Private source
Private entitlements
Secure daily view
India partner

Secure view as the only published sales surface

Privilege checks keep private objects out of the import. The view filters by account and returns daily totals.

Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.

Read the complete diagram explanation
  1. Secure view as the only published sales surface

    Privilege checks keep private objects out of the import. The view filters by account and returns daily totals.

    Private source → Private entitlements → Secure daily view → India partner

Try the SQL or command

Read → predict → run in your learning environment → compare. You can also learn by reading without an account.

New to SQL? Where to run it and how to read it

A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.

  1. No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
  2. For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
  3. Read the entire example, including comments beginning with --. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor.
  4. Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
SELECT / FROM
Choose the values to return / identify their input.
VALUES / COLUMN1
VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
AS / WITH
AS gives a result a readable name. WITH names a temporary query step within one statement.
NULL / ::
NULL means missing or unknown. The :: notation converts a value to a named data type.
Session
One connection and its settings. Keep related transaction steps in the same session.
Database.schema.table
A full address for stored data. It is separate from the warehouse that processes queries.

Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →

Help with common practice errors
  • No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
  • Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
  • Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
  • Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.

Before running this lesson

The datasets are fictional. Results are expected or simulated. Run live steps only in approved test accounts with the documented roles, regions, and feature access.

Check your understanding

Choose an answer, then check your reasoning. This is practice, not a scored test.

Which outcome proves that the regional filter works for an India analyst with valid access?

Try it yourself

Why is an empty view for a newly added account not enough to declare the sharing setup broken?

Compare your reasoning

Check the account locator and its entitlement. An invited account can validly read a view and still see zero rows if it has no approved region.

Connect this lesson to the learning path

Official sources and curriculum

Module 19 · See module scope

By Rohit Ray · Independent educational lesson · Explore this visual lab