Tag: Row Level Security

Design and implement Row-Level Security (RLS) (DP-800 Exam Prep)

This post is a part of the DP-800: Developing AI-Enabled Database Solutions Exam Prep Hub.
This topic falls under these sections:
Secure, optimize, and deploy database solutions (35–40%)
   --> Implement data security and compliance
      --> Design and implement Row-Level Security (RLS)


Note that there are 10 practice questions (with answers) at the end of each section to help you solidify your knowledge of the material. Also, there are 4 practice tests with 30 questions each available from the hub's main page below the exam topics section.

What is Row-Level Security (RLS)?

Row-Level Security (RLS) is a SQL Server and Azure SQL Database feature that restricts which rows a user can access based on a security policy. Rather than controlling access to an entire table, RLS filters data so that users see only the rows they are authorized to view.

For example, a Sales table might contain data for all sales regions:

SalesPersonRegionSales
AliceEast125000
BobWest98000
CarolNorth143000
DavidSouth110000

With RLS enabled:

  • Alice sees only East region rows.
  • Bob sees only West region rows.
  • Regional managers see only their assigned regions.
  • Executives may see all rows.

The application continues to query the entire table, but SQL Server automatically filters the results.


Why Use Row-Level Security?

Many organizations have users who should share the same tables while viewing different subsets of the data.

Common scenarios include:

  • Multi-tenant Software-as-a-Service (SaaS) applications
  • Regional sales reporting
  • Department-specific HR records
  • Healthcare systems where providers access only their patients
  • Educational systems where instructors see only their own students
  • Financial institutions with branch-specific records

Without RLS, developers often implement filtering within application code. RLS centralizes these security rules inside the database, reducing development effort and improving security.


How Row-Level Security Works

RLS works by attaching a security policy to a table.

When a query executes:

  1. SQL Server identifies the current user.
  2. A predicate function evaluates each row.
  3. Only rows that satisfy the predicate are returned.

This occurs automatically without modifying application queries.


Row-Level Security Architecture

Application
SELECT * FROM Orders
Security Policy
Predicate Function
Only Authorized Rows Returned

The application does not need to include a WHERE clause because SQL Server applies the filtering automatically.


Components of Row-Level Security

RLS consists of three primary components:

1. Predicate Function

A predicate function determines whether a row should be visible.

Typically, this is an inline table-valued function.

Example:

CREATE FUNCTION Security.fn_FilterSales
(
@SalesRegion NVARCHAR(50)
)
RETURNS TABLE
WITH SCHEMABINDING
AS
RETURN
SELECT 1 AS fn_result
WHERE @SalesRegion = USER_NAME();

This function allows users to see rows only when the SalesRegion value matches their database user name.


2. Security Policy

The security policy associates the predicate function with a table.

Example:

CREATE SECURITY POLICY SalesFilter
ADD FILTER PREDICATE
Security.fn_FilterSales(SalesRegion)
ON dbo.Sales
WITH (STATE = ON);

Once enabled, every query against the Sales table automatically uses the filter.


3. Protected Table

The protected table contains the actual business data.

Applications continue to issue normal SELECT, UPDATE, DELETE, and MERGE statements while SQL Server enforces the policy.


Types of Security Predicates

SQL Server supports two predicate types.

Filter Predicate

A filter predicate limits which rows users can read.

Example:

SELECT *
FROM Sales;

The query returns only rows authorized by the security policy.

This is the most commonly used predicate.


Block Predicate

A block predicate prevents unauthorized modifications.

It can prevent:

  • INSERT
  • UPDATE
  • DELETE

Example:

A user may be allowed to read only West region rows and may also be prevented from inserting East region records.


Block Predicate Types

Block predicates can be applied:

  • BEFORE INSERT
  • AFTER INSERT
  • BEFORE UPDATE
  • AFTER UPDATE
  • BEFORE DELETE

This provides fine-grained control over data modifications.


Example: Multi-Tenant Application

Imagine a SaaS application storing customer records.

CustomerIDTenantIDCustomerName
101TenantAABC Company
102TenantBXYZ Industries
103TenantAContoso Ltd

Instead of creating separate databases for every customer, one database stores all tenants.

The predicate function filters rows by TenantID so that:

  • TenantA users see only TenantA records.
  • TenantB users see only TenantB records.

Applications require no additional filtering logic.


Example: Sales Regions

Sales table:

EmployeeRegion
AliceEast
BobWest
CarolEast
DavidSouth

Logged-in user:

EastManager

Predicate:

WHERE Region = USER_NAME()

Result:

EmployeeRegion
AliceEast
CarolEast

