Azure VM自定义脚本扩展SAS令牌支持

时间:2017-05-03 06:07:25

标签: azure azure-virtual-machine azure-resource-manager azure-template

我正在尝试使用ARM模板部署向Azure VM添加自定义脚本扩展,我想让它使用SAS令牌从存储帐户下载文件。

这是模板(简化):

{
    "name": "CustomScriptExtension"
    "type": "Microsoft.Compute/virtualMachines/extensions",
    "location": "eastus",
    "properties": {
        "publisher": "Microsoft.Compute",
        "type": "CustomScriptExtension",
        "typeHandlerVersion": "1.8",
        "settings": {
            "fileUris": [
                "https://{storage-account}.blob.core.windows.net/installers/{installer}.msi?sv=2015-04-05&sig={signature}&st=2017-05-03T05:18:28Z&se=2017-05-10T05:18:28Z&srt=o&ss=b&sp=r"
            ],
            "commandToExecute": "start /wait msiexec /package {installer}.msi /quiet"
        },
    }
}

部署它会导致此错误:

{
  "name": "CustomScriptExtension",
  "type": "Microsoft.Compute.CustomScriptExtension",
  "typeHandlerVersion": "1.8",
  "statuses": [
    {
      "code": "ProvisioningState/failed/3",
      "level": "Error",
      "displayStatus": "Provisioning failed",
      "message": "Failed to download all specified files. Exiting. Error Message: Missing mandatory parameters for valid Shared Access Signature"
    }
  ]
}

如果我直接使用SAS令牌点击URL,它会正确地下拉文件,因此我知道SAS令牌是正确的。自定义脚本扩展插件是否不支持带有SAS令牌的URL?

4 个答案:

答案 0 :(得分:5)

我想通了,这必定是自定义脚本扩展中的一个错误,导致它不支持存储帐户级SAS令牌。如果我在SAS令牌的末尾添加&sr=b(这不是存储帐户级SAS令牌规范的一部分),它就会开始工作。

我在这里找到了这个信息: https://azureoperations.wordpress.com/2016/11/21/first-blog-post/

答案 1 :(得分:1)

正如@ 4c74356b41所说。现在,客户脚本扩展模板不支持SAS令牌。如果要从专用存储帐户下载文件,可以使用存储帐户密钥。请参阅此example

{
      "type": "Microsoft.Compute/virtualMachines/extensions",
      "name": "[concat(variables('vmName'),'/', variables('extensionName'))]",
      "apiVersion": "[variables('apiVersion')]",
      "location": "[resourceGroup().location]",
      "dependsOn": [
        "[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]"
      ],
      "properties": {
        "publisher": "Microsoft.Azure.Extensions",
        "type": "CustomScript",
        "typeHandlerVersion": "2.0",
        "autoUpgradeMinorVersion": true,
        "settings": {
          "fileUris": "[split(parameters('fileUris'), ' ')]",
          "commandToExecute": "[parameters('commandToExecute')]"
        },
        "protectedSettings": {
          "storageAccountName": "[parameters('customScriptStorageAccountName')]",
          "storageAccountKey": "[parameters('customScriptStorageAccountKey')]"
        }
      }
    }

答案 2 :(得分:0)

不,它不支持SAS令牌。请参阅此反馈项:

https://github.com/Azure/azure-linux-extensions/issues/105

答案 3 :(得分:0)

当前,VM Extension中支持S​​AS令牌