Databricks Field Guide

Analysing and serving · Chapter 14

Databricks row-level security for multi-tenant reporting

Reviewed by TechFabric engineers. How we write this guide →

Row-level security on Databricks is a SQL function attached to a table (a row filter) or to a column (a column mask) that Unity Catalog evaluates on every query, using the reader's identity from current_user() or is_account_group_member(). For multi-tenant reporting the hard part is that identity: your employees arrive as themselves, but your customers' users usually arrive as your application's service principal, so the tenant has to travel in an embed token, a parameter, or (since October 2026) an OAuth custom identity claim the filter can read. This chapter covers each path with the SQL, as of 22 October 2026.

Andrey Taran, Senior Databricks Engineer at TechFabric, started a client project from a six-line ticket: dashboards inside a B2B product's own portal, changeable without a release, fast, and with no load on the application. None of the six lines mentioned tenants. Embedded viewers have no Databricks login, so Unity Catalog row filters couldn't keep one customer out of another's data, and isolation moved into the dashboard SQL, keyed on a tenant id carried in the embed token. He called it the requirement nobody wrote down when he told the story at the Dnipro Databricks User Group on 26 September 2026.

It also broke in the way this chapter is about. The tenant key used a pipe as a separator, Databricks rejected the token, the portal swallowed the error, and every dashboard went blank for every customer at once. The isolation failed closed, which is the direction you want, and still gave nobody an error to report.

That project is where our view of the embedded half of this problem comes from. The design question we'd ask first on any multi-tenant reporting build is whose identity actually arrives at the table, because the answer differs for your employees and for your customers' users, and it decides where each customer's boundary and each role's entitlements can be enforced.

The short version

If the reader has a login in your identity provider (an employee, an analyst, a partner you onboard), put the rule in Unity Catalog as a row filter or column mask and every tool inherits it. If the reader is your customer's user inside your product, they don't exist in your Databricks account; the query arrives as your application or the dashboard publisher, and the tenant predicate in your serving layer is now the security boundary. Treat that predicate as authentication code, test that a restricted reader sees nothing, and never filter a broad result in application code.

Whose identity reaches the table #

tenant predicate
in every query

token becomes a Postgres role

Employee or analyst
in your IdP

Databricks login

Unity Catalog row filter
current_user is the reader

Gold table

Customer's user
in your product

Your application

Service principal or publisher
sees every tenant

Lakebase
Postgres RLS

Two readers, two enforcement points: the catalog for people with a login, the serving layer for your customers' users

When the reader is an identified principal, row filters work as advertised. The query runs as that person, current_user() returns them, is_account_group_member() resolves their real groups, and the rule holds whether they arrive through a dashboard, the SQL editor, a notebook or a JDBC tool you've never heard of. That's why we'd keep internal entitlements in the catalog rather than in a BI tool, where a filter holds only for people who come in through that tool.

When the reader is your customer's user, none of that applies. From the platform's point of view there's one reader, and it's entitled to everything. The identity has to be carried explicitly, as a tenant value in an embed token, a parameter on a query your server issues, or a session variable that Postgres row-level security reads.

One service principal, many end users: custom identity claims #

Databricks now has a platform answer for applications that query on behalf of their own users. When your server requests an OAuth token for its service principal, it can add a custom_claim (with the client_credentials grant, or the token-exchange grant for workload identity federation), and SQL reads it back with current_oauth_custom_identity_claim() (custom identity claims, updated 21 October 2026). It needs compute on Databricks Runtime 19 or above, and the claim reaches SQL only through the JDBC driver on a SQL warehouse, the SQL Statement Execution API and the Genie Agents API; the workspace SQL editor never carries one.

curl -s -X POST "https://<workspace-host>/oidc/v1/token" \
  -u "$SP_CLIENT_ID:$SP_CLIENT_SECRET" \
  -d grant_type=client_credentials -d scope=all-apis \
  --data-urlencode "custom_claim=dealer-4471"
