custom-script-extension-linux: Getting HTTP 403 when attempting to download fileUris with user-assigned managed identity

Using v2.1.3 of this extension with a user-assigned managed identity, it fails when attempting to download the files defined in fileUris with the following errors:

time=2020-03-23T23:22:23Z version=v2.1.3/git@4cd2b9f-clean operation=enable seq=6 file=0 event="download start"
time=2020-03-23T23:22:23Z version=v2.1.3/git@4cd2b9f-clean operation=enable seq=6 file=0 retry=0 error="unexpected status code: actual=404 expected=200"
time=2020-03-23T23:22:23Z version=v2.1.3/git@4cd2b9f-clean operation=enable seq=6 file=0 retry=0 info="downloader download.urlDownload returned 404, skipping retries"
time=2020-03-23T23:22:23Z version=v2.1.3/git@4cd2b9f-clean operation=enable seq=6 file=0 retry=0 error="unexpected status code: actual=403 expected=200"
time=2020-03-23T23:22:23Z version=v2.1.3/git@4cd2b9f-clean operation=enable seq=6 file=0 retry=0 info="downloader *download.blobWithMsiToken returned 403, skipping retries"
time=2020-03-23T23:22:23Z version=v2.1.3/git@4cd2b9f-clean operation=enable seq=6 file=0 event="download failed" error="failed to download file: unexpected status code: actual=403 expected=200"
time=2020-03-23T23:22:23Z version=v2.1.3/git@4cd2b9f-clean operation=enable seq=6 event="failed to handle" error="processing file downloads failed: failed to download file[0]: failed to download file: unexpected status code: actual=403 expected=200"

I’ve double checked that the user-assigned identity has the proper role assignments for both the VM and the Storage Account (Contributor role in both cases).

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 2
  • Comments: 15

Most upvoted comments

Finally found a solution for me. The user assigned identity needs at least “Storage Blob Data Contributor” (Reader is not enough!) Role on Storage Account. Below my template for reference:

    {
      "type": "Microsoft.Compute/virtualMachines/extensions",
      "apiVersion": "2021-07-01",
      "name": "[format('{0}/{1}', parameters('virtualMachineName'), 'InstallTools')]",
      "location": "[variables('location')]",
      "properties": {
        "publisher": "Microsoft.Azure.Extensions",
        "type": "CustomScript",
        "typeHandlerVersion": "2.1",
        "autoUpgradeMinorVersion": true,
        "settings": {
          "skipDos2Unix": false,
          "fileUris": [
            "[format('{0}test.yml', parameters('storageLocationScripts'))]"
          ]
        },
        "protectedSettings": {
          "commandToExecute": "touch test.txt",
          "managedIdentity": {
            "clientId": "088795a3-f52c-4b29-883e-7c3f379293b5"
          }
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'))]"
      ]
    }

Hope this helps anyone.