授予服务主体访问其他租户中的应用程序的权限

时间:2018-10-04 12:07:02

标签: azure-active-directory

我在一个租户(OneTenant)中拥有一个Azure AD服务主体,我想授予对另一个租户(OtherTenant)中的应用程序的访问权限。

租户OneTenant中的服务主体是Azure Logic应用程序的托管服务身份。因此,我真正想要的是从我的逻辑应用程序调用API。此API受OtherTenant中的Azure AD应用程序的保护。

OtherTenant中的应用程序定义了许多角色,OneTenant中的服务主体应具有以下角色之一,以便可以调用API。

我尝试了以下操作:

  • OtherTenant中的应用设置为多租户
  • 运行以下PS命令以尝试将SP添加到应用程序中的角色:

    New-AzureADServiceAppRoleAssignment `
      -ObjectId <object-id-of-sp-in-one-tenant> `
      -Id <role-id> `
      -PrincipalId <object-id-of-sp-in-one-tenant> `
      -ResourceId <app-id-in-other-tenant>
    

    (均已登录OneTenantOtherTenant

    这会产生一个错误,指出找不到app-id-in-other-tenantobject-id-of-sp-in-one-tenant,这取决于我登录的位置。

我还尝试根据OneTenant中的应用程序ID在OtherTenant中创建服务主体,在这种情况下,我会收到一条错误消息:Authenticating principal does not have permission to instantiate multi-tenantapplications and there is not matching Applicationin the request tenant.

3 个答案:

答案 0 :(得分:3)

按照您的问题直接执行命令:

New-AzureADServiceAppRoleAssignment `
  -ObjectId <object-id-of-sp-in-one-tenant> `
  -Id <role-id> `
  -PrincipalId <object-id-of-sp-in-one-tenant> `
  -ResourceId <app-id-in-other-tenant>

尝试更改最后一个参数值,即ResourceId

当前您正在通过<app-id-in-other-tenant>

<object-id-of-API-in-other-tenant>

替换

答案 1 :(得分:2)

好吧,我终于开始测试Rohit Saigal提出的solution是否有效。它确实指向正确的方向,但并不完整。

第一步是all_languages = I18n.config.available_locales.dup # copy the array all_languages.delete(:en) # or, for your case all_languages.delete(current_user.language.to_sym) # non-mutating way all_langs_without_en = I18n.config.available_locales.reject { |loc| loc == :en } 中创建一个服务主体,该服务主体表示OneTenant中的应用程序。因此,在登录OtherTenant时,运行以下脚本:

OneTenant

下一步是使用以下参数运行$spInOneTenant = New-AzureADServicePrincipal -AppId <app-id-in-other-tenant> cmdlet:

New-AzureADServiceAppRoleAssignment

技巧是将在上一步中创建的服务主体的对象ID用作New-AzureADServiceAppRoleAssignment ` -Id <role-id> ` -ObjectId <object-id-of-sp-in-one-tenant> ` -PrincipalId <object-id-of-sp-in-one-tenant> ` -ResourceId $spInOneTenant.ObjectId

答案 2 :(得分:0)

此处提出的问题/答案很有帮助,但是我花了一些时间来仔细研究细节并使其真正起作用,因此,请允许我详细说明上述内容,因为它可能也会对其他人有所帮助。

场景

两个租户:

  • Home Tenant
  • Other Tenant

一项Azure应用服务API app,其访问权限由Home Tenant管理。

放置在Logic app中的订阅中的一个Other Tenant需要安全访问API app中的Home Tenant

方法

申请注册

为使API app将身份和访问管理委派给Azure AD,在application的Azure Active Directory中注册了home tenantapplication已注册为多租户应用。

您还需要创建一个应用角色(请参见文档:How to: Add app roles in your application and receive them in the token),将其命名为read.weather

Other TenantLogic App的配置

要向Logic App提供API app访问权限,请执行以下操作:

  1. logic app启用系统分配的身份-即使用Managed Identity。记下系统分配的受管理身份Object ID{18a…}),您将在一分钟内需要它。

  2. 使用此命令在application中为Other Tenant创建服务主体,其中appId是在{{1}中注册的application的appId }(例如,在这里说Home Tenant):

{1a3}

此命令将输出一个json文档,其中包括New-AzureADServicePrincipal -AppId {appId}用于刚刚创建的服务主体。

objectId

您还应该看到来自[... more json ...] "objectId": "b08{…}", [... more json...] 命令的json输出中的appRoles,包括您刚创建的应用角色read.weather

 New-AzureADServicePrincipal
  1. 使用以下命令将所有角色绑定在一起:

[... more json...] "appRoles": [ { "allowedMemberTypes": [ "Application" ], "description": "Read the weather.", "displayName": "Read Weather", "id": "46f{…}", "isEnabled": true, "value": "read.weather" } ], [... more json...]

例如像这样的东西:

New-AzureADServiceAppRoleAssignment -Id {app role ide} -ObjectId {system assigned identity object id} -PrincipalId {system assigned identity object id} -ResourceId {object id of service principal}

  1. 现在,我们准备在New-AzureADServiceAppRoleAssignment -Id 46f… -ObjectId 18a… -PrincipalId 18a… -ResourceId b08…中使用URI到Logic App的URI(使用托管身份进行身份验证)来建立HTTP请求。

请注意,受众是必需的,其格式为:API app

Logic App configuration

但是等等……!

这是否意味着只要有人知道您的api://{appId}注册的appId,任何人都可以这样做,这是否会损害application的安全性?

是的,确实如此,是的,的确可以损害API app的安全性。

如果您查看从API app创建并用作载体的访问令牌,它是有效的访问令牌,其中包含所有必要的声明,包括应用程序角色。但是,访问令牌是由Logic App而不是Other Tenant颁发的。

因此,如果您有一个多租户应用程序,并且想要防止这种情况发生,那么您可以检查调用API的传入访问令牌的发布者(更有可能是Home Tenant),并且仅在发行者是tid,或者您可以将Home Tenant做成一个租户应用。

或者,您可以要求发行者匹配API信任的租户列表。

相关问题