CREATE OR REPLACE VIEW originations_prd.gold.loan_application_by_dealer AS
SELECT *
FROM originations_prd.gold.loan_application
WHERE dealer_id = current_oauth_custom_identity_claim();   -- NULL claim matches nothing

GRANT SELECT ON VIEW originations_prd.gold.loan_application_by_dealer TO `dealer-portal-apps`;   -- a group holding the app's service principal

The function reference is specific about how to write that predicate: plain equality, so a token with no claim returns no rows, and never IS NULL, coalesce or <=>, which can turn a missing claim into every customer's data. Use the claim only as a comparison value, never in RLIKE, an IDENTIFIER or EXECUTE IMMEDIATE. Grant the service principal the view only, never the base table or a mapping table, or it can simply read around the filter. The claim is signed but not encrypted (anyone holding the token can read it), it's limited to 1,000 printable ASCII characters, and your server must choose it, never copy it from request input. Genie conversations started this way belong to the service principal, so the application has to track which of its users owns each one.

That makes the service that mints tokens the control an auditor reviews, and we'd give it the same scrutiny as the predicate in the view.

Readers with a login: rules in the catalog #

A row filter is a SQL function that returns a boolean per row; a column mask returns the value or something safer. This is the shape we'd use for a gold table where every row carries a dealer_id:

CREATE OR REPLACE FUNCTION originations_prd.gold.loan_tenant_filter(dealer_id STRING)
RETURN is_account_group_member('loans-internal-all-tenants')
    OR is_account_group_member(concat('tenant-', dealer_id, '-readers'));

ALTER TABLE originations_prd.gold.loan_application
  SET ROW FILTER originations_prd.gold.loan_tenant_filter ON (dealer_id);

CREATE OR REPLACE FUNCTION originations_prd.gold.mask_applicant_ssn(ssn STRING)
RETURN CASE WHEN is_account_group_member('loans-pii-readers') THEN ssn
            ELSE concat('XXX-XX-', right(ssn, 4)) END;

ALTER TABLE originations_prd.gold.loan_application
  ALTER COLUMN applicant_ssn SET MASK originations_prd.gold.mask_applicant_ssn;

The limitations decide where these go. You can't apply a row filter or column mask to a view, so the policy sits on the table underneath and every view reads through it. Two more shape a design. Filtered tables lose time travel and cloning, and a MERGE into one fails for many policy shapes, so we'd put policies on the gold tables people read and never on a silver table a pipeline merges into. And a policy function can't read a table that has its own active policy, which rules out the obvious design of an entitlement lookup table that is itself protected.

When the same rule has to cover dozens of tables, Databricks recommends ABAC policies, which attach at catalog or schema level and apply to every table carrying a governed tag, over table-by-table filters (row filters and column masks, updated 9 October 2026). Table-level filters also need Runtime 12.2 LTS or above, and dedicated-access clusters read filtered tables only on 15.4 LTS and above, through serverless fine-grained access control.

For entitlements inside a tenant (a regional manager sees three branches, a rep sees eleven accounts), keep the filter a CASE over group membership where the set is small and stable. Where it changes daily, we'd materialise the entitlement into the gold table as a derived key the filter can test, refreshed by the pipeline, so the join runs once at build time instead of inside every scan.

How tenants are laid out is the other early decision. A catalog per tenant makes the boundary a grant, which auditors like, and costs a schema migration run N times. A shared table with a tenant key scales to thousands of tenants and makes the filter security-critical code. Our rule of thumb is a catalog each below a few dozen tenants with slow growth, and the shared table above that or wherever tenants sign up self-service, with a large or regulated tenant moved to its own catalog when a contract asks for it. On a shared table, liquid clustering on the tenant key lets file pruning discard most of the data before the filter runs.

Customers' users with no login: the predicate is the boundary #

AI/BI dashboards can be embedded for external viewers, and this is the path Andrey's project took. Your server mints a user-scoped token carrying two values, and the page hands it to DatabricksDashboard from @databricks/aibi-client. external_viewer_id lands in the audit logs and must not contain personal data; external_value is what every dataset filters on.

