【问题标题】:Remediation for Network restriction policy of Azure Storage accountAzure 存储账户网络限制策略修复
【发布时间】:2021-03-23 02:54:15
【问题描述】:

我有“存储帐户应限制网络访问”的定义文件。我想在现有存储帐户上运行此策略,如果不符合它,则更改网络访问(删除公共访问 + 分配子集)。作为此政策的一部分,我如何创建此补救措施?

"properties": {
    "displayName": "Audit Storage Accounts Open to Public Networks",
    "policyType": "Custom",
    "mode": "Indexed",
    "description": "This policy ensures that storage accounts with exposure to Public Networks are audited.",
    "parameters": {},
    "policyRule": {
        "if": {
            "allOf": [{
                    "field": "type",
                    "equals": "Microsoft.Storage/storageAccounts"
                },
                {
                    "field": "Microsoft.Storage/storageAccounts/networkAcls.defaultAction",
                    "equals": "Allow"
                }
            ]
        },
        "then": {
            "effect": "audit"
        }
    }
}

【问题讨论】:

    标签: azure azure-storage azure-policy


    【解决方案1】:

    如果要通过 Azure Policy 将 VNET 分配给存储帐户,可以使用 effect DeployIfNotExist 来实现。 例如

    我的定义文件。请注意,在示例中,您使用现有的子网。如需新建子网,请参考template

    {
      "properties": {
        "displayName": "storage3",
        "policyType": "Custom",
        "mode": "All",
        "parameters": {
          "effect": {
            "type": "String",
            "metadata": {
              "displayName": "Effect",
              "description": "Enable or disable the execution of the policy"
            },
            "allowedValues": [
              "DeployIfNotExists",
              "Disabled"
            ],
            "defaultValue": "DeployIfNotExists"
          }
        },
        "policyRule": {
          "if": {
            "allOf": [
              {
                "field": "type",
                "equals": "Microsoft.Storage/storageAccounts"
              },
              {
                "field": "Microsoft.Storage/storageAccounts/networkAcls.defaultAction",
                "notEquals": "Deny"
              }
            ]
          },
          "then": {
            "effect": "[parameters('effect')]",
            "details": {
              "type": "Microsoft.Storage/storageAccounts",
              "name": "[field('name')]",
              "existenceCondition": {
                "field": "Microsoft.Storage/storageAccounts/networkAcls.defaultAction",
                "equals": "Deny"
              },
              "roleDefinitionIds": [
                "/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
    
              ],
              "deployment": {
                "properties": {
                  "mode": "incremental",
                  "template": {
                    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                      "name": {
                        "type": "string"
                      },
                      "sku": {
                        "type": "string"
                      },
                      "location": {
                        "type": "string"
                      },
                      "kind": {
                        "type": "string"
                      }
                    },
                    "resources": [
                      {
                        "name": "[parameters('name')]",
                        "type": "Microsoft.Storage/storageAccounts",
                        "apiVersion": "2019-06-01",
                        "location": "[parameters('location')]",
                        "properties": {
                          "networkAcls": {
                            "bypass": "AzureServices",
                            "virtualNetworkRules": [
                              {
                                "id": "",
                                "action": "Allow"
                              }
                            ],
                            "ipRules": [],
                            "defaultAction": "Deny"
                          }
                        },
                        "dependsOn": [],
                        "sku": {
                          "name": "[parameters('sku')]"
                        },
                        "kind": "[parameters('kind')]"
                      }
                    ]
                  },
                  "parameters": {
                    "name": {
                      "value": "[field('name')]"
                    },
                    "sku": {
                      "value": "[field('Microsoft.Storage/storageAccounts/sku.name')]"
                    },
                    "location": {
                      "value": "[field('location')]"
                    },
                    "kind": {
                      "value": "[field('kind')]"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    

    更多详情请参考

    https://docs.microsoft.com/en-us/azure/governance/policy/concepts/effects#deployifnotexists

    https://docs.microsoft.com/en-us/azure/storage/common/storage-network-security#grant-access-from-a-virtual-network

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-23
      • 1970-01-01
      • 2021-05-01
      • 2021-06-23
      • 2018-01-29
      • 1970-01-01
      • 2016-03-04
      • 2022-08-02
      相关资源
      最近更新 更多