Grant service principal access to application in other tenant

前端 未结 3 1944
滥情空心
滥情空心 2021-01-14 00:29

I have an Azure AD service principal in one tenant (OneTenant) that I would like to give access to an application in another tenant (OtherTenant).<

相关标签:
3条回答
  • 2021-01-14 00:36

    Ok, I finally got around to testing if the solution presented by Rohit Saigal works. It does point in the right direction but is not complete.

    First step is to create a service principal in OneTenant that represents the application in OtherTenant. So while signed in to OneTenant, run the following script:

    $spInOneTenant = New-AzureADServicePrincipal -AppId <app-id-in-other-tenant>
    

    Next step is to run the New-AzureADServiceAppRoleAssignment cmdlet with the following parameters:

    New-AzureADServiceAppRoleAssignment `
        -Id <role-id> `
        -ObjectId <object-id-of-sp-in-one-tenant> `
        -PrincipalId <object-id-of-sp-in-one-tenant> `
        -ResourceId $spInOneTenant.ObjectId
    

    The trick is to use the object id of the service principal you created in the previous step as the ResourceId.

    0 讨论(0)
  • 2021-01-14 00:44

    Taking the command as is from your question:

    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>
    

    Try changing the last parameter value i.e. ResourceId

    Currently you're passing <app-id-in-other-tenant>

    Replace that with <object-id-of-API-in-other-tenant>

    0 讨论(0)
  • 2021-01-14 00:45

    The question/answers presented here were helpful, but yet it took me some time to work through the details and actually make it work, so allow me to elaborate some more on the above, as it might help others too.

    Scenario

    Two tenants:

    • Home Tenant.
    • Other Tenant.

    One Azure App Service API app, with access managed by the Home Tenant.

    One Logic app placed in a subscription in Other Tenant that need to securely access the API app in the Home Tenant.

    Approach

    Application registration

    For the API app to delegate identity and access management to Azure AD an application is registered in the home tenant’s Azure Active Directory. The application is registered as a multi-tenant app.

    You also need to create an app role (see documentation: How to: Add app roles in your application and receive them in the token), lets call it read.weather.

    Configuration of Other Tenant and Logic App

    To provide the Logic App access to the API app do this:

    1. Enable a system assigned identity for the logic app - i.e. use Managed Identity. Note down the system assigned managed identity Object ID ({18a…}), you will need it in a minute.

    2. Create a service principal for the application in the Other Tenant using this command, where appId is the appId of the application registered in Home Tenant (e.g. lets say it’s {1a3} here):

    New-AzureADServicePrincipal -AppId {appId}

    This command will output a json document which includes among other things an objectId for the service principal just created.

    [... more json ...]
    "objectId": "b08{…}",
    [... more json...]
    

    You should also see the appRoles, including the app role read.weather you just created, om the json output from the New-AzureADServicePrincipal command:

    [... more json...]
      "appRoles": [
        {
          "allowedMemberTypes": [
            "Application"
          ],
          "description": "Read the weather.",
          "displayName": "Read Weather",
          "id": "46f{…}",
          "isEnabled": true,
          "value": "read.weather"
        }
      ],
    [... more json...]
    
    1. To tie it all together make an app role assignment using the command:

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

    E.g. something like this:

    New-AzureADServiceAppRoleAssignment -Id 46f… -ObjectId 18a… -PrincipalId 18a… -ResourceId b08…

    1. Now we are ready to set up the HTTP request in the Logic App using the URI to the API app using Managed Identity for authentication.

    Notice that the audience is needed and has the form: api://{appId}.

    But wait…!

    Does this mean that anyone could do this, if only they know the appId of your application registration, and wouldn’t this compromise the security of the API app?

    Yes, it does, and yes indeed it could compromise the security of the API app.

    If you look at the access token being created and used as bearer from the Logic App it is a valid access token, which contains all the necessary claims, including the app role(s). The access token is however issued by Other Tenant and not Home Tenant.

    Therefore, if you have a multi tenanted application and you want to guard it against this scenario, then you could check the issuer (tid more likely) of the incoming access token calling the API and only accept it if the issuer is the Home Tenant, or you could make the application a single tenant app.

    Or, you could require that the issuer matches a list of tenants that the API trusts.

    0 讨论(0)
提交回复
热议问题