A Snowflake row access policy is a schema-level object that dynamically controls row visibility during query execution. Policies receive input columns (for example, a region_id or customer_account), use context functions to check the querying user’s privileges, and return TRUE or FALSE for each row—deciding which rows pass through.
In well-architected deployments:
- Policies use only current session context and entitlements—no hard-coded user lists.
- Policy code is kept clean by deferring access mapping to a central entitlements table or RBAC matrix. This ensures strong performance and makes expansion or audits trivial.
- Policies can support advanced scenarios, like restricting based on multiple columns or supporting multi-role inheritance, using features such as IS_ROLE_IN_SESSION().
Pro tip: Avoid embedding detailed business logic or static lists in the policy itself. This centralization ensures that scaling or updating access models never becomes a development bottleneck.
How Policies Use CURRENT_ROLE() and IS_ROLE_IN_SESSION()
Dynamic row-level filtering in Snowflake hinges on these key functions:
- CURRENT_ROLE() returns the user’s active Snowflake role. Use it for simple, direct role enforcement.
- IS_ROLE_IN_SESSION(‘ROLE_NAME’) checks if a given role is active in the user’s current session, supporting multi-role inheritance, privilege chaining, and cleaner handling of RBAC models.
By tying policy logic to these context-aware functions rather than manual lists, you get automation-friendly, maintainable access models. For instance, supporting a new department or rotating out old roles is as easy as updating the entitlements table—no code changes required.
Critical: Always avoid embedding explicit user identifiers or entitlements in your SQL policy code. Leverage these functions and external mapping tables for maintainable RLS.
Why a Centralized Mapping Table is a Best Practice
Embedding all logic inside RLS policies is risky and unscalable. Instead, maintain a centralized entitlements table mapping Snowflake roles to allowed values (such as which region or business unit codes they can access). This model:
- Decouples Security from Code: Admins can grant, revoke, or audit access by updating entitlements records—no policy changes or redeployment needed.
- Enables Audit-readiness: You can export a point-in-time snapshot showing exactly which roles can access which rows, a key requirement under regulations like GDPR.
- Accelerates Multi-role Access: Managing cross-functional access for roles like auditors, analysts, or regional leads is reduced to configuration, not development. For example, granting a role access to multiple regions is a single insert operation.
- Supports Efficient Query Plans: Properly indexed entitlements tables and lean policy logic reduce join complexity, keeping both performance and costs optimal as your organization grows.
This is a Snowflake security best practice, helping you avoid pitfalls flagged in industry research and competitor guides—like hard-to-manage secure views or policy code bloat (see ThinkETL).