SQL Server Row Level Security Ad Groups

Published
Length
3 min read

Luis Felipe Dias

All posts

You can use sql server row level security ad groups to filter table rows by team. The database checks group rules on each query and returns matching rows. This setup keeps row rules inside the database engine. Engineers and apps do not need extra query filters in their code. How sql server row level security ad groups work in practice In SQL Server, a database user is the identity of a login when it connects. There are 13 types of database users in the system. When someone needs many databas

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 can use sql server row level security ad groups to filter table rows by team. The database checks group rules on each query and returns matching rows.

This setup keeps row rules inside the database engine. Engineers and apps do not need extra query filters in their code.

How sql server row level security ad groups work in practice

In SQL Server, a database user is the identity of a login when it connects. There are 13 types of database users in the system. When someone needs many databases on one instance, a login in master is common. For one or a few databases, a contained database user is an option. An admin must first turn on contained databases on the server and database.

Admins map directory groups to database users and roles. Then they write filter rules that check the active role or group. When an engineer or AI agent runs a query, the engine checks these rules. It hides rows that do not match the group of the caller.

This approach works for both human engineers and automated tools. An AI agent using a group identity gets the same row limits as a person. The database blocks unauthorized rows before any results leave the server. Teams do not have to maintain separate views for each department.

Security tradeoffs of fixed roles and static access

Many teams start with built-in fixed database roles for broad access. Members of the datareader role can read all data from all user tables and views. Members of the datawriter role can add, delete, or change data in user tables. The denydatareader role blocks reading any data or metadata from user tables and views. The denydatawriter role blocks adding, changing, or deleting data in the database. The owner role can do all maintenance tasks and can even drop the database.

You cannot change the permissions assigned to these fixed database roles. Every role, including the public role, has basic connect rights by default. Because fixed roles are broad, they do not stop sensitive data leaks on their own. Even with row filters, allowed rows often hold private fields.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

If a row passes the group check, the user sees the whole row. That row might hold emails, phone numbers, card numbers, or national IDs. Static roles also leave accounts open all day and night. If an attacker steals a login key, they inherit everything that group can read. Row rules also add work for the database CPU on every single query. Complex group checks can slow down big reports and analytical jobs.

Why session controls matter alongside row filters

Database group rules only control which rows a user can fetch. They do not inspect the live query text or mask individual columns on the fly. They also do not require a peer to approve a risky update command first.

Modern teams pair database roles with an external layer that sits before the database. This layer checks identity on every query and applies data masking to results. Data masking rewrites matched fields like emails and card numbers in query results. Engineers can still debug issues using real row shapes without exposing private strings. Teams also gain a clear audit log of who ran each query and when.

Govern SQL Server queries and responses in flight

Table grants decide which SQL Server objects a caller may touch. They do not check query intent or rewrite sensitive values in results across every client and agent. By design, hoop.dev sits inline in the TDS wire protocol next to SQL Server as a sidecar for your SQL Server. On every production batch from an engineer or AI agent, hoop.dev decides to pass, mask, block, or hold it for approval.

With hoop.dev guardrails and hoop.dev data masking, banned statements are refused or held for review, matched sensitive fields in supported result columns are masked in memory, and each decision is logged. Check out the code on GitHub.

Frequently asked questions

Can you change the permissions of fixed database roles in SQL Server?

No, you cannot change the permissions assigned to fixed database roles. If a team needs custom rules, admins must create user-defined database roles instead.

When should you use a contained database user instead of a server login?

Use a login in master when people need access to many databases on an instance. Use a contained database user when someone needs access to one or a few databases.

Do row filters hide sensitive columns inside allowed rows?

No, row rules only control which rows appear in the query result. To protect fields like phone numbers or national IDs, you need column rules or masking.

The query runs. The emails stay hidden.