向托管标识授予 O365 邮箱权限
Grant O365 Mailbox Permission to a Managed Identity
尝试让逻辑应用程序通过 Graph API 获取电子邮件详细信息,因为 O365 Outlook Connector 不提供我需要的输出,但 Graph API 提供(Internet 消息 headers).
Outlook 连接器创建了一个 API 连接用于身份验证,效果很好。
要调用 Graph API 我正在使用 HTTP 操作并且它支持托管身份,所以我想知道:
- 我能否授予托管标识可以读取特定邮箱的权限?
- HTTP 操作能否使用 API 连接(类似于 Outlook 连接器所做的)?
1.Can I grant permission such that the Managed Identity can read a certain mailbox?
托管身份是一个服务主体,我们可以在 Azure 门户 -> Azure Active Directory
-> Enterprise applications
中检查它及其权限。但是我们无法在其中添加新的权限,所以我们需要 create a new AD App in the App registrations
, add credentials to your app
,然后授予Microsoft Graph API的Mail.Read
应用权限,参考这个link. The permission is to call this api List messages(我想你想用这个api,如果没有,就按照文档来找到应用权限,添加它。)最后,不要忘记点击Grant admin consent
按钮。
在逻辑应用中,Active Directory OAuth
用于 Authentication
,https://graph.microsoft.com/
用于 Audience
,并指定 URL
、Client id
、 secret
,等等,什么需要调用MS图api。 xxx@microsoft.com
是用户主体名,也是邮箱地址。我不确定我是否足够正确地理解你问题中的 read a certain mailbox
,如果你的意思是你只想授予一个邮箱的权限,我会说没有这样的Microsft 图表中的权限。
2.Can the HTTP action use an API Connection (similar to what the Outlook connector does)?
http 操作没有 pre-bulit 连接器,您可以尝试 Custom connectors in Logic Apps。
有一种方法可以将该应用程序角色权限添加到托管身份。使用 Azure 门户无法做到这一点。您可以在 Azure 门户中验证以下步骤是否有效。这种方法节省了您自己创建委托人的时间,并且消除了客户 id/secret 簿记的需要。
使用 Powershell 时,可以将 Mail.Read 应用程序角色权限添加到托管标识,无论是系统托管标识还是用户托管标识。还有其他方法可以执行相同的步骤,例如天蓝色命令行界面。但以下是我所知道的有效和使用过的。
这些步骤适用于具有可分配应用程序角色的任何身份和应用程序。所以你也可以添加Sharepoint权限来列出站点,打开一个Excelsheet。但请记住,Microsoft 应用角色大多是全有或全无。它打破了最小特权原则。
我很想知道避免违反原则的通用方法。
要将应用角色权限分配给托管身份,我们需要了解几件事:
ID...
- ...托管标识(例如“logic-app-identity”)
- ...具有应用程序角色的应用程序(例如“Microsoft Graph”)
- ...分配给托管身份的应用程序角色的 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
尝试让逻辑应用程序通过 Graph API 获取电子邮件详细信息,因为 O365 Outlook Connector 不提供我需要的输出,但 Graph API 提供(Internet 消息 headers).
Outlook 连接器创建了一个 API 连接用于身份验证,效果很好。
要调用 Graph API 我正在使用 HTTP 操作并且它支持托管身份,所以我想知道:
- 我能否授予托管标识可以读取特定邮箱的权限?
- HTTP 操作能否使用 API 连接(类似于 Outlook 连接器所做的)?
1.Can I grant permission such that the Managed Identity can read a certain mailbox?
托管身份是一个服务主体,我们可以在 Azure 门户 -> Azure Active Directory
-> Enterprise applications
中检查它及其权限。但是我们无法在其中添加新的权限,所以我们需要 create a new AD App in the App registrations
, add credentials to your app
,然后授予Microsoft Graph API的Mail.Read
应用权限,参考这个link. The permission is to call this api List messages(我想你想用这个api,如果没有,就按照文档来找到应用权限,添加它。)最后,不要忘记点击Grant admin consent
按钮。
在逻辑应用中,Active Directory OAuth
用于 Authentication
,https://graph.microsoft.com/
用于 Audience
,并指定 URL
、Client id
、 secret
,等等,什么需要调用MS图api。 xxx@microsoft.com
是用户主体名,也是邮箱地址。我不确定我是否足够正确地理解你问题中的 read a certain mailbox
,如果你的意思是你只想授予一个邮箱的权限,我会说没有这样的Microsft 图表中的权限。
2.Can the HTTP action use an API Connection (similar to what the Outlook connector does)?
http 操作没有 pre-bulit 连接器,您可以尝试 Custom connectors in Logic Apps。
有一种方法可以将该应用程序角色权限添加到托管身份。使用 Azure 门户无法做到这一点。您可以在 Azure 门户中验证以下步骤是否有效。这种方法节省了您自己创建委托人的时间,并且消除了客户 id/secret 簿记的需要。
使用 Powershell 时,可以将 Mail.Read 应用程序角色权限添加到托管标识,无论是系统托管标识还是用户托管标识。还有其他方法可以执行相同的步骤,例如天蓝色命令行界面。但以下是我所知道的有效和使用过的。
这些步骤适用于具有可分配应用程序角色的任何身份和应用程序。所以你也可以添加Sharepoint权限来列出站点,打开一个Excelsheet。但请记住,Microsoft 应用角色大多是全有或全无。它打破了最小特权原则。
我很想知道避免违反原则的通用方法。
要将应用角色权限分配给托管身份,我们需要了解几件事:
ID...
- ...托管标识(例如“logic-app-identity”)
- ...具有应用程序角色的应用程序(例如“Microsoft Graph”)
- ...分配给托管身份的应用程序角色的 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