在Azure数据工厂中使用MSI对Azure Web作业进行身份验证

时间:2019-08-15 16:28:44

标签: azure factory webjob azure-managed-identity

通过ADF中的Web活动对Azure Web作业进行MSI身份验证会给出错误403-此Web应用已停止。问题,而通过基本身份验证调用了同一Web作业。

该Web作业作为手动触发托管在Windows App Service上。

在ADF V2中,我创建了一个网络活动并提供了以下设置:
URL:https://<web app name>.scm.azurewebsites.net/api/triggeredwebjobs/<webjobname>/run
Method: POST
Headers: NA
Body: {}
Authentication: MSI with resource as https://management.azure.com/
  • 我已在部署Web作业的App Service中启用了MSI,并在AAD中确认了这一点。
  • AAD上也已在ADF上启用了MSI。
  • 在应用程序服务中,我已将我的ADF添加到访问控制中,其角色为 Contributor ,并尝试了其他几种角色,例如 Managed Application Operator Role < / strong>。

注意:分配角色并启用MSI后,我也重新启动了我的App Service。

这是adf中网络活动的代码:

{
"name": "pipeline1",
"properties": {
    "activities": [
        {
            "name": "Web1",
            "type": "WebActivity",
            "dependsOn": [],
            "policy": {
                "timeout": "7.00:00:00",
                "retry": 0,
                "retryIntervalInSeconds": 30,
                "secureOutput": false,
                "secureInput": false
            },
            "userProperties": [],
            "typeProperties": {
                "url": "https://<webappname>.scm.azurewebsites.net/api/triggeredwebjobs/<webjobname>/run",
                "method": "POST",
                "authentication": {
                    "type": "MSI",
                    "resource": "https://management.azure.com/"
                }
            }
        }
    ],
    "annotations": []
},
"type": "Microsoft.DataFactory/factories/pipelines"
}

我希望身份验证成功,并且应该触发Web作业,但是实际上Web应用没有通过MSI身份验证调用,并且活动失败,输出为错误403-此Web应用已停止

2 个答案:

答案 0 :(得分:1)

您需要将url更改为https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/triggeredwebjobs/{webJobName}/run?api-version=2016-08-01,然后它将正常工作。

参考-Web Apps - Run Triggered Web Job

测试结果

enter image description here

enter image description here

答案 1 :(得分:0)

大多数MSDN文档都指出,为了对SCM站点进行身份验证,应使用基本身份验证。参考: https://github.com/projectkudu/kudu/wiki/WebJobs-API#invoke-a-triggered-job

但是我能够发现,为了使用MSI对SCM站点进行身份验证,资源应为'https://management.core.windows.net/',而不是'https://management.azure.com'。

要回答上述问题,只需更改“身份验证”中的资源,如下所示:

Authentication: MSI with resource as https://management.azure.com/

参考链接: https://github.com/projectkudu/kudu/issues/2957#issuecomment-477890719 ,其中指出

  

在请求MSI令牌时,您必须定义   https://management.core.windows.net/作为资源而不是   https://management.azure.com/

我当然相信这可能对使用MSI身份验证访问KUDU有所帮助。