0

我有一个需要读取 AAD 组信息的 azure 函数应用程序。此函数应用启用了系统分配的托管标识,并且 MSI 对 Microsoft Graph 具有 Directory.ReadAll 权限。

我使用此代码获取 AAD 组列表:

    from azure.graphrbac import GraphRbacManagementClient
    from msrestazure.azure_active_directory import MSIAuthentication
    import logging

    MSI_credential = MSIAuthentication(resource="https://graph.windows.net") 
    graphrbac_client = GraphRbacManagementClient(credentials=MSI_credential, tenant_id='*****')
    groups = graphrbac_client.groups.list()
    for g in groups:
        logging.info(g.display_name)

这给了我以下错误:

Retrying (Retry(total=3, connect=4, read=3, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')

我也尝试过使用这个包装类,https://github.com/jongio/azidext/blob/master/python/azure_identity_credential_adapter.py 但它给出了完全相同的错误。我在这里想念什么?这可能与在防火墙中将“https://graph.windows.net”列入白名单有关吗?

4

1 回答 1

0

这是一个防火墙问题。在防火墙中将https://graph.windows.net列入白名单解决了该问题。此外,为了使用 graph.windows.net,与应用关联的 MSI 需要 Azure 活动目录图 Directory.ReadAll 访问权限。

于 2021-12-14T22:14:57.313 回答