【Azure 环境】部署ARM Linked Template时候 Blob SAS Token不能正常工作
问题描述
通过AZ CLI指令部署ARM模板,使用 Linked Template ,并且把模板文件存放到Storage Account中。然后调用 az deployment group create 指令部署模板。
部署指令:
$sasToken = ' <SAS Token> ‘az deployment group create --name DeployLinkedTemplate --resource-group "armtest-rg" --template-uri "https://<stroage account name>.blob.core.chinacloudapi.cn/arm/azuredeploy.json" --parameters projectName=armtestpjname --query-string $sasToken --verbose
Unable to retrieve url https://<stroage account name>.blob.core.chinacloudapi.cn/arm/azuredeploy.json?sp=r
'st' is not recognized as an internal or external command,
operable program or batch file.
'se' is not recognized as an internal or external command,
operable program or batch file.
'spr' is not recognized as an internal or external command,
operable program or batch file.
'sv' is not recognized as an internal or external command,
operable program or batch file.
'sr' is not recognized as an internal or external command,
operable program or batch file.
'sig' is not recognized as an internal or external command,
operable program or batch file.
问题解答
需要使用单引号来包含SAS Token的内容,并且由于内容中包含了&符号,而 “&” 在 CMD/Powershell中是与运算符,需要使用双引号进行转移 [ “&” ], 所以需要把包含&符号的字符串修改为
$sasToken = 'sp=r"&"st=2025-02-14T07:46:18Z"&"se=2025-02-14T15:46:18Z"&"spr=https"&"sv=2022-11-02"&"sr=c"&"sig=xxxxxxxxxxxxxxxxxxxxxxxxxxx'
修改之后,就能成功执行!
附录:存放Linked Template文件的存储账号不能启用防火墙
原因在于当执行 az deployment group create 指令时,会由 ARM Provider 的运行环境来获取存储在Blob中的模板文件,由于ARM Provider主机的IP地址由IPv4,IPv6,且资源如果与存储账号在同一个区域时,会由Azure内部的骨干网直接内网访问,没有公网IP地址。
当为存储账号启用防火墙后,因为如下两个原因无法访问模板文件:
一:防火墙白名单中无法配置IPv6地址,内网地址
二:ARM Provider资源不支持VNET配置且由Azure管理,该资源没有被加入到Storage Account受信任的访问列表中
参考资料
- az deployment does not work with SAS tokens for template-uri : https://stackoverflow.com/questions/53337127/az-deployment-does-not-work-with-sas-tokens-for-template-uri
- 无法链接到位于 Azure 存储防火墙后面的存储帐户中的模板 : https://docs.azure.cn/zh-cn/azure-resource-manager/templates/linked-templates?tabs=azure-powershell#securing-an-external-template
- Trusted access for resources registered in your Microsoft Entra tenant: https://learn.microsoft.com/en-us/azure/storage/common/storage-network-security?tabs=azure-portal#trusted-access-for-resources-registered-in-your-microsoft-entra-tenant
- Azure IP Ranges and Service Tags – China Cloud : https://www.microsoft.com/en-us/download/details.aspx?id=57062
当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2024-02-19 【Azure Function App】在VS Code中,创建好Function App后部署到Azure中,无法选择Subscriptions
2022-02-19 【Azure 应用服务】部署Jar到App Service for Linux,因启动命令路径配置错误而引起:( Application Error 问题
2022-02-19 【Azure 应用服务】App Services 恶意软件防护相关