Blog Post

Azure Database Support Blog
1 MIN READ

Lesson Learned #93: Defining a custom SQL role to someone logging in via Azure AD

Jose_Manuel_Jurado's avatar
Jul 03, 2019

Today, I worked on a service request where our customer asked is it possible to define a custom SQL role to someone logging in via Azure Active Directory who is in the Admins group?

 

In Azure SQL Database we have two administrator users: SQL Logins and Azure Active Directory that could be a AAD User or AAD Group.

 

However, we couldn't see this user in the security list of the database and we cannot add this administrator user as a custom SQL role.

 

In this situation, I noticed that running SELECT USER_NAME(), this command returns dbo and, at least, you could identify this type of group.

 

For giving more context in this situation, the idea is to use Row Level Security to an specific group and specific Admin Users, for example:

 

ALTER FUNCTION [fn_access]()

RETURNS TABLE

WITH SCHEMABINDING

 

AS

RETURN SELECT 1 AS fn_accessResult

WHERE USER_NAME()='dbo'

 

Enjoy! 

Published Jul 03, 2019
Version 1.0
No CommentsBe the first to comment