具有 Azure Active Directory 身份验证的 Azure SQL - 在安全功能中用于行级安全

发布于 01-14 05:40 字数 391 浏览 4 评论 0原文

我们有一个使用 Azure AD 身份验证的 Azure SQL 数据库。这对于会员和来宾 AD 用户以及 AD 组都适用。

我们需要对某些表应用行级安全性,基于:

  1. 用户是否拥有数据库的所有权(或至少 CREATE USER 权限),或者
  2. 基于 AD 组

我们创建了一个表值函数,用于适当的安全策略。 问题:

  1. 我们如何确定用户是否拥有函数内数据库的所有权(必须使用模式绑定定义)? 使用 sys.fn_my_permissions 查找权限被拒绝,因为 sys 函数无法与架构绑定一起使用。
  2. 我们如何查询用户属于哪些 AD 组?

或者我们是否需要维护数据库内的关系表(伴随多个维护 - AD + 多个数据库)?

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:

  1. whether the user has ownership (or at least CREATE USER permission) over the database, or
  2. based on the AD group

We have created a table-valued function for use in the appropriate security policy.
Problem:

  1. 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 using sys.fn_my_permissions is refused as sys functions can't be used with schemabinding.
  2. 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)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜心小果奶2025-01-21 05:40:52

系统函数 is_member('') 可用于验证当前用户是否是某个 AD 组的成员,只要该 AD 组已作为 AD 组添加到数据库中即可。主要的。
此功能也适用于数据库角色。

因此,像这样的安全功能是有效的:

CREATE FUNCTION [fUserCanAccess](@Group varchar(50))
   RETURNS TABLE
   WITH SCHEMABINDING
AS RETURN (
   SELECT 1 as canAccess WHERE
      is_member('db_owner') = 1
   or
      is_member(@Group) = 1
;

第一个 is_member 测试允许访问所有行的数据库角色。第二个 is_member 测试用户是否位于同一 (AD) 组中。

is_member() 返回:

  • 如果 AD 组是数据库中的用户并且登录用户是 AD 组的成员(在 Active Directory 中),则返回 1
  • 如果 AD 组是 AD 组,则返回 0是数据库中的用户,并且登录的用户不是 AD 组(在 Active Directory 中)的成员
  • 如果 AD 组不存在或者不是数据库中的用户,

则为 NULL 组名称不区分大小写。

The system function is_member('<AD Group>') can be used to verify whether the current user is a member of an AD group as long as that AD Group has been added to the database as a principal.
This function also works for database roles.

So security function like this works:

CREATE FUNCTION [fUserCanAccess](@Group varchar(50))
   RETURNS TABLE
   WITH SCHEMABINDING
AS RETURN (
   SELECT 1 as canAccess WHERE
      is_member('db_owner') = 1
   or
      is_member(@Group) = 1
;

The first is_member tests for a database role that allows access to all rows. The second is_member tests for the user being in the same (AD) Group.

is_member(<AD Group>) returns:

  • 1 if the AD Group is a user in the database and the logged on user is a member of the AD Group (in Active Directory)
  • 0 if the AD Group is a user in the database and the logged on user is not a member of the AD Group (in Active Directory)
  • NULL if the AD Group does not exist or is not a user in the database

The Group name is NOT case sensitive.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文