You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

从私有Blob存储部署WAR文件至App Service时遇Bad Request错误

解决私有Blob部署WAR到Azure App Service的权限问题

问题原因

你使用的私有Blob URL未附带访问权限,az webapp deploy命令无法直接访问私有存储中的文件,因此触发Bad Request错误。

解决方案

通过生成**SAS Token(共享访问签名)**为Blob URL附加临时访问权限,无需修改容器的私有访问类型。

步骤1:添加Blob SAS Token数据源

在Terraform代码中添加azurerm_storage_blob_sas数据源,生成仅包含读权限的临时SAS Token:

# 生成私有Blob的临时访问SAS Token
data "azurerm_storage_blob_sas" "war_blob_sas" {
  connection_string = azurerm_storage_account.example.primary_connection_string
  container_name    = azurerm_storage_container.example1.name
  blob_name         = azurerm_storage_blob.blobexample.name

  # 设置SAS有效期,提前30分钟生效避免时间同步问题,有效期1小时
  start  = timeadd(timestamp(), "-30m")
  expiry = timeadd(timestamp(), "1h")

  permissions {
    read = true # 仅授予读权限,满足部署时下载WAR文件的需求
  }
}

步骤2:修改local-exec部署命令

将生成的SAS Token拼接到Blob URL末尾,让az webapp deploy命令获得授权访问私有Blob:

resource "azurerm_linux_web_app" "app_name" {
  # 原有配置代码保持不变...

  provisioner "local-exec" {
    command = "az webapp deploy --resource-group ${azurerm_resource_group.rg.name} --name ${azurerm_linux_web_app.app_name.name} --src-url ${azurerm_storage_blob.blobexample.url}?${data.azurerm_storage_blob_sas.war_blob_sas.sas} --type war"
  }
}

说明

  • SAS Token提供临时、最小权限的访问授权,仅开放读操作,有效期可控,不会暴露存储账户的永久密钥。
  • 可根据实际部署需求调整start和expiry参数,适配你的部署时间窗口。

内容的提问来源于stack exchange,提问作者Lekha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 22:35:41