Sub topic 13
Row-level security and source credentials in each mode
This chapter assumes you can build a star schema in Power BI Desktop, write basic DAX, and know what a workspace is. It covers two questions that change with storage mode: who sees which rows, and whose identity reaches the data source.
Two separate security layers
A semantic model has two layers of access control.
- Row-level security (RLS) limits which rows a report user sees. You define roles with DAX filter expressions on tables.
- Source credentials decide which identity the service uses to read the data source.
Storage mode affects both. Where RLS is enforced and when the source credential is used depend on the mode.
Row-level security in the semantic model
A role holds a DAX filter on a table. This filter limits a salesperson to their own region:
[SalesRegionEmail] = USERPRINCIPALNAME ()USERPRINCIPALNAME() returns the signed-in user's sign-in name. The filter flows through relationships to the fact table, so one rule on a dimension table is usually enough.
In Import mode, the VertiPaq engine applies the filter to the in-memory data. The source never sees the end user.
In DirectQuery mode, the filter is turned into a WHERE clause in the SQL sent to the source. Complex role expressions can produce slow SQL, so keep them simple.
In Direct Lake mode, the engine applies the role filter to the in-memory columns. If a query falls back to DirectQuery, the filter is applied in the SQL sent to the source instead.
Source credentials in each mode
| Mode | When the source is read | Credential used |
|---|---|---|
| Import | During refresh | The data source credential stored on the semantic model |
| DirectQuery | On every report query | Stored credential, or the viewer's identity if single sign-on (SSO) is on |
| Direct Lake | When columns load or on fallback | By default, the identity of the semantic model owner (a fixed identity), or the viewer's identity if you choose SSO |
Import is the simplest. Report viewers never touch the source, so they need no source permissions. Only the refresh credential matters, and refresh fails when that credential expires or its password changes.
DirectQuery has two options:
- Stored credential. Every viewer reaches the source as the same account. The source cannot tell users apart, so RLS must live in the semantic model.
- Single sign-on. The service passes the viewer's identity to the source. The source can then enforce its own row rules and auditing. Each viewer needs permissions there.
Combining model RLS and source security
Do not assume that source-side security carries over to the model. With a stored credential, the source returns everything that account can read, and only model RLS restricts viewers. With SSO, source security applies, and model RLS can apply on top of it. Pick one layer as the main control and test the other.
Also note that RLS roles do not apply to workspace members with Contributor or higher access. They can see all the data, so test roles with a viewer account or the "View as" feature in Desktop.
Mode effects on RLS design
Keep these points in mind:
- Role filters on large DirectQuery tables should use indexed columns, or each query will be slow.
- In a composite model, a role filter on an Import table does not stop a DirectQuery table from sending its own queries. Check the SQL the visual generates.
- Direct Lake with a fixed identity needs read access to the Delta tables for that identity, not for every viewer.
Exercise
A DirectQuery model uses a stored credential, and the source database has no row-level rules. How can you limit each salesperson to their own region, and why does the source not do it?
Show answer
Define an RLS role in the semantic model with a DAX filter such as [SalesRegionEmail] = USERPRINCIPALNAME(). The source sees only the one stored account for every query, so it cannot tell users apart. The model translates the role into a WHERE clause on the SQL it sends.
Exercise
An Import model refreshes nightly. On Monday the refresh starts failing, but viewers can still open the report. Why, and what do you check first?
Show answer
Viewers read the in-memory copy from the last good refresh, so the report still opens, but the data goes stale. Check the stored data source credential, which has probably expired or had its password changed, and update it in the semantic model settings.