Loading...

Seamless Integration: Leveraging Managed Identities to Invoke API Management from Azure Logic App

Seamless Integration: Leveraging Managed Identities to Invoke API Management from Azure Logic App

Organizations are continuously looking for ways to streamline their processes, enhance security, and improve the overall efficiency of their operations. One common challenge faced by businesses is securely accessing and managing APIs  while ensuring the confidentiality and integrity of data.

 

In this blog, we'll explore how organizations can leverage Azure Logic App and Managed Identities to achieve seamless integration with Azure API Management, simplifying authentication and enhancing security.

 

Managed Identities provide a secure way for Azure services and resources to authenticate themselves to other Azure services, eliminating the need for explicit credentials or secrets. They allow services like Azure Functions and Azure Logic Apps to access other resources securely without the complexities of managing credentials.

 

High level steps:

Step 1: Register an application in Azure AD to represent the logic app(client application)

Step 2: Create a managed identity for Logic App

Step 3: Associate the Managed Identity to the Application Role

Step 4: Configure Logic App to trigger HTTP Action to invoke the API

Step 5: Configure a JWT validation policy in the APIM to pre-authorize requests

Step 6: Testing - Trigger the logic app to run

 

Step 1: Register an application in Azure AD to represent the logic app(client application)

  1. In your Azure Portal, go to Azure Active Directory, select App Registrations
  2. Select New registration
  3. When the Register an application page appears, enter your application's registration information:
    • In the Name section, enter a meaningful application name that will be displayed to users of the app, such as client-app.
    • In the Supported account types section, select an option that suits your scenario.
  4. Leave the Redirect URI section empty
  5. Select Register to create the application.
  6. On the app Overview page, find the Application (client) ID value and record it for later.
  7. Under the Manage section of the side menu, select Expose an API and set the Application ID URI with the default value. Record this value for later.
  8. Under the Manage section of the side menu, select App roles then click Create app role:
    1. In the Display name, enter a meaningful role name for example: AddRole
    2. Allowed member types: select Applications
    3. Value: example: AddRole
    4. Description: <as necessary>
    5. Do you want to enable this app role? checked
    6. Click Apply
    7. Record the role ID for later
  9. Repeat the step 8 to add additional App roles (if any) supported by your API.

 

Step 2: Create a managed identity for Logic App

You can either use system assigned managed identity or user assigned managed identity.

 

System assigned managed identity is tied directly to the lifecycle of the Azure resource which its assigned. When you delete the resource, the managed identity is also removed. Each resource can have only one System Assigned Managed Identity, and it can't be shared with other resources.

 

User Assigned Managed Identities, as the name suggests, are created explicitly by users within Azure AD. You can create them independently of Azure resources. Unlike System Assigned Managed Identities, User Assigned Managed Identities are not tied to a specific Azure resource's lifecycle. They are created and deleted independently of any resource. It can be associated with one or more Azure resources, allowing you to share the identity across different resources.

 

To learn more about it refer this link.

 