no: a pipe in the key

yes

yes

no

Your server mints a token
external_value = tenant key

Token accepted?

Every dashboard blank,
no error shown

Dataset has
WHERE tenant =
__aibi_external_value?

That tenant's rows,
on the publisher's compute

Every tenant's rows:
a cross-tenant leak

How the tenant value reaches the rows in an embedded dashboard, and the two ways it fails
SELECT *
FROM originations_prd.gold.loan_application
WHERE dealer_id = __aibi_external_value

Three properties of that design are what we'd check in review. Compute runs on the publisher's credentials, so whoever runs the query can see every tenant and the WHERE in each dataset is the isolation boundary; one dataset without it leaks. The two values together can't exceed 1 KB, so the tenant key has to be compact, and, as the pipe showed, made of characters the token accepts (the project uses a tilde now). And Ask Genie isn't available in external embedding, so natural-language questions for customers go through the Genie Conversation API from your own server.

Andrey's slides add two more lessons we'd carry into any embedded build. A scope version doubles as the cache key, so changing one tenant's access clears that tenant's cache and nobody else's. And transferring ownership of a view took away access the dashboards relied on and caused an outage, which is why we'd let a group own production objects, as Unity Catalog argues for grants.

What the predicate costs at production scale #

Putting the tenant predicate in every dataset means the number of datasets and where the rows live decide what each customer's page load costs, and Andrey's project measured both.

Over Lakehouse Federation to Azure SQL, an aggregated dataset pushed its GROUP BY down and returned in about 5 seconds, while a raw-row dataset didn't push down and took about 50 (part 2 of his series). The talk showed a view that filtered one side of a join and not the other, which had Azure SQL send 6.46 million rows in production to show about 800, against a test table of 130,000 rows. Our reading is that a tenant predicate has to reach the table it filters, so we'd put it in the view under the dataset as well as in the dataset.

How many datasets a board ends up with, and what running them together costs, is in Reporting. Moving everything into Delta took a full dashboard load from about two minutes to 20 seconds.

Decision What we'd choose for an embedded, multi-tenant board Why, on those numbers
Where the predicate lives A Unity Catalog view under every dataset, repeated in the dataset One missing WHERE leaks; one the source can't push down costs a full scan
Datasets per board One row-level dataset, plus only the pivots and top-N tables that can't share it Every extra dataset is another query per load and per filter click
Federation or Delta Federation for the demo, Delta before the first real customer Two minutes against 20 seconds for a full load
Before each deploy Open every embedded dashboard with a real token for two tenants A rejected token and a wrong join both render as an empty chart

Application reads: row-level security in Postgres #

When the product's own pages need tenant data, as opposed to a dashboard, we'd put the read model in Lakebase and let Postgres row-level security enforce the tenant. At the first Gilbert Databricks User Group session each OAuth token arrived as a Postgres role, and one policy on demo_app.orders gave three roles three answers: the owner saw every row, a service principal got an empty array for rows it couldn't read, and an insert the policy would have hidden came back 403. For customers who share one application role, we'd key the same kind of policy to a session variable the application sets before any query, and test that a missing variable returns nothing.

Testing the negative case #

The test that matters is that a restricted reader doesn't see rows they shouldn't. We'd run a suite on every pipeline run, not once at handover, that connects as a principal in each entitlement group and asserts an empty result for every scope it doesn't hold. For embedded dashboards we'd do what Andrey's team does on every deploy, open each one with a real token, and add a second tenant whose rows must not appear. The pipe in the tenant key passed every length check and still blanked every board, and only a test with a real token would have caught it before customers did.

For an auditor, Unity Catalog's system tables answer the two questions they actually ask, who was granted access to this tenant's data and who read it, as queries with dated evidence. We'd also write the deletion path for a departing tenant next to the ingestion path from the start, since it has to reach bronze, silver, gold, the serving layer and every export.