No SAS, No Stress: Access Blob Scripts in AVD Image Templates using Managed Identity

What’s the most annoying part of an automation? When a time-limited token has expired and you start troubleshooting what’s going wrong? I also used the blob script links with a Shared Access Signatures (SAS) to access my files in my AVD Custom Image Templates configuration. But from now on I bring the blob script links at a higher level, without SAS token, instead the managed identity gets enough permission to the blob container to download the files.

Below I describe how to use a managed identity to download files from a blob container in a custom AVD image template configuration.

Prerequisites

This blog article does not describe how to enable AVD custom image templates or the Azure Image Builder.

First requirement is that you have followed the Microsoft documentation on how to use custom image templates to create custom images in Azure Virtual Desktop.

Second, you need to create an Azure storage account with a blob container to which you can upload your custom script file. If you have not already done so, you can follow the link here.

You must ensure that public network access is enabled in the network settings of the storage account, otherwise the creation of the custom image template will fail.

Storage Account networking settings ensure that public network access is activated.

Note: There is no way to enable network access from selected virtual networks or via private endpoint connections, as the image creation service will not be able to connect the storage account.

The access level of the blob container can be set to private (no anonymous access), which means that the files are not publicly accessible anonymously.

Blob container access level can be set to private (no anonymous access).

Short list of what you need:
Managed Identity
– Storage Account with a blob container and custom script file
– AVD Custom Image template you want to optimize

Assign blob reader permission to the managed identity

1. Open your Azure Storage Account for your custom scripts and select “Access Control (IAM)”.

Images shows the Azure Storage Account and the Access Control settings.

2. Click “+Add role assignment” to start the role assignment process.

Image shows the add role assignment drop down.

3. Search for “Storage Blob Data Reader” and select the appropriate authorization role, then click “Next”.

Images shows the selection of the storage blob data reader role.

4. In the members tab select “Managed identity” and click on “+ Select members“.

Image shows the members tab to select assign access to managed identity.

5. Select your subscription and “User Assigned Managed Identity”, then you can search for your managed identity or select it from the list and then click “Select” & “Next“.

Image shows the select of your managed identity.

6. The condition tab can be skipped to the Review + assign tab and then click “Review + assign” to assign the permission role to your managed identity.

Images shows the summary of the add  role assignment process.

Use blob script file without SAS token in a custom image template

1. Open the Custom image template blade and click “+ Add custom image template”.

Note: There is no way to change an existing custom image template, so we need to create a new template and import an existing template.

Image shows how to add new custom image template.

2. Enter a new template name and select “Yes” to import from an existing template, then “Browser image templates“.

Image shows how to select an existing custom image template.

3. If you have successfully selected an existing template, you can proceed to step 5. Customization and click on “+ Add custom script“.

Image shows how to add custom script to the custom image template.

6. Add the script name (1:1 the script name) and the URI without SAS token from your custom script, then click “Save“.

Image shows the prompt to select the custom script.

7. On the Tags tab, click on “Next” and then on “Create”. It takes a few minutes to create the custom image template.

Image shows the successfully created user-defined image template.

8. In the last step, select your newly created custom image template and click on “Start build” to start the build process.

Image shows how to start the image build.

To check the live logs during the build process

1. Open your staging resource group from the list.

Image shows how to access the staging resource group.

2. Search for a temporary container instance and open this instance.

Image shows how to find the container instance of the build process.

3. Click on “Container” under “Settings” and then open “Logs” to view the live logs during the build process.

Image shows the image builder process live log.

Note: If the build process has been completed successfully or has failed, the log file is saved in the temporary storage account in the staging resource group.

Conclusion

By replacing time-limited SAS tokens with a managed identity and proper RBAC permissions, you not only simplify your AVD image customization process but also significantly improve its security and maintainability.

This approach eliminates the hassle of token expiration and manual updates, allowing your automation to run more reliably and securely. With just a few configuration steps, you can enable your custom image templates to access blob-stored scripts seamlessly—no SAS, no stress.

Resources