Home › Data engineering › Metric views › 6 · Row-level security

Data engineering · BI and analytics · free guide · 6 · Row-level security

Row-level security with metric views

Row-level security (RLS) means the same metric gives each person only their part: Asha manages the North and sees North revenue; Ravi runs sales nationally and sees all of it. With metric views, the rule of thumb is short: put RLS on the gold tables, not in the metric view, and drive it from one entitlements table.

Asha, NorthmanagerRavi, allregionssales_mv(metric view)fact_sales_linerow filter:region allowedfor current_user()?entitlements tableuser → regionsAsha sees North rowsRavi sees every rowlooks upmaterialization is refused while a row filter is on the source

The rule lives on the table. Every path to the data, the metric view included, passes through it.

How it works

Whose identity applies

A metric view is a view. As with any Unity Catalog view, access to the base tables is checked as the view's owner, which is why users need SELECT only on the metric view, not on the gold tables. But row filters and column masks on those tables run with the person querying: inside the filter function, current_user() and is_account_group_member() see the querying user. So one metric view, shared with everyone, returns different rows to different people.

Databricks made this explicit for tag-based (ABAC) policies: since 28 April 2026 they are evaluated as the session user for tables reached through views. Test it in your own workspace with two users before you go live (tests below).

Building it

Entitlements table, row filter, grant

-- 1. One entitlements table: who may see which region. Owned by a security team.
CREATE TABLE main.security.region_access (user_email STRING, region STRING);
INSERT INTO main.security.region_access VALUES
  ('asha@example.com', 'North'),
  ('ravi@example.com', '*');                        -- '*' = every region

-- 2. A row filter function. It runs for every row the user reads.
CREATE OR REPLACE FUNCTION main.security.region_filter(p_region STRING)
RETURN EXISTS (
  SELECT 1 FROM main.security.region_access a
  WHERE a.user_email = current_user() AND (a.region = p_region OR a.region = '*')
);

-- 3. Attach it to the gold fact. Keep region ON the fact (copied from the dealer
--    in gold) so the filter needs no join per row.
ALTER TABLE main.sales_gold.fact_sales_line
  SET ROW FILTER main.security.region_filter ON (region);

-- 4. People only get SELECT on the metric view, not on the gold tables.
GRANT SELECT ON VIEW main.sales_gold.sales_mv TO `sales-managers`;
-- A column mask: only finance sees cost, so gross margin is null for others.
CREATE OR REPLACE FUNCTION main.security.cost_mask(cost DECIMAL(18,2))
RETURN CASE WHEN is_account_group_member('finance') THEN cost ELSE NULL END;
ALTER TABLE main.sales_gold.fact_sales_line ALTER COLUMN cost_amount SET MASK main.security.cost_mask;

Masked columns flow into measures: a measure over a masked column returns null (or the masked value) for people outside the group.

Where to put it

Options with a verdict

Where RLS livesWhat happensVerdict
Row filter on the gold table, driven by an entitlements tableApplies to every reader of the table: metric views, SQL, dashboards, Genie, notebooks. One place to change who sees what.Pursue (default)
ABAC policies (tag-based row filters and masks)Same idea at scale: tag columns once, write the policy once for many tables. Since 28 Apr 2026, ABAC policies on base tables behind views are evaluated as the session user.Pursue at scale
filter: in the metric view YAML using current_user()Easy to bypass: anyone with SELECT on the gold table skips it; it is scope, not security; and it blocks materialization anyway.Drop
One metric view per region (sales_north_mv, sales_south_mv ...)Copies multiply, definitions drift, Genie gets confused.Drop
Dynamic views that hide rows with CASE on group membershipThe older pattern; works, but row filters are simpler and travel with the table.Only for legacy

The trade-off

Security blocks materialization

Databricks refuses to materialize a metric view whose view or source tables use row filters, column masks or ABAC policies, and refuses invoker functions such as current_user() in materializations. The reason is sound: a materialization is computed once, as the owner, so it would hold everyone's rows. What to do instead:

  • Make the gold tables fast: liquid clustering on the filter columns (date, region), statistics, predictive optimization. Most dashboards are fast enough on a right-sized warehouse.
  • Build your own aggregate table in gold (for example day × region × segment) in the pipeline, put the same row filter on it, and point a second metric view at it for the hot dashboards. It is small, so it is fast without materialization.
  • Split data that needs no security (company-wide KPIs shown to everyone) into its own metric view, and materialize that one.

Power BI too

When Power BI copies the data

Power BI DirectQuery with single sign-on runs as the user, so the Unity Catalog row filter applies. Import and Direct Lake copy the data out, so Power BI must apply its own role. Make that role read the same entitlements table, so there is still one list of who sees what. Details: RLS on both sides.

Prove it

Security tests to run before go-live

WhoAsksMust see
North managerSELECT region, MEASURE(net_revenue) ... GROUP BY ALLOnly North rows; North total equals the finance figure for North
All-regions userSame queryEvery region; grand total equals finance's company total
User with no entitlement rowSame queryZero rows, not an error and not everything
North manager via Genie'What was revenue by zone last month?'Only North, same number as the SQL
North manager via Power BI DirectQuery with SSOReport pageOnly North (runs as the user)
Power BI Import modelReport page as a North userOnly North because the Power BI role reads the same entitlements table

← 5 · Grain · Next: 7 · Speed →

FAQ

Questions people ask

Where should row-level security live with metric views?

On the gold tables, as Unity Catalog row filters (or ABAC policies) driven by one entitlements table. Every reader, including the metric view, then sees only allowed rows. Don't put security in the metric view's YAML filter.

Does a metric view run as the owner or as the user?

Access to the base tables is checked as the owner, like any view, so users only need SELECT on the metric view. Row filters and column masks on those tables evaluate as the querying user, so current_user() inside them is the person asking.

Can I materialize a metric view that has row-level security?

No. Databricks refuses materialization when the view or its sources use row filters, column masks or ABAC policies, because a materialization is computed once as the owner. Speed it up with table layout or your own secured aggregate table instead.

Sources

Checked against (11 Nov 2026)

Metric views change every few months. Confirm runtime minimums and preview status before a design depends on them.