Azure Function Authentication:Azure Active Directory:使用安全组来包含身份(用户和服务主体)以访问 Function
Azure Function Authentication: Azure Active Directory: Use Security Group to include identities (users and service principals) to access Function
我有一个启用了 Azure Active Directory 身份验证的 Azure Function(包括“请求未通过身份验证时采取的操作”=“使用 Azure Active Directory 登录”)。另外选项“需要用户分配?”与 Azure 函数相关的服务主体 (sp_func) 设置为“是”,以避免租户中的每个人最终都能够 运行 该函数。
目标是将单个安全组(可以包括用户和服务主体)添加到 sp_func 的“用户和组”,以便分配给组的决定是否函数是否可以访问。对于用户,这可以正常工作,但不适用于服务主体 (sp_nonfunc)。为了让他们 (sp_nonfunc) 工作,我必须为他们 (sp_nonfunc) 设置权限,到底什么允许他们与 Azure Function 交互,无论他们 (sp_nonfunc) 是是否分配到组。
我是否可以只将服务主体 (sp_nonfunc) 添加到一个组,并将该组添加到 sp_func,然后使用 [=33] 执行函数=](未明确授予 sp_nonfunc 权限)?
编辑:即使我在清单中定义了自己的 appRole,也似乎无法直接将 sp_nonfunc 添加到 sp_func。目前唯一的方法似乎是为 sp_func 添加 sp_nonfunc 的权限 - 但这是我想要避免的。
EDIT2:这里我是如何在 sp_func 清单
中定义角色的
"appRoles": [
{
"allowedMemberTypes": [
"Application"
],
"displayName": "AzureFunctionAccess",
"id": "xxx-xxx-xxx-xxx-xxx",
"isEnabled": true,
"description": "Access Azure Function.",
"value": "AzureFunctionAccess"
}
]
EDIT3:当我不直接将角色分配给 sp_nonfunc 而只是将 sp_nonfunc 添加到我获得的安全组时,使用资源请求 https://login.microsoftonline.com/<tenant id>/oauth2/token
= sp_func:
的已注册应用程序的应用程序 ID URI
{
"error": "invalid_grant",
"error_description": "AADSTS501051: Application 'xxx-xxx-xx-xx-xx'(xxx) is not assigned to a role for the application 'https://xxx'(xxx).\r\nTrace ID: xxx-xxx-xx-xx-xx\r\nCorrelation ID: xxx-xxx-xx-xx-xx\r\nTimestamp: xx-xx-xx xx:xx:xxZ",
"error_codes": [
501051
],
"timestamp": "xx-xx-xx xx:xx:xxZ",
"trace_id": "5xxx-xxx-xx-xx-xx",
"correlation_id": "xxx-xxx-xx-xx-xx",
"error_uri": "https://login.microsoftonline.com/error?code=501051"
}
这种方式行不通,要使用服务主体(在您的情况下为 sp_nonfunc
)获取函数应用程序(sp_func
)的令牌,您需要提供 API sp_nonfunc
.
权限
导航到门户中与sp_nonfunc相关的应用程序注册->API permissions
->添加您定义的AzureFunctionAccess
,最后单击Grant admin consent for xxx
按钮.
然后用客户端凭证流获取token,就可以了。 (我用的是v2.0端点,如果你用v1.0也可以。)
更详细的步骤,我之前在写过,大家可以参考。
我有一个启用了 Azure Active Directory 身份验证的 Azure Function(包括“请求未通过身份验证时采取的操作”=“使用 Azure Active Directory 登录”)。另外选项“需要用户分配?”与 Azure 函数相关的服务主体 (sp_func) 设置为“是”,以避免租户中的每个人最终都能够 运行 该函数。
目标是将单个安全组(可以包括用户和服务主体)添加到 sp_func 的“用户和组”,以便分配给组的决定是否函数是否可以访问。对于用户,这可以正常工作,但不适用于服务主体 (sp_nonfunc)。为了让他们 (sp_nonfunc) 工作,我必须为他们 (sp_nonfunc) 设置权限,到底什么允许他们与 Azure Function 交互,无论他们 (sp_nonfunc) 是是否分配到组。
我是否可以只将服务主体 (sp_nonfunc) 添加到一个组,并将该组添加到 sp_func,然后使用 [=33] 执行函数=](未明确授予 sp_nonfunc 权限)?
编辑:即使我在清单中定义了自己的 appRole,也似乎无法直接将 sp_nonfunc 添加到 sp_func。目前唯一的方法似乎是为 sp_func 添加 sp_nonfunc 的权限 - 但这是我想要避免的。
EDIT2:这里我是如何在 sp_func 清单
中定义角色的"appRoles": [
{
"allowedMemberTypes": [
"Application"
],
"displayName": "AzureFunctionAccess",
"id": "xxx-xxx-xxx-xxx-xxx",
"isEnabled": true,
"description": "Access Azure Function.",
"value": "AzureFunctionAccess"
}
]
EDIT3:当我不直接将角色分配给 sp_nonfunc 而只是将 sp_nonfunc 添加到我获得的安全组时,使用资源请求 https://login.microsoftonline.com/<tenant id>/oauth2/token
= sp_func:
{
"error": "invalid_grant",
"error_description": "AADSTS501051: Application 'xxx-xxx-xx-xx-xx'(xxx) is not assigned to a role for the application 'https://xxx'(xxx).\r\nTrace ID: xxx-xxx-xx-xx-xx\r\nCorrelation ID: xxx-xxx-xx-xx-xx\r\nTimestamp: xx-xx-xx xx:xx:xxZ",
"error_codes": [
501051
],
"timestamp": "xx-xx-xx xx:xx:xxZ",
"trace_id": "5xxx-xxx-xx-xx-xx",
"correlation_id": "xxx-xxx-xx-xx-xx",
"error_uri": "https://login.microsoftonline.com/error?code=501051"
}
这种方式行不通,要使用服务主体(在您的情况下为 sp_nonfunc
)获取函数应用程序(sp_func
)的令牌,您需要提供 API sp_nonfunc
.
导航到门户中与sp_nonfunc相关的应用程序注册->API permissions
->添加您定义的AzureFunctionAccess
,最后单击Grant admin consent for xxx
按钮.
然后用客户端凭证流获取token,就可以了。 (我用的是v2.0端点,如果你用v1.0也可以。)
更详细的步骤,我之前在