Other regions are invisible.


Creating an RLS Policy

Step 1: Create Schema

CREATE SCHEMA Security;

Step 2: Create Predicate Function

CREATE FUNCTION Security.fn_FilterRegion
(
@Region NVARCHAR(50)
)
RETURNS TABLE
WITH SCHEMABINDING
AS
RETURN
SELECT 1
WHERE @Region = USER_NAME();

Step 3: Create Security Policy

CREATE SECURITY POLICY RegionFilter
ADD FILTER PREDICATE
Security.fn_FilterRegion(Region)
ON dbo.Sales
WITH (STATE = ON);

The policy immediately begins protecting the table.


Disabling a Security Policy

ALTER SECURITY POLICY RegionFilter
WITH (STATE = OFF);

The policy remains defined but no longer filters data.


Re-enabling the Policy

ALTER SECURITY POLICY RegionFilter
WITH (STATE = ON);

Dropping a Security Policy

DROP SECURITY POLICY RegionFilter;

Security Context Functions

RLS frequently uses identity functions.

Common examples include:

FunctionPurpose
USER_NAME()Current database user
SUSER_SNAME()Login name
SESSION_CONTEXT()Session-specific values
ORIGINAL_LOGIN()Original login before impersonation

These functions allow security decisions based on the current user or application context.


SESSION_CONTEXT()

Many enterprise applications use SESSION_CONTEXT() rather than database usernames.

Example:

EXEC sp_set_session_context
@key='TenantID',
@value='TenantA';

Predicate:

WHERE
@TenantID =
SESSION_CONTEXT(N'TenantID');

This approach works well in web applications where many users connect using a shared database login.


Benefits of Row-Level Security

Centralized Security

Rules exist inside the database instead of multiple applications.


Transparent to Applications

Applications issue normal SQL statements.

No code changes are typically required.


Consistent Enforcement

Every query is filtered automatically.

Developers cannot accidentally omit security filters.


Simplifies Development

No need to duplicate WHERE clauses throughout application code.


Improved Maintainability

Security policies can be updated without changing application logic.


Limitations

Not a Replacement for Authentication

Users must still authenticate.

RLS determines only which rows are visible.


Does Not Encrypt Data

Use:

  • Always Encrypted
  • Transparent Data Encryption (TDE)

when encryption is required.


Does Not Mask Data

Use:

  • Dynamic Data Masking

when users should see masked values instead of hidden rows.


Predicate Performance

Complex predicate functions can reduce query performance.

Predicate functions should remain efficient.


RLS vs Dynamic Data Masking

Row-Level SecurityDynamic Data Masking
Hides rowsMasks column values
User cannot see unauthorized recordsUser sees rows but masked data
Controls access to recordsControls visibility of sensitive columns
Based on predicatesBased on masking functions
Often used with DDMOften combined with RLS

RLS vs Always Encrypted

Row-Level SecurityAlways Encrypted
Controls visible rowsEncrypts stored values
Server evaluates predicatesClient decrypts data
Data remains readable by authorized usersDatabase cannot read encrypted values without client-side decryption
Access controlConfidentiality protection

Best Practices

Keep Predicate Functions Simple

Simple predicates improve query performance.


Use SCHEMABINDING

Predicate functions should use:

WITH SCHEMABINDING

This prevents changes that could invalidate the security policy.


Use SESSION_CONTEXT() for Web Applications

This scales better than relying solely on database usernames.


Test with Non-Administrative Accounts

Database administrators often bypass normal security scenarios.

Always validate RLS using standard user accounts.


Combine with Other Security Features

For comprehensive protection, combine RLS with:

  • Dynamic Data Masking
  • Always Encrypted
  • Transparent Data Encryption
  • Microsoft Entra authentication
  • Least-privilege permissions
  • SQL auditing

DP-800 Exam Tips

Candidates should be able to:

  • Explain the purpose of Row-Level Security.
  • Differentiate filter predicates from block predicates.
  • Understand the role of predicate functions and security policies.
  • Create RLS using inline table-valued functions.
  • Enable, disable, and drop security policies.
  • Use USER_NAME(), SUSER_SNAME(), and SESSION_CONTEXT() in predicate functions.
  • Differentiate RLS from Dynamic Data Masking and Always Encrypted.
  • Identify common scenarios such as multi-tenant SaaS applications.
  • Recognize that RLS is transparent to application code.

Practice Exam Questions

Question 1

A company stores sales records for all regions in a single table. Regional managers should view only the rows for their assigned region.

Which SQL Server feature should you implement?

A. Transparent Data Encryption

B. Row-Level Security

C. Dynamic Data Masking

