We have a Azure SQL database using Azure AD authentication. This all works fine for both Member and Guest AD users, and with AD Groups.
We need to apply row-level security to some tables, based on:
- whether the user has ownership (or at least CREATE USER permission) over the database, or
- based on the AD group
We have created a table-valued function for use in the appropriate security policy. Problem:
- how can we establish whether the user has ownership over the database within the function (which has to be defined
with schemabinding)? Looking up permissions usingsys.fn_my_permissionsis refused assysfunctions can't be usedwith schemabinding. - how can we query what AD groups the user is a member of?
Or do we need to maintain tables of the relationships within the database (with attendant multiple maintenance - AD + several databases)?