Context Lab

UC RLS method picker

Education helper for Unity Catalog row-level security · Not a compliance guarantee · Not affiliated with Databricks, Inc.

You need row limits by country (e.g. HK vs SG) and sometimes region (e.g. APAC) on Unity Catalog tables, and the same idea should hold when BI tools query Databricks. Three common patterns overlap. Answer the questions, then read the matching mini-example below.

Three Unity Catalog RLS patterns: ABAC with governed tags, table row filters, and dynamic SQL views
ABAC · row filter · dynamic view — pick by scale and logic (original)

Your setup

Simple examples (fiction · HK retail)

Same made-up world for all three: fact table sales.orders with columns country (HK/SG) and region (APAC). Analyst Ada is allowed HK only. Sketches for learning — not copy-paste production policy.

1) ABAC — many tables, one central rule

Story: 60+ fact tables all have a country column. Platform owns access; domains should not paste 60 copies of the same SQL.

Why pick this: Tag the column once, attach one attribute-based policy. Ada (country=HK) only sees HK rows on every tagged table.

-- Education sketch (names/APIs vary by release)
ALTER TABLE sales.orders SET TAGS ('rls.country' = 'country');
-- Policy idea: user.attr.country must match the tagged column value
-- Ada → HK rows only on orders, shipments, returns, …

2) Row filter — one table, simple column

Story: Only sales.orders needs RLS for now. The rule is “row.country equals Ada’s country.” Everyone still queries the same table name.

Why pick this: Fastest when logic is a single-table predicate and you do not want a new view name for every consumer.

-- Education sketch
CREATE FUNCTION gov.country_filter(country STRING)
RETURNS BOOLEAN
RETURN country = current_user_country();  -- Ada → 'HK'

ALTER TABLE sales.orders
SET ROW FILTER gov.country_filter ON (country);

3) Dynamic view — region↔country mapping

Story: Ada is an APAC lead who may see HK+SG via a mapping table, not a single attribute on orders. Domain owners iterate in SQL.

Why pick this: Use when the rule needs a join (user → allowed region/country). Grant the view; keep the base table locked down.

-- Education sketch
CREATE VIEW sales.orders_rls AS
SELECT o.*
FROM sales.orders o
JOIN gov.user_region_map m
  ON m.user_email = current_user()
 AND o.region = m.region
 AND o.country = m.country;
-- Ada's map rows: (Ada, APAC, HK), (Ada, APAC, SG)

Deep dive: OAuth vs service principal (and Fabric). Shared BI identities (one PAT / service principal) collapse “Ada” into one principal — UC still filters as that principal, not each analyst. Prefer OAuth / per-user when you need true per-person RLS into Databricks.