D. Always Encrypted

Answer: B

Explanation: Row-Level Security filters rows based on a security policy so users automatically see only the records they are authorized to access.


Question 2

Which object determines whether a row is visible to a user in Row-Level Security?

A. Security predicate function

B. Database trigger

C. View

D. Stored procedure

Answer: A

Explanation: An inline table-valued predicate function evaluates each row and determines whether it should be returned.


Question 3

Which statement about Row-Level Security is correct?

A. It encrypts rows before storage.

B. It permanently removes unauthorized rows.

C. It automatically filters query results according to a security policy.

D. It masks sensitive column values.

Answer: C

Explanation: RLS evaluates a security policy during query execution and returns only authorized rows without modifying the stored data.


Question 4

Which type of security predicate prevents unauthorized INSERT, UPDATE, or DELETE operations?

A. Filter predicate

B. Access predicate

C. Security predicate

D. Block predicate

Answer: D

Explanation: Block predicates prevent users from performing unauthorized data modifications.


Question 5

Which function is commonly used in web applications to store tenant-specific information for Row-Level Security?

A. CURRENT_USER

B. SESSION_CONTEXT()

C. USER_ID()

D. DB_NAME()

Answer: B

Explanation: SESSION_CONTEXT() stores key-value pairs for the current session, making it ideal for multi-tenant applications.


Question 6

A developer creates the following policy:

ADD FILTER PREDICATE
Security.fn_FilterRegion(Region)
ON dbo.Sales;

What is the effect?

A. Rows are encrypted.

B. Columns are masked.

C. Unauthorized rows are automatically filtered from query results.

D. The table becomes read-only.

Answer: C

Explanation: A filter predicate restricts which rows are returned based on the predicate function.


Question 7

Which statement best describes the relationship between applications and Row-Level Security?

A. Applications must include special WHERE clauses.

B. Applications require encryption libraries.

C. Applications typically require no changes because SQL Server applies filtering automatically.

D. Applications cannot use SELECT * statements.

Answer: C

Explanation: RLS is transparent to applications. SQL Server automatically applies the filtering logic defined in the security policy.


Question 8

Which feature is most appropriate when users should see every row but sensitive values should be partially hidden?

A. Row-Level Security

B. Always Encrypted

C. Transparent Data Encryption

D. Dynamic Data Masking

Answer: D

Explanation: Dynamic Data Masking hides sensitive column values while still allowing users to access all authorized rows.


Question 9

Which statement is true regarding Row-Level Security?

A. It replaces authentication.

B. It determines which rows a user can access after authentication.

C. It encrypts the database backup.

D. It compresses tables.

Answer: B

Explanation: Authentication establishes the user’s identity, while RLS determines which rows that authenticated user is allowed to access.


Question 10

Which practice is recommended when designing Row-Level Security policies?

A. Use complex scalar functions to maximize flexibility.

B. Disable SCHEMABINDING to simplify maintenance.

C. Keep predicate functions simple and efficient to minimize performance overhead.

D. Place all filtering logic in application code instead of the database.

Answer: C

Explanation: Efficient predicate functions help reduce the performance impact of Row-Level Security while maintaining centralized, database-enforced access control.


Go to the DP-800 Exam Prep Hub main page

Configure Row-Level Security Group Membership (PL-300 Exam Prep)

This post is a part of the PL-300: Microsoft Power BI Data Analyst Exam Prep Hub; and this topic falls under these sections:
Manage and secure Power BI (15–20%)
--> Secure and govern Power BI items
--> Configure Row-Level Security Group Membership


Note that there are 10 practice questions (with answers and explanations) at the end of each topic. Also, there are 2 practice tests with 60 questions each available on the hub below all the exam topics.

Overview

Configuring Row-Level Security (RLS) group membership is a key governance and scalability topic within the “Manage and secure Power BI (15–20%)” domain of the PL-300: Microsoft Power BI Data Analyst certification exam. This topic builds on basic RLS concepts and focuses on how users are assigned to RLS roles, with an emphasis on using Microsoft Entra ID (Azure AD) security groups instead of individual users.

For the exam, you should understand where RLS roles are defined, where group membership is configured, how group-based RLS behaves, and why it is considered a best practice.


What Is RLS Group Membership?

RLS group membership refers to assigning security groups (rather than individual users) to Row-Level Security roles in a Power BI semantic model. Any user who is a member of the group automatically inherits the data access defined by the role.

This approach:

  • Improves scalability
  • Simplifies administration
  • Aligns with enterprise security standards
  • Reduces ongoing maintenance

