原文地址:https://prodata.ie/2022/06/16/enabling-managed-identity-authentication-on-azure-functions-in-data-factory/

 

This blog shows you how to enable Managed Identity on an Azure Function call from ADF, this can help secure the Function by adding a second authentication method on top of the API Key. Enabling these options enforces https on all function calls, ADF handles authentication and so no custom headers, tokens or keys are necessary to be exchanged.

The high level process is:

  1. Configure Microsoft Identity on Azure Function
  2. Enable Managed Identity on Data Factory
  3. Configure Linked Service in Data Factory
  4. Assign Permissions to the Data Factory in Azure Function

 

Step 1 – Enable Microsoft Identity on Azure Function

On the Azure function, in the authentication tab, click Add identity provider.

【转】Enabling Managed Identity Authentication on Azure Functions in Data Factory_ide

Set the identity provider to Microsoft, you can manually create one in Azure Active Directory (App Registrations) but I recommend choosing to create a new app registration, changing its name to FunctionName-auth / -app and giving it the default permissions.

【转】Enabling Managed Identity Authentication on Azure Functions in Data Factory_ide_02

Use the default permission option

【转】Enabling Managed Identity Authentication on Azure Functions in Data Factory_Azure_03

Copy the generated App (client) id, as this is used in data factory to handle authorization.

【转】Enabling Managed Identity Authentication on Azure Functions in Data Factory_Azure_04

Step 2 – Enable Managed Identity on Data Factory

In the Data Factory’s controls, go to Managed Identities, and enable a system assigned Identity.

【转】Enabling Managed Identity Authentication on Azure Functions in Data Factory_ide_05

Step 3- Configure Linked Service in Data Factory

Enter the Data Factory studio, and then Manage, Linked Services and either create a new or update previous function implementation.

【转】Enabling Managed Identity Authentication on Azure Functions in Data Factory_Azure_06

Change authentication method to System Assigned Managed Identity, and paste the copied client ID from Step 1 into Resource ID. This step is necessary as authorization does not work without this.

【转】Enabling Managed Identity Authentication on Azure Functions in Data Factory_Data_07

Step 4 – Assign Permissions to the Data Factory in Function

On the function app, go to Access control (IAM), and Add a new role assignment

【转】Enabling Managed Identity Authentication on Azure Functions in Data Factory_ide_08

Assign reader role.

【转】Enabling Managed Identity Authentication on Azure Functions in Data Factory_Azure_09

Assign the Data Factory’s Managed Identity to that role.

 

【转】Enabling Managed Identity Authentication on Azure Functions in Data Factory_Azure_10

Here is an example function working.

【转】Enabling Managed Identity Authentication on Azure Functions in Data Factory_Data_11

The response below indicates that either the app registration was deleted/ created incorrectly, or the role is not assigned in the Data Factory’s IAM.

【转】Enabling Managed Identity Authentication on Azure Functions in Data Factory_Data_12

Differences to Microsoft Articles

The Microsoft Articles that we could find on this matter don’t include all the steps to get it working end to end. In the fast paced world of azure things get out of date fast 


https://docs.microsoft.com/en-us/azure/app-service/configure-authentication-provider-aad

This doesn’t provide an example of linking the resource ID and adding permissions for the data factory on the function.

https://docs.microsoft.com/en-us/azure/spring-cloud/tutorial-managed-identities-functions

This article uses old examples of App Registration and Authentication configuration as well as outdated instructions on permission management.

当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!