azure - Azure 中需要哪些权限才能授予对托管标识的访问权限以调用自定义 api

标签 azure azure-active-directory azure-managed-identity

我想将在我的应用程序注册中创建的角色 Things.Reead.All 分配给托管身份。 应用程序注册 SP 对象 ID 为 8055e1eb-0000-0000-9b77-00000000000 角色定义如下所示

"appRoles": [
        {
            "allowedMemberTypes": [
                "Application"
            ],
            "description": "Allow the application to read all things as itself.",
            "displayName": "Read all things",
            "id": "86a914fa-a862-4962-9975-000000000000",
            "isEnabled": true,
            "lang": null,
            "origin": "Application",
            "value": "Things.Read.All"
        }

关于系统分配的托管标识的唯一已知信息是其对象 ID,例如

aad300-0872-0000-811d-00000000000

并且我想允许它调用希望看到访问 token 中的角色的应用程序 8055e1eb-0000-0000-9b77-00000000000。 我知道我必须使用以下 api 来执行此操作。

https://graph.microsoft.com/v1.0/servicePrincipals/8055e1eb-0000-0000-9b77-00000000000/appRoleAssignedTo
{
  "principalId": "aad300-0872-0000-811d-00000000000",
  "resourceId": "8055e1eb-0000-0000-9b77-00000000000",
  "appRoleId": "86a914fa-a862-4962-9975-000000000000"
}

我对我的租户拥有广泛但受控的访问权限。当我从

获取 token 时
az account get-access-token --resource https://graph.microsoft.com

并调用上面的内容,我得到了

    "code": "Authorization_RequestDenied",
    "message": "Insufficient privileges to complete the operation.",

我需要弄清楚进行此调用所需的确切权限。

最佳答案

由于您没有回答我的评论,我只能给您我自己的解决方案,该解决方案使用服务主体登录 azure cli,它对我有用。

请按照以下步骤操作。

1. Create a new App Registration in azure ad ,然后 get values for signing increate a new application secret .

2.导航到应用程序的API权限,添加应用程序权限(不是委托(delegate)权限)Directory.ReadWrite.All Microsoft Graph,最后不要忘记单击为 xxx 授予管理员同意按钮。

注意:来自 docAppRoleAssignment.ReadWrite.All权限就足够了,但是根据我的测试,它不起作用,不确定这是否是一个错误,我已经解码了 token , token 具有AppRoleAssignment .ReadWrite.All 权限。

enter image description here

enter image description here

3.在azure cli中,运行以下命令来获取 token 。

az account clear
az login --service-principal --allow-no-subscriptions --username '<application-id>' --password '<application secret>' --tenant '<tenant-id>'
az account get-access-token --resource https://graph.microsoft.com

4.我测试了调用api的 token - Grant an appRoleAssignment for a service principal为我的功能应用程序的系统分配标识授予应用程序角色,效果很好。

enter image description here

在门户中检查:

enter image description here

关于azure - Azure 中需要哪些权限才能授予对托管标识的访问权限以调用自定义 api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63257647/

相关文章:

azure - 以正确的方式应用服务托管身份和 key 保管库

ASP.Net WebApi Key Vault configBuilders 无法处理

azure - 使用 ACR 和托管标识配置 Azure WebApp

azure - 将 Azure 云服务更新到操作系统系列 6

authentication - 连接到 HDInsight Web 门户时 Azure HDInsight 身份验证失败

Powershell - 使用 Powershell 对 Azure AD 应用程序执行 "Grant Permissions"操作

asp.net - Azure AD 中的 jwt-bearer 代表授权问题

python - Flask API 突然收不到请求

azure - 使用 "Web API on-behalf-of flow"创建 Microsoft Graph Webhook 时访问 token 验证失败

Azure API 管理客户端身份验证