Azure SQL Server Row Level Security

Published
Length
3 min read

Luis Felipe Dias

All posts

Using azure sql server row level security lets teams restrict which table rows each user reads or changes. The database checks a user rule on every query and hides rows that do not match. Teams use this feature when many people or apps share one database table. Instead of building custom views for each team, admins apply filter rules at the table level. This keeps query logic simple for developers and AI agents. How azure sql server row level security works in practice Before setting up row

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

Using azure sql server row level security lets teams restrict which table rows each user reads or changes. The database checks a user rule on every query and hides rows that do not match.

Teams use this feature when many people or apps share one database table. Instead of building custom views for each team, admins apply filter rules at the table level. This keeps query logic simple for developers and AI agents.

How azure sql server row level security works in practice

Before setting up row filters, admins must set up database users and logins. A database user is the identity of a login when it connects to a database. In SQL Server, there are 13 types of database users available for teams.

When people need access to many databases on an instance, admins create a SQL user with a login in master. For one or a few databases, a contained database user with a password is an option. This user is not tied to a login in master. An admin must first enable contained databases on the server and the database.

Once a user logs in, row filters check that user identity before returning data. When an engineer or AI agent runs a query, the database engine checks the rule. It only returns rows that match the current user or session context.

This works well when every person or service has a distinct database user. The database engine handles the row checks without changing the app query text. Developers can write normal select statements and still get filtered results.

Security tradeoffs of static roles and shared logins

Row filters depend on knowing who is running the query. Many teams still assign broad fixed database roles to shared accounts. In SQL Server, the permissions assigned to fixed database roles cannot be changed.

For example, members of the db_datareader role can read all data from all user tables and views. Members of db_datawriter can add, delete, or change data in all user tables. Meanwhile, db_denydatareader cannot read any data from user tables, views, or metadata about them. The db_denydatawriter role cannot add, modify, or delete data in tables.

Row-Level Security + Server-Sent Events Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

At the top level, db_owner can run all setup and maintenance tasks and can drop the database. All roles, including the public role, have basic connect rights. If engineers share one login with db_datareader rights, row rules cannot tell them apart.

Even with row filters in place, allowed rows can still hold sensitive data. A support engineer might need to check an order row for a customer. That single row can still expose emails, phone numbers, card numbers, or national IDs.

Row rules only decide if a whole row shows up or stays hidden. They do not mask sensitive columns inside the rows that pass the check. Also, managing hundreds of separate database users for human engineers and AI agents adds heavy work. Admins must rotate keys, track role memberships, and clean up old accounts across every server.

Why query-level controls matter for engineers and AI agents

Modern teams let engineers and automated tools run read queries to fix production issues. Giving each tool a permanent login in master or a contained user creates sprawl. Shared logins break user tracking and weaken row filter rules.

A better path combines database roles with identity checks and field masking at query time. When a user runs a query, the system checks their real identity first. As results return, data masking rewrites matched fields like emails or card numbers in results.

This approach keeps database user lists small while protecting sensitive columns in returned rows. Teams get clear audit logs for every query without building complex filter rules for every table.

Add runtime guardrails beside SQL Server

Role grants and network rules are needed setup for SQL Server. Still, an allowed user or agent tool can send a bad delete or read raw customer fields over a valid session. In practice, hoop.dev sits inline in the TDS protocol beside the database as a sidecar for your SQL Server. For every query an agent or human runs in production, hoop.dev decides whether to pass, mask, block, or escalate it for review.

With hoop.dev SQL Server controls, rules refuse banned statements before they run, hold risky queries for human review, and mask matched sensitive values in supported result columns in memory. Furthermore, hoop.dev holds SOC 2 Type II and generates evidence for HIPAA, PCI DSS, SOX, and GDPR audits. See the source on GitHub.

Frequently asked questions

How do database users differ from server logins in SQL Server?

A database user is the identity of a login when it connects to a database. A standard SQL user ties to a login in master, while a contained user stays inside one database.

Can admins change the permissions of fixed roles like db_datareader?

No, the permissions assigned to fixed database roles cannot be changed in SQL Server. Members of db_datareader can read all user tables and views unless other rules block them.

Does row filtering hide sensitive fields inside an allowed row?

No, row filtering only controls whether a whole row is returned to the user. To hide emails, phone numbers, card numbers, or national IDs inside allowed rows, teams need data masking.

The query runs. The emails stay hidden.