Exam Focus: The PL-300 exam strongly favors group-based RLS as the recommended approach.


Where RLS Group Membership Is Configured

Understanding where actions occur is frequently tested.

Power BI Desktop

  • Create RLS roles
  • Define DAX filter expressions
  • No users or groups are assigned here

Power BI Service

  • Assign users or security groups to RLS roles
  • Manage role membership after publishing

Key Distinction:

  • Roles and filters → Desktop
  • Users and groups → Service

Why Use Security Groups for RLS?

Benefits of Group-Based RLS

  • Centralized identity management
    Groups are managed in Microsoft Entra ID, not Power BI.
  • Automatic access updates
    Adding or removing users from a group instantly updates data access.
  • Reduced administrative effort
    No need to modify RLS settings when staff changes.
  • Auditability and compliance
    Easier to review who has access and why.

Exam Tip: If a question asks for the most scalable or best practice approach, choose security groups.


Types of Groups Used in RLS

Supported Group Types

  • Microsoft Entra ID security groups (recommended)
  • Mail-enabled security groups

Not Recommended / Not Supported

  • Distribution lists (not ideal for security)
  • Microsoft 365 groups (not designed for RLS scenarios)

PL-300 Expectation: Know that security groups are the preferred option for RLS role membership.


Assigning Groups to RLS Roles

Step-by-Step (Power BI Service)

  1. Publish the semantic model from Power BI Desktop
  2. In the Power BI Service, open the semantic model
  3. Select Security
  4. Choose an RLS role
  5. Add one or more security groups
  6. Save changes

Once assigned, all group members inherit the role’s data filters.


Group Membership and Dynamic RLS

Group membership is often combined with dynamic RLS for maximum flexibility.

Common Pattern

  • RLS role contains a dynamic filter using USERPRINCIPALNAME()
  • A mapping table links users to business entities (e.g., region, department)
  • A security group controls who is subject to that role

This pattern:

  • Minimizes the number of roles
  • Supports large organizations
  • Separates identity management from data logic

How Group-Based RLS Is Evaluated

When a user opens a report:

  1. Power BI identifies the user’s Entra ID group memberships
  2. The user is matched to assigned RLS roles
  3. The union of all applicable role filters is applied
  4. Only authorized rows are returned

Important Exam Concept:
Users in multiple roles see the combined (union) of allowed data—not the most restrictive set.


Testing Group-Based RLS

In Power BI Desktop

  • Use View as
  • Test role logic only (group membership is not evaluated here)

In Power BI Service

  • Use View as role
  • Or test by signing in as a user who belongs to the group

Exam Awareness: Group membership itself cannot be fully tested in Desktop—only in the Service.


Common Pitfalls (Exam-Relevant)

  • Assigning individual users instead of groups
  • Expecting RLS to apply before publishing
  • Forgetting that group membership changes happen outside Power BI
  • Confusing workspace roles with RLS roles
  • Assuming admins bypass RLS automatically

RLS Group Membership vs Workspace Roles

FeatureWorkspace RolesRLS Group Membership
Controls content access
Controls data visibility
Uses Entra ID groups
Defined in Desktop
Assigned in Service

PL-300 Focus: These are complementary—not interchangeable—security mechanisms.


Governance and Best Practices

  • Always prefer security groups over individuals
  • Use clear, business-aligned group names
  • Keep RLS logic simple and documented
  • Coordinate with identity administrators
  • Review group membership regularly

Common Exam Scenarios

You may be asked to identify:

  • The best way to manage RLS for hundreds of users
  • Why a user gained or lost data access without a model change
  • Where to update access when an employee changes roles
  • How group membership impacts RLS evaluation

Key Takeaways for the PL-300 Exam

  • RLS roles are defined in Power BI Desktop
  • Group membership is configured in the Power BI Service
  • Microsoft Entra ID security groups are the recommended approach
  • Group-based RLS improves scalability and governance
  • Users see the union of all assigned RLS roles
  • RLS applies to all reports and apps using the semantic model

Practice Questions

Go to the Practice Questions for this topic.

Implement Row-Level Security (RLS) Roles (PL-300 Exam Prep)

This post is a part of the PL-300: Microsoft Power BI Data Analyst Exam Prep Hub; and this topic falls under these sections:
Manage and secure Power BI (15–20%)
--> Secure and govern Power BI items
--> Implement Row-Level Security (RLS) Roles


Note that there are 10 practice questions (with answers and explanations) at the end of each topic. Also, there are 2 practice tests with 60 questions each available on the hub below all the exam topics.

Overview

