Row Access Policies
A row access policy is a TRUE or FALSE test run for every row. Rows where it returns FALSE don't exist for that query.
The problem
IsmaFrost's SALES table holds rows for Europe, the Americas and APAC. Alice should see only the European rows. Thomas's pipeline, working as DATA_ENGINEER, must see all of them. Amine has no regional entitlement at all. One view per region would multiply objects and invite mistakes.
The mental model
Imagine an invisible WHERE clause that Snowflake adds to every query on the table, written once by the security team. That clause is the row access policy. It requires Enterprise edition or above.
How it works
A row access policy is a schema-level object with a signature (the columns it reads) and a body that returns BOOLEAN. When you attach it to a table or view, you map its arguments to columns. At query time Snowflake applies it on every access path: direct queries, views and shares. When a table also has masking policies, Snowflake evaluates the row access policy first and then masks columns on the rows that remain. That order is documented. Figure 3.15 follows Alice's query.
A separate rule is easy to confuse with that order: the same column can't be in both a row access policy signature and a masking policy signature. A masking policy always receives the column it masks as its first argument. So REGION, which the row access policy reads, can't be masked, and can't be a condition column of a masking policy either. Snowflake states the rule without giving a reason, so learn it as a fact.
QUERYSELECT * FROM salesAlice: ANALYST + EUROPE_ANALYST
TABLESALES40M rows stored
1 · POLICYRow accesskeep region = EUROPE12M rows remain
surviving rows
2 · POLICYMaskingCUSTOMER_EMAILmasked on those rows
3Result12M rows, emails masked
Worked example: entitlements as data
Setup, from the grant sheet: EUROPE_ANALYST is granted to Alice next to ANALYST, and with secondary roles ALL both are active in her session. Customer emails get their own policy, CUSTOMER_EMAIL_MASK, built like EMAIL_MASK but exempting DATA_ENGINEER: the pipeline needs clear emails to match customers. SYSADMIN inherits DATA_ENGINEER, so it sees them too; IsmaFrost accepts that for customer emails, unlike salaries.
CREATE MASKING POLICY governance_db. policies. customer_ email_ mask AS (val STRING) RETURNS STRING ->CASE WHEN IS_ROLE_ IN_ SESSION('DATA_ ENGINEER' ) THEN valELSE REGEXP_REPLACE( val, '.+@', '*****@') END; ALTER TABLE sales_db. core. sales MODIFY COLUMN customer_ SET MASKING POLICY governance_db. policies. customer_ email_ mask;
Writing role names inside the policy body works for two regions and breaks at twenty. The production pattern keeps entitlements in a mapping table that the policy reads. Onboarding a region then becomes an INSERT that Youness can delegate and audit, instead of a policy change.
CREATE TABLE governance_db. policies. region_ map (role_name STRING, region STRING); INSERT INTO governance_db. policies. region_ map VALUES ('EUROPE_ANALYST' , 'EUROPE'),('DATA_ENGINEER' , 'ALL');CREATE ROW ACCESS POLICY governance_db. policies. region_ access AS (sales_ region STRING) RETURNS BOOLEAN -> EXISTS (SELECT 1 FROM governance_db. policies. region_ map m WHERE IS_ROLE_ IN_ SESSION( m. role_ name) AND (m.region = sales_region OR m.region = 'ALL'));ALTER TABLE sales_db. core. sales ADD ROW ACCESS POLICY governance_db. policies. region_ access ON (region);
The policy body runs with the privileges of the policy's owner. Alice doesn't need, and doesn't get, SELECT on REGION_MAP.
| Who queries | Policy result | What comes back |
|---|---|---|
| Thomas · DATA_ | TRUE for every row | Every row |
| Alice · ANALYST + EUROPE_ | TRUE where region = 'EUROPE' | The European rows only |
| Amine · ANALYST only, no mapping row | FALSE for every row | 0 rows, and the query succeeds |
Limits and traps
Look at the last row of the table. Row access policies fail silently: no error, just an empty result. That is the design (Amine can't guess what he is missing) and also a debugging trap (an empty dashboard looks like a data problem). Before blaming the pipeline, list the policies attached to the table with the table function POLICY_REFERENCES:
SELECT *FROM TABLE(sales_ db. INFORMATION_ SCHEMA. POLICY_ REFERENCES( REF_ENTITY_ NAME => 'sales_ db. , REF_core. sales' ENTITY_ DOMAIN => 'table'));
To drop a policy, detach it first with ALTER TABLE … DROP ROW ACCESS POLICY.
Which protection does a scenario need?
Addresses and private endpoints. Says nothing about data.
A governance policy or a secure view.
"EUROPE_ANALYST sees only European rows."
Dynamic masking, or external tokenization when clear values can't be stored.
- A row access policy is a BOOLEAN per row, attached to a table or view, Enterprise and above.
- Row access is evaluated before masking. The same column can't be in both a row access and a masking policy signature.
- Sessions without entitlement get an empty result, not an error.

