【发布时间】:2020-07-10 04:27:28
【问题描述】:
如何允许用户分配的托管身份 (UAMI) 对 Azure AD 组进行读写? 我有一个作为 UMAI 运行的 .Net Core 3.1 Azure Function 应用程序。该应用程序需要能够 R/W Azure AD 组。我的代码通过笔记本电脑上的应用注册服务主体运行。在 Azure 中,UAMI 是订阅参与者,并且与 FunctionApp 相关联。
这适用于本地和 Azure:
var azureFluentClient = AzureAuthenticator.AzureFluentClient(context._ILogger, context.ExecutionContext,context.Settings);
var resourceGroups = await azureFluentClient.ResourceGroups.ListAsync();
在本地工作,在 Azure 上失败:
var azureFluentClient = AzureAuthenticator.AzureFluentClient(context._ILogger, context.ExecutionContext, context.Settings);
var groups = await azureFluentClient.AccessManagement.ActiveDirectoryGroups.GetByNameAsync("AAA1");
错误:
{"odata.error":{"code":"Authorization_RequestDenied","message":{"lang":"en","value":"Insufficient privileges to complete the operation."},"requestId":"f797cb42-a75d-48d9-a902-c580955800cd","date":"2020-07-10T05:41:59"}}
ex.Response.Content: "Insufficient privileges to complete the operation."
Microsoft.Azure.Management.Graph.RBAC.Fluent.Models.GraphErrorException: Operation returned an invalid status code 'BadRequest'
at Microsoft.Azure.Management.Graph.RBAC.Fluent.GroupsOperations.ListWithHttpMessagesAsync(ODataQuery`1 odataQuery, Dictionary`2 customHeaders, CancellationToken cancellationToken)
at Microsoft.Azure.Management.Graph.RBAC.Fluent.GroupsOperationsExtensions.ListAsync(IGroupsOperations operations, ODataQuery`1 odataQuery, CancellationToken cancellationToken)
at Microsoft.Azure.Management.Graph.RBAC.Fluent.ActiveDirectoryGroupsImpl.<ListAsync>b__7_0(CancellationToken cancellation)
at Microsoft.Azure.Management.ResourceManager.Fluent.Core.PagedCollection`2.LoadPageWithWrapModelAsync(Func`2 listInnerAsync, Func`3 listInnerNext, Func`3 wrapModelAsync, Boolean loadAllPages, CancellationToken cancellationToken)
at Microsoft.Azure.Management.ResourceManager.Fluent.Core.PagedCollection`2.LoadPage(Func`2 listInnerAsync, Func`3 listInnerNext, Func`2 wrapModel, Boolean loadAllPages, CancellationToken cancellationToken)
at Microsoft.Azure.Management.Graph.RBAC.Fluent.ActiveDirectoryGroupsImpl.ListAsync(Boolean loadAllPages, CancellationToken cancellationToken)
at HDIManagement.FunctionApp.API.TestServiceConfiguration.TestADGroupAccess(OperationsContext context) in C:\Users\josep\source\repos\HDI\BareMetal\HDI-Logging\HDIManagement.FunctionApp\API\TestConfiguration.cs:line 67
不同之处在于有一个用于本地运行的应用注册,它具有 API 权限:Azure Active Directory Graph/Directory.ReadWrite.All。我认为问题在于没有与 UAMI 关联的应用注册,因此无法授予权限。
【问题讨论】:
标签: c# azure azure-active-directory azure-functions azure-web-app-service