-->

Azure的政策拒绝:如果标签中的一个资源组名称不存在(Azure Policy Deny :if

2019-10-29 23:28发布

我创建了一个Azure的政策,我想拒绝的资源组创建,如果用户没有指定用钥匙标签“信封”或“使用”

但是,当我创建一个信封标签它阻止我的资源组,只允许我,当我加入这两者是env和使用标签。

按我的理解,“anyof”在蔚蓝的政策作为“OR”,但我的代码是不是表现同样WA

{
  "if": {
    "allOf": [
      {
        "field": "type",
        "equals": "Microsoft.Resources/subscriptions/resourceGroups"
      },
      {
        "anyof": [
          {
            "field": "tags.Env",
            "exists": false
          },
          {
            "field": "tags.use",
            "exists": false
          }
        ]
      }
    ]
  },
  "then": {
    "effect": "deny"
  }
}

根据克里斯的建议,我制作的标签名称和值,但它给我的政策错误,它不走的是“NOT”

{
  "mode": "all",
  "policyRule": {
    "if": {
      "allOf": [
        {
          "field": "type",
          "equals": "Microsoft.Resources/subscriptions/resourceGroups"
        },
        {
          "not":{
        {
          "field": "tags.Env",
          "equals" : "Prod"
        },
        {
          "field": "tags.OS",
          "equals" : "windows"
        }
                  }
        }
      ]
    },
    "then": {
      "effect": "deny"
    }
  },
  "parameters": {}
}

Answer 1:

眼下,像你提到的,政策评估,如果“tags.Env不存在或tags.use不存在”。 如果两个标签不存在,您将被拒绝。

你想要的是否认,如果“tags.Env不存在,tags.use不存在”。 这将意味着他们都缺少这是你正试图阻止什么。

{
  "if": {
    "allOf": [
      {
        "field": "type",
        "equals": "Microsoft.Resources/subscriptions/resourceGroups"
      },
      {
         "field": "tags.Env",
         "exists": false
       },
       {
         "field": "tags.use",
         "exists": false
       }
    ]
  },
  "then": {
    "effect": "deny"
  }
}


文章来源: Azure Policy Deny :if one of the tag not present in the resource group name