VSTS 部署失败并显示“授权失败......类型为‘Microsoft.Storage/storageAccounts/providers/locks’”

Kai*_*ter 3 azure azure-resource-manager azure-devops

我正在部署一个带有 VSTS 的 ARM 模板,其中包含一个锁(在我的情况下,锁定功能应用程序的存储帐户)

{
    "parameters": {
        "name": {
            "type": "string"
        },
        "storageName": {
            "type": "string"
        },
        "location": {
            "type": "string"
        }
    },
    "resources": [
        {
            "apiVersion": "2015-05-01-preview",
            "type": "Microsoft.Storage/storageAccounts",
            "name": "[parameters('storageName')]",
            "location": "[parameters('location')]",
            "properties": {
                "accountType": "Standard_LRS"
            },
            "resources": [
                {
                    "type": "Microsoft.Storage/storageAccounts/providers/locks",
                    "name": "[concat(parameters('storageName'), '/Microsoft.Authorization/', parameters('storageName'))]",
                    "apiVersion": "2015-01-01",
                    "dependsOn": [
                        "[concat('Microsoft.Storage/storageAccounts/', parameters('storageName'))]"
                    ],
                    "properties": {
                        "level": "CannotDelete",
                        "notes": "One or more function apps were linked to this storage account. You can see all the function apps linked to the account under 'files' or 'shares'."
                    }
                }
            ]
        },...
Run Code Online (Sandbox Code Playgroud)

当使用我的凭据从 VS 或命令行部署时,这很好用。但是,从 VSTS 版本定义进行部署时,部署失败并显示:

Resource Microsoft.Resources/deployments 'myFunctionApp' failed with message '{
  "error": {
    "code": "InvalidTemplateDeployment",
    "message": "The template deployment failed with error: 'Authorization failed for template resource 'myFunctionAppStorage/Microsoft.Authorization/myFunctionAppStorage' of type 'Microsoft.Storage/storageAccounts/providers/locks'. The client '***VSTS service principal Id***' with object id '***VSTS service principal Id***' does not have permission to perform action 'Microsoft.Authorization/locks/write' at scope '/subscriptions/*** subscription ***/resourceGroups/*** resource group ***/providers/Microsoft.Storage/storageAccounts/myFunctionAppStorage/providers/Microsoft.Authorization/locks/myFunctionAppStorage'.'."
  }
}
Run Code Online (Sandbox Code Playgroud)

当我Microsoft.Storage/storageAccounts/providers/locks从模板中删除该部分时,VSTS 部署工作。但是随后存储帐户将不会受到阻止删除的锁定。

Kai*_*ter 7

Contributor角色 - 当 VSTS 在连接到资源组订阅的 AAD 中创建服务主体时分配 - 不足以放置锁定。分配Owner和锁定可以与 VSTS 部署过程一起放置。