【问题标题】:Grant O365 Mailbox Permission to a Managed Identity向托管标识授予 O365 邮箱权限
【发布时间】:2019-10-03 01:16:03
【问题描述】:

尝试让逻辑应用通过 Graph API 获取电子邮件详细信息,因为 O365 Outlook 连接器不提供我需要的输出,但 Graph API 提供(Internet 邮件标头)。

Outlook 连接器为身份验证创建了一个 API 连接,效果很好。

要调用 Graph API,我使用的是 HTTP 操作,它支持托管身份,所以我想知道:

  1. 我可以授予托管身份读取特定邮箱的权限吗?
  2. HTTP 操作能否使用 API 连接(类似于 Outlook 连接器的功能)?

【问题讨论】:

    标签: azure azure-active-directory microsoft-graph-api azure-logic-apps


    【解决方案1】:

    1.我可以授予托管身份读取某个邮箱的权限吗?

    托管标识是一个服务主体,我们可以在 Azure 门户 -> Azure Active Directory -> Enterprise applications 中检查它及其权限。但是我们无法在其中添加新权限,因此我们需要在App registrationsadd credentials to your app 中添加create a new AD App ,然后授予Microsoft Graph API的Mail.Read应用权限,参考这个link。权限是调用这个apiList messages(我想你想用这个api,如果没有,就按照文档找到应用程序权限,添加。)最后别忘了点击Grant admin consent按钮。

    在逻辑应用中,Authentication使用Active Directory OAuthAudience使用https://graph.microsoft.com/,具体使用URLClient idsecret等,需要调用MS graph api . xxx@microsoft.com 是用户主体名称,也是邮箱地址。我不确定我是否正确理解了您问题中的 read a certain mailbox,如果您的意思是只想授予一个邮箱的权限,我会说 Microsft 图中没有这样的权限。

    2.HTTP 操作能否使用 API 连接(类似于 Outlook 连接器所做的)?

    没有用于 http 操作的预构建连接器,您可以尝试 Custom connectors in Logic Apps

    【讨论】:

    • 谢谢乔伊,这很有帮助。关于“如果您的意思是只想授予一个邮箱的权限,我会说在Microsft图中没有这样的权限。”这就是我想要做的,我想只授予一个邮箱(我控制的邮箱)的权限,因为这是最低权限,但也因为我无法获得阅读所有邮箱的电子邮件的权限;-)
    【解决方案2】:

    有一种方法可以将该应用程序角色权限添加到托管身份。使用 Azure 门户无法做到这一点。您可以在 Azure 门户中验证以下步骤是否有效。此方法无需您自己创建委托人,并且无需保存客户 ID/秘密簿记。

    当您使用 Powershell 时,可以将 Mail.Read 应用程序角色权限添加到托管身份,无论是系统托管身份还是用户托管身份。还有其他方法可以执行相同的步骤,例如Azure CLI。但以下是我所知道的有效并使用过的。

    这些步骤可用于具有可分配应用角色的任何身份和应用程序。因此,您还可以添加 Sharepoint 权限以列出站点,打开 Excel 工作表。但请记住,Microsoft 应用程序角色大多是全有或全无。它违反了最低权限原则。
    我很想知道一种避免违反原则的通用方法。

    要将应用角色权限分配给托管身份,我们需要了解以下几点:

    ...的ID

    1. ...托管身份(例如“logic-app-identity”)
    2. ...具有应用程序角色的应用程序(例如“Microsoft Graph”)
    3. ...分配给托管标识的应用程序角色的 ID(例如“Mail.Read”)

    然后我们可以将应用角色分配给托管标识。

    为可读性设置一些变量

    $managed_identity_name = "logic-app-identity"
    $application_with_the_required_role_name = "Microsoft Graph"
    $application_role_to_assign_name = "Mail.Read"
    

    使用 AzureAD 模块并登录。

    使用来自 here 的 AzureAd 模块

    Import-Module AzureAd
    Connect-AzureAd #shows popup to login
    

    1。获取托管标识 id

    # filter first server side, and in case of multiple results, the where ensures a single result
    # -All is necessary because a managed identity is a sort of service principal
    $managed_identity_id = (Get-AzureADServicePrincipal -All $true -SearchString $managed_identity_name | where DisplayName -eq $managed_identity_name).ObjectId
    

    2。获取具有请求的应用程序角色的应用程序

    # -SearchString on "Microsoft Graph" returns two results, therefore the where clause to ensure a single result
    # storing the returned object, because it contains the approles array
    $application_with_the_required_role = (Get-AzureADServicePrincipal -SearchString "Microsoft Graph" | where DisplayName -eq "Microsoft Graph")
    
    # fun fact: the ObjectId of the "Microsoft Graph" application is always: 94d0e336-e38a-4bfc-9b21-8fbb74b6b835
    $application_with_the_required_role_id = $application_with_the_required_role.ObjectId
    

    3。获取要分配给托管标识的应用程序角色 ID

    # the required id is now simply called Id
    # fun fact: the ObjectId of the "Mail.Read" app role is always: 810c84a8-4a9e-49e6-bf7d-12d183f40d01
    $application_role_to_assign_id = ($application_with_the_required_role.AppRoles | where Value -eq $application_role_to_assign_name).Id
    

    将应用角色分配给托管标识

    New-AzureADServiceAppRoleAssignment -ObjectId $managed_identity_id -PrincipalId $managed_identity_id -ResourceId $application_with_the_required_role_id -Id $application_role_to_assign_id
    

    奖励:验证作业

    # should list the assigned application to the identity, dig further for the specific app role
    # (I don't know how :S)
    Get-AzureADServiceAppRoleAssignedTo -ObjectId $managed_identity_id | fl
    
    # and the other way around to list the identities assigned to the application
    Get-AzureADServiceAppRoleAssignment -ObjectId $application_with_the_required_role_id | fl
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-04
      • 1970-01-01
      • 2015-06-19
      • 2022-08-04
      • 2021-03-26
      相关资源
      最近更新 更多