使用Azure Resource Manager模板配置CORS

问题描述 投票:6回答:5

我正在尝试使用Azure Resource Manager工具在配置CORS下建议为我的存储帐户设置CORS规则:https://docs.microsoft.com/en-us/azure/app-service-api/app-service-api-cors-consume-javascript

通过添加属性cors:

    "resources": [
    {
        "type": "Microsoft.Storage/storageAccounts",
        "sku": {
            "name": "Standard_RAGRS",
            "tier": "Standard"
        },
        "kind": "Storage",
        "name": "[parameters('storageAccounts_teststoragejkjk_name')]",
        "apiVersion": "2016-01-01",
        "location": "westus",
        "tags": {},
        "properties": {
            "cors": {"allowedOrigins": ["*"]}
        },
        "resources": [],
        "dependsOn": []
    }
]

部署返回成功,我可以在Azure门户的活动日志下看到Write StorageAccount操作,但Cors规则不会添加到任何地方,当我从Azure下载模板时,它没有这个“cors属性”。

我也尝试手动添加Corse规则(我只需要在我的Blob上),自动化脚本(包括deployment.ps)看起来仍然相同......

有关如何使用ARM模板配置Cors规则的blob存储的任何建议?

azure powershell cors azure-storage-blobs azure-resource-manager
5个回答
3
投票

什么是部署客户端?如果你使用Powershell部署ARM(你可能是),为什么不使用Set-AzureStorageCORSRule

PS C:\>$CorsRules = (@{
AllowedHeaders=@("x-ms-blob-content-type","x-ms-blob-content-disposition");
AllowedOrigins=@("*");
MaxAgeInSeconds=30;
AllowedMethods=@("Get","Connect")},
@{
AllowedOrigins=@("http://www.fabrikam.com","http://www.contoso.com");
ExposedHeaders=@("x-ms-meta-data*","x-ms-meta-customheader");
AllowedHeaders=@("x-ms-meta-target*","x-ms-meta-customheader");
MaxAgeInSeconds=30;
AllowedMethods=@("Put")})

PS C:\> Set-AzureStorageCORSRule -ServiceType Blob -CorsRules $CorsRules


2
投票

我正在尝试为我的存储帐户设置CORS规则

我创建了一个类似的ARM template来创建存储帐户资源,我发现它似乎无法识别/接受cors和其他属性(例如我定义的val),除了accountType属性。

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": { },
  "variables": { },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "2015-06-15",
      "name": "[concat('storage', uniqueString(resourceGroup().id))]",
      "location": "[resourceGroup().location]",
      "properties": {
        "accountType": "Standard_LRS",
        "cors": {
          "allowedHeaders": [ "*" ],
          "allowedMethods": [ "get", "post", "put" ],
          "allowedOrigins": [ "*" ],
          "exposedHeaders": [ "*" ],
          "maximumAge": 5
        },
        "val": "123"
      }
    }
  ],
  "outputs": { }
}

此外,正如我们所知,我们可以为天蓝色存储服务(blob,表,队列和文件共享)配置Cors设置,似乎它不能使我们在部署存储帐户模板时直接在存储帐户级别配置Cors设置。 enter image description here


1
投票

存储资源提供程序当前不支持存储帐户CORS,因此无法通过模板进行设置。正如Fred指出的那样,CORS只能通过data plane API设置在服务上。


1
投票

我在谷歌搜索时遇到了这个帖子。现在可以通过ARM模板https://docs.microsoft.com/en-us/azure/templates/microsoft.storage/2018-07-01/storageaccounts/blobservices在存储帐户的blob服务上设置CORS

经过测试,它的工作原理


0
投票

正如@JBA指出的那样现在可以通过ARM templates工作了。

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "name": "storageAccountName",
      "apiVersion": "2018-02-01",
      "location": "northeurope",
      "kind": "StorageV2",
      "sku": {
        "name": "Standard_LRS",
        "tier": "Standard"
      },
      "tags": {},
      "dependsOn": [],
      "properties": {
        "accessTier": "Hot"
      },
      "resources": [
        {
          "name": "default",
          "type": "blobServices",
          "apiVersion": "2018-11-01",
          "dependsOn": [
            "storageAccountName"
          ],
          "properties": {
            "cors": {
              "corsRules": [
                {
                  "allowedOrigins": [
                    "https://mywebsite.com"
                  ],
                  "allowedMethods": [
                    "GET"
                  ],
                  "maxAgeInSeconds": 0,
                  "exposedHeaders": [
                    "*"
                  ],
                  "allowedHeaders": [
                    "*"
                  ]
                }
              ]
            }
          },
          "resources": []
        },
        {
          "type": "blobServices/containers",
          "apiVersion": "2018-03-01-preview",
          "name": "[concat('default/', 'myFilesToShare')]",
          "dependsOn": [
            "storageAccountName"
          ],
          "properties": {
            "publicAccess": "Blob"
          }
        }
      ]
    }
  ]
}
© www.soinside.com 2019 - 2024. All rights reserved.