Azure SQL Database Row Level Security

Published
Length
3 min read

Luis Felipe Dias

All posts

You use azure sql database row level security to filter table rows based on who runs a query. The database engine checks user identity and hides rows that do not match your policy. Teams use this feature to share one table across many tenants or groups. Each person or app queries the same table but gets only allowed rows. This keeps filter logic inside the database instead of inside every app. How azure sql database row level security works in practice A database user is the identity of a lo

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.

You use azure sql database row level security to filter table rows based on who runs a query. The database engine checks user identity and hides rows that do not match your policy.

Teams use this feature to share one table across many tenants or groups. Each person or app queries the same table but gets only allowed rows. This keeps filter logic inside the database instead of inside every app.

How azure sql database row level security works in practice

A database user is the identity of a login when it connects to a database. Microsoft SQL platforms support thirteen types of database users. When someone needs many databases on an instance, a login in master is common. For one or a few databases, a contained database user with a password works well. An admin must first enable contained databases on the server and database.

Row rules rely on this database user identity or on session context values. A predicate function checks if a row matches the active user or tenant value. A security policy then binds that function to the target table. Filter predicates hide non-matching rows during read queries without raising an error. Block predicates stop users from inserting, updating, or deleting rows outside their scope.

Engineers and AI agents run standard queries without adding custom filter clauses. The engine applies the policy on every query plan by default. This setup helps when several apps or scripts read from the same schema.

Security and operational tradeoffs of native roles and row rules

Native roles give broad permissions across a database. Members of the fixed datareader role can read all data from all user tables and views. The fixed datawriter role can add, delete, or change data in all user tables. The deny datareader role blocks reading any data or metadata from user tables and views. The deny datawriter role blocks adding, changing, or deleting data. You cannot change the permissions assigned to fixed database roles.

Row-Level Security + Database Replication Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

The owner role can run all setup and maintenance tasks and can drop the database. Because fixed roles are broad, teams pair them with row policies to limit scope. Still, managing database users and policies across dozens of databases takes steady effort. If an app uses one shared login, the database sees only one identity. The app must set session context values right every time, or filters fail.

Row policies also do not mask sensitive columns inside an allowed row. If an engineer can read a row, they get the full email or phone number. Data masking rewrites matched fields like card numbers or national IDs in query results. Also, static passwords for contained users can leak if stored on laptops. Teams often add an external control layer to check queries and mask sensitive fields.

Check SQL Server batches and results on the wire

SQL Server logins and roles decide who connects. They do not check what each TDS batch does or mask sensitive values in returned rows. With hoop.dev, you run an open-source proxy, a sidecar for your SQL Server, inline in the TDS wire protocol. On every batch an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.

Before a batch hits the server, hoop.dev guardrails refuse disallowed actions with a native TDS error or hold risky statements for approval. On the way back, hoop.dev data masking rewrites sensitive values in supported result columns in memory, and every decision is logged. Explore the MIT-licensed project on GitHub.

Frequently asked questions

How do fixed database roles interact with row policies?

Fixed roles grant table access, while row policies filter which specific rows return. A datareader member can query all tables, but the policy hides unauthorized rows.

Why do shared app logins complicate row filtering?

A shared login maps to one database user for all app customers. You must pass tenant identity in session context so the filter knows who is asking.

Does row filtering protect sensitive columns inside returned rows?

No, row rules only control which rows appear in the query result. To hide emails, phone numbers, or card numbers in allowed rows, use field masking.

The query runs. The emails stay hidden.