如何使用 Azure Pipelines 在 Azure AD 中注册 Web 应用程序?

How to register a web app in Azure AD using Azure Pipelines?

我正在尝试使用 Bicep 模板和 Azure Pipelines 部署 Azure 资源。 到目前为止,我设法部署了一个 Web 应用程序,但我很难在 Azure AD 中注册它。

我的管道中有一个作业应该在 Azure AD 中创建一个应用程序:

此作业失败并出现以下错误:

ERROR: Insufficient privileges to complete the operation.

我也试过像这样使用 az rest 命令 并得到类似的错误:

ERROR: Forbidden({"error":{"code":"Authorization_RequestDenied","message":"Insufficient privileges to complete the operation.","innerError":{"date":"2022-03-01T07:18:30","request-id":"903fcd87-ad15-4766-8f31-132185e2c97d","client-request-id":"903fcd87-ad15-4766-8f31-132185e2c97d"}}})

很明显,管道使用的服务连接没有一些必要的权限,但我不知道是哪个。

服务连接具有 所有者 角色。以下是服务连接的 API 权限:

有一个类似问题的 提示我需要 Application.ReadWrite.All in Azure AD Graph ,但 Azure AD 已弃用:

如有任何帮助,我们将不胜感激!

您应该改用 Microsoft Graph 并select那里有适当的权限。

另一种选择是让 Web 应用程序的 bicep 模板通过在标识中使用 SystemAssigned 为您添加系统管理的标识 属性:

 resource appService 'Microsoft.Web/sites@2020-06-01' = {
  name: webAppName
  location: location
  properties: {
    serverFarmId: appServicePlan.id
    siteConfig:{
      alwaysOn: true
    }
    httpsOnly: true  
    clientAffinityEnabled: false
  }
  identity: {
    type: 'SystemAssigned'
    }
}