Implementing Row-Level Security (RLS) is a critical skill for Power BI Data Analysts and a key topic within the “Manage and secure Power BI (15–20%)” domain of the PL-300: Microsoft Power BI Data Analyst certification exam. RLS ensures that users only see the data they are authorized to view, even when accessing the same reports or semantic models.

For the exam, you must understand how RLS roles are created, how they are implemented using DAX, how users and groups are assigned, and how RLS behaves in the Power BI Service.


What Is Row-Level Security?

Row-Level Security restricts access to specific rows of data in a semantic model based on the identity of the user viewing the report.

RLS:

  • Is defined in Power BI Desktop
  • Uses DAX filter expressions
  • Is enforced in the Power BI Service
  • Applies to all reports that use the semantic model

Key Concept: RLS controls data visibility, not report visibility.


RLS Architecture in Power BI

The RLS workflow consists of four main steps:

  1. Define roles in Power BI Desktop
  2. Create DAX filter expressions for tables
  3. Publish the semantic model to the Power BI Service
  4. Assign users or groups to roles in the Service

Each role defines which rows are visible when the user is a member of that role.


Creating RLS Roles in Power BI Desktop

Step 1: Create Roles

In Power BI Desktop:

  • Go to Model view or Report view
  • Select Modeling → Manage roles
  • Create one or more roles (e.g., SalesWest, SalesEast)

Roles are placeholders until users or groups are assigned in the Power BI Service.


Step 2: Define Table Filters (DAX)

RLS is implemented using DAX filter expressions applied to tables.

Example: Static RLS

[Region] = "West"

This filter ensures that users assigned to the role only see rows where Region equals West.

Exam Tip: RLS filters act like WHERE clauses and reduce visible rows—not columns.


Static vs Dynamic RLS

Static RLS

  • Filters are hardcoded values
  • Each role represents a specific segment
  • Easy to understand, but not scalable

Example:

[Department] = "Finance"


Dynamic RLS (Highly Exam-Relevant)

Dynamic RLS uses the logged-in user’s identity to filter data automatically.

Common functions:

  • USERPRINCIPALNAME()
  • USERNAME()

Example:

[Email] = USERPRINCIPALNAME()

Dynamic RLS:

  • Scales well
  • Reduces number of roles
  • Is commonly used in enterprise models

Best Practice: Use dynamic RLS with a user-to-dimension mapping table.


Assigning Users to RLS Roles (Power BI Service)

After publishing the semantic model:

  1. Go to the Power BI Service
  2. Navigate to the semantic model
  3. Select Security
  4. Assign users or Microsoft Entra ID (Azure AD) groups to roles

Best Practice: Always assign security groups, not individual users.


Testing RLS

In Power BI Desktop

  • Use Modeling → View as
  • Test roles before publishing
  • Validate DAX logic

In Power BI Service

  • Use View as role
  • Confirm correct filtering for assigned users

Exam Tip: “View as” does not bypass RLS—it simulates user access.


RLS Behavior in Common Scenarios

Reports and Dashboards

  • RLS applies automatically
  • Users cannot see restricted data
  • Visual totals reflect filtered data

Power BI Apps

  • RLS is enforced
  • No additional configuration required

Analyze in Excel / External Tools

  • RLS is enforced if the user has Build permission
  • Users cannot bypass RLS through external connections

Important RLS Limitations (Exam Awareness)

  • RLS does not hide tables or columns (use Object-Level Security for that)
  • RLS cannot be applied directly to measures
  • Workspace Admins are not exempt from RLS unless explicitly configured
  • RLS does not apply in Power BI Desktop for the model author unless using “View as”

Object-Level Security (OLS) vs RLS

FeatureRLSOLS
Controls rows
Controls columns/tables
Configured in Desktop❌ (External tools)
Exam depthHighAwareness only

PL-300 Focus: RLS concepts are tested far more deeply than OLS.


Governance and Best Practices

  • Use dynamic RLS wherever possible
  • Centralize security logic in the semantic model
  • Use groups, not individuals
  • Document role logic for maintainability
  • Test RLS thoroughly before sharing reports

Common Exam Scenarios

You may be asked to determine:

  • Why different users see different values in the same report
  • How to reduce the number of RLS roles
  • How to implement user-based filtering
  • Where RLS logic is created vs enforced

Key Takeaways for the PL-300 Exam

  • RLS restricts row-level data visibility
  • Roles and filters are created in Power BI Desktop
  • Users and groups are assigned in the Power BI Service
  • Dynamic RLS uses USERPRINCIPALNAME()
  • RLS applies to all reports and apps using the semantic model
  • RLS is enforced at the semantic model level

Practice Questions

Go to the Practice Questions for this topic.