Row-level security (RLS) in Snowflake restricts the set of rows returned by queries according to a user’s role or session context, enabling fine-grained data access control within the same table.
Row-level security (RLS) in Snowflake allows administrators to enforce fine-grained data access policies so that different users querying the same table automatically see only the rows they are authorized to view. Snowflake implements RLS through row access policies, which are reusable expressions attached to tables or views that evaluate at query time based on the current CURRENT_ROLE()
or other session parameters.
Modern analytics platforms ingest multi-tenant or highly sensitive datasets—think customer records, payroll, healthcare, or financial transactions. Duplicating tables for every tenant or permission group leads to data sprawl, complex ETL, and nightmare maintenance. Row-level security solves this by:
A ROW ACCESS POLICY
is a named object containing a Boolean SQL expression that returns TRUE
when a row is visible to the caller. Policies are created once and can be attached to multiple tables or views.
CREATE OR REPLACE ROW ACCESS POLICY rlp_customer_tenant
AS (tenant_id STRING) RETURNS BOOLEAN ->
tenant_id = CURRENT_ROLE();
WHERE
clause.CREATE ROLE tenant_a;
CREATE ROLE tenant_b;
-- Grant minimal privileges
GRANT USAGE ON DATABASE analytics TO ROLE tenant_a;
GRANT SELECT ON TABLE analytics.public.customers TO ROLE tenant_a;
CREATE OR REPLACE ROW ACCESS POLICY rlp_customers_tenant
AS (tenant_id STRING) RETURNS BOOLEAN ->
tenant_id = CURRENT_ROLE();
ALTER TABLE analytics.public.customers
ADD ROW ACCESS POLICY rlp_customers_tenant
ON (tenant_id);
-- Assume role Tenant A
USE ROLE tenant_a;
SELECT tenant_id, customer_name FROM analytics.public.customers;
-- Only rows where tenant_id = 'TENANT_A' are returned
Assume a sales table with columns order_id
, region
, sales_amount
, and sales_rep_id
. Regional managers should see only their region.
CREATE OR REPLACE ROW ACCESS POLICY rlp_sales_region
AS (region STRING) RETURNS BOOLEAN ->
region = CURRENT_REGION();
ALTER TABLE sales ADD ROW ACCESS POLICY rlp_sales_region ON (region);
-- Northeast manager
ALTER ROLE northeast_mgr SET TAG region = 'NE';
USE ROLE northeast_mgr;
SELECT SUM(sales_amount) FROM sales; -- returns NE data only
Snowflake caches query results aggressively. Ensure policy predicates rely on deterministic functions like CURRENT_ROLE()
or session variables to avoid cache leakage.
Create policies in a dedicated SECURITY
schema so they’re easy to audit and version-control.
Pair RLS with MASKING POLICIES
for a defense-in-depth approach.
Mistake: Policy signature does not match columns referenced in ON()
clause.
Fix: Make sure argument order and data types align exactly.
Mistake: Users can’t query table after policy applied because missing APPLY
privilege.
Fix: Grant APPLY ROW ACCESS POLICY
to necessary roles.
Mistake: Policy references CURRENT_TIMESTAMP()
causing inconsistent caching.
Fix: Stick to deterministic or session-stable functions.
Because Galaxy is a modern SQL IDE, defining and testing row access policies is straightforward:
CREATE ROW ACCESS POLICY
statement in a Galaxy tab with AI Copilot autocompleting role names and column lists.Snowflake’s QUERY_HISTORY
and ACCESS_HISTORY
views record which policies filtered what data. Periodically review these logs or set up alerts when policy changes occur.
Row-level security in Snowflake delivers powerful, maintainable, and performant fine-grained access control. By encapsulating business rules in reusable policies and leveraging role-based evaluations, teams can keep a single source of truth while meeting stringent compliance requirements. Tools like Galaxy further streamline development, testing, and collaboration around these policies, helping data engineers ship secure data products faster.
Without row-level security, companies often duplicate data by tenant or department, leading to governance nightmares and rising costs. Snowflake’s built-in row access policies let you enforce least-privilege, compliance-ready data access without extra ETL or table sprawl—critical for multi-tenant SaaS platforms and regulated industries.
A row access policy is a reusable security object containing a Boolean expression that Snowflake evaluates at query time to filter rows based on the user’s context, such as their current role or session variables.
Snowflake rewrites the query plan to push policy predicates down to micro-partitions, so performance impact is generally minimal. However, poorly written policies or non-deterministic functions can reduce caching efficiency.
Galaxy lets you switch SQL roles from a dropdown or keyboard shortcut. Run the same SELECT in different roles to confirm that the row access policy filters data correctly. You can save each test query in a Collection for peer endorsement.
Yes. Attach masking policies for sensitive columns and row access policies for row filtering. They run independently but together provide granular access control.