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

This post has been republished via RSS; it originally appeared at: Azure Database Support Blog articles.

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! 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.