I have used system assigned managed identity for Logic App.

  1. Go to the Azure Portal (https://portal.azure.com/).
  2. Navigate to the Logic App you want to configure with Managed Identity.
  3. Under the Logic App's "Settings," click on "Identity."
  4. In the "Identity" blade, enable the System-assigned Managed Identity for your Logic App. Click "Save."

 

anammalu_0-1695405369717.png

 

Step 3: Assign Managed Identity access to the Application Role using powershell

Use the below script in azcli powershell to assign managed identity access to the application role

# Install the Azure AD module if you don't have it yet. # Install-Module AzureAD $tenantID = '<tenantID guid>' $serverApplicationName = '<Application Registration Name>' $managedIdentityName = '<managed identity name - for system assigned is the name of your resource>' $appRoleName = '<role name>' Connect-AzureAD -TenantId $tenantID # Look up the Logic app's managed identity's object ID. $managedIdentity = (Get-AzureADServicePrincipal -Filter "DisplayName eq '$managedIdentityName'") $managedIdentityObjectId = $managedIdentity.ObjectId # Look up the details about the server app's service principal and app role. $serverServicePrincipal = (Get-AzureADServicePrincipal -Filter "DisplayName eq '$serverApplicationName'") $serverServicePrincipalObjectId = $serverServicePrincipal.ObjectId $appRoleId = ($serverServicePrincipal.AppRoles | Where-Object {$_.Value -eq $appRoleName }).Id # Assign the managed identity access to the app role. New-AzureADServiceAppRoleAssignment -ObjectId $managedIdentityObjectId -Id $appRoleId -PrincipalId $managedIdentityObjectId -ResourceId $serverServicePrincipalObjectId

 

I have used the script from Microsoft docs link

 

 Step 4: Configure Logic App to trigger HTTP Action to invoke the API

In your Logic App workflow:

  1. Add an HTTP action to make requests to the APIM API endpoint
  2. Provide the API endpoint in the URI and select the method
  3. Add the Ocp-Apim-Subscription-Key HTTP header to the request, passing the value of a valid subscription key. (you can fetch it from APIM)

  4. Add authentication header and select the Authentication type as Managed Identity, select system-assigned managed identity and audience as the Application ID URI you recorded from the step 1.

anammalu_1-1695405369720.png

 

Step 5: Configure a JWT validation policy in the APIM to pre-authorize requests

Add the following Validate JWT policy to <inbound> policy section of your API which checks the value of the audience claim in an access token obtained from Azure AD and checks the additional claims for the app role and returns an error message if the token is not valid. Refer this link for more information.

<!-- replace the following values with the values in your solution: tenantID - the guid representing your Azure Active Directory Tenant ID clientId – api://client ID of the Application registered on Step 1 roleID - the value of the role defined on Step 1 --> <validate-jwt header-name="Authorization" failed-validation-httpcode="401" failed-validation-error-message="Unauthorized. Access token is missing or invalid." require-scheme="Bearer"> <openid-config url=https://login.microsoftonline.com/{{tenantID}}/v2.0/.well-known/openid-configuration /> <audiences> <audience>{{clientID}}</audience> </audiences> <issuers> <issuer>https://sts.windows.net/{{tenantID}}/</issuer> </issuers> <required-claims> <claim name="roles" match="any"> <value>{{roleId}}</value> </claim> </required-claims> </validate-jwt>

 

 

Step 6: Testing - Trigger the logic app to run

Trigger your Logic App to run, and it will use its Managed Identity to authenticate and make requests to the APIM resource.

 

anammalu_2-1695405369723.png

 

That's it! Your Logic App is now configured to access the API Management resource using Managed Identity.

 

Conclusion:

The Managed Identity seamlessly handles authentication to Azure API Management, eliminating the need for managing credentials or tokens manually. Although the setup process might initially appear complex, the long-term benefits are invaluable.

With this approach, you've effectively established a password less solution for your internal API interactions. This is especially valuable for projects involving extensive system integrations, where simplicity, security, and streamlined workflows are paramount. Embracing Managed Identities paves the way for a future where secure, hassle-free API communication becomes the norm.

 

 

 

Published on:

Learn more
Azure Architecture Blog articles
Azure Architecture Blog articles

Azure Architecture Blog articles

Share post:

Related posts

End-to-End Full-Stack Web Application with Azure AD B2C Authentication: A Complete Guide

Application Overview The purpose of this sample application is to demonstrate the usage of Azure Active Directory B2C (Azure AD B2C) for authe...

1 year ago

Complex Data Extraction using Document Intelligence and RAG

Section 1: Introduction   Historically, data extraction from unstructured documents was a manual and tedious process. It consisted of a c...

1 year ago

Harnessing Generative AI with Weaviate on Azure Kubernetes Service and Azure NetApp Files

Table of Contents Introduction Prerequisites Install Weaviate Approximate Nearest Neighbor (ANN) Benchmarks ANN Benchmarks Setup ANN Benchmark...

1 year ago

Securing Containerized Applications with SSH Tunneling

As cloud engineers and architects embrace containerization, ensuring secure communication becomes paramount. Data transmission and access cont...

1 year ago

Exploring AI Agent-Driven Auto Insurance Claims RAG Pipeline.

Introduction: In this post, I explore a recent experiment aimed at creating a RAG pipeline tailored for the insurance industry, specificall...

1 year ago

Azure NetApp Files now stores sensitive data DoD IL5 compliant in Azure US Government regions

Table of Contents Introduction Why Azure NetApp Files? DoD IL5 compliance in Azure Government Azure NetApp Files reaches feature parity betwee...

1 year ago

Data Intelligence End-to-End with Azure Databricks and Microsoft Fabric

This Azure Architecture Blog was written in conjunction with Isaac Gritz, Senior Solutions Architect, at Databricks.   The Data Inte...

1 year ago

AI Studio End-to-End Baseline Reference Implementation

  Azure AI Studio is designed to cater to the growing needs of developers seeking to integrate advanced AI capabilities into their appli...

1 year ago

Mastering AI adoption: Essentials to building, operating and optimizing genAI workloads on Azure

Mastering your AI adoption: Essentials to building, operating and optimizing genAI workloads on Azure As the demand for scalable, efficient AI...

2 years ago

Optimize Azure Stack HCI with the Well-Architected Framework

  Azure Stack HCI is a hyperconverged infrastructure (HCI) solution that provides storage, network, and compute resources in on-premises...

2 years ago

Newsletter

Get the latest Dynamics 365 and Power Platform content in your inbox

A curated digest of community blogs, product news, videos, and podcasts — delivered without the noise.

Weekly updates Unsubscribe anytime Fresh community picks
We use your email only for the newsletter and you can unsubscribe at any time.
By subscribing, you agree to the privacy policy.