簡體   English   中英

Azure 自定義標簽策略,排除資源類型

[英]Azure Custom Tag Policy, Exclude resource type

我做了一個 azure 自定義策略,發現 object 不合規,自定義缺少標簽,我的訂閱。

我從這個政策中得到了很多錯誤,因為它還發現了 oms 代理、擴展等。

這里是 json:

    {
  "mode": "All",
  "policyRule": {
    "if": {
      "anyOf": [
        {
          "field": "tags['TAG1']",
          "exists": false
        },
        {
          "field": "tags['TAG2']",
          "exists": false
        }
      ]
    },
    "then": {
      "effect": "audit"
    }
  },
  "parameters": {}
  }

它會搜索所有資源並對其進行審核(如果它們不帶有該標簽)。

是否可以針對特定資源類型指定排除項? 例如 Microsoft.Compute/virtualMachines/extensions 等...

謝謝

這樣,您可以在“notEquals”運算符中提及您不想檢查標簽的所有資源類型。

{
      "if": {
        "allOf": [
          {
            "field": "type",
            "notEquals": "Microsoft.Security/assessments"
          },
          {
            "field": "type",
            "notEquals": "Microsoft.Compute/VirtualMachines"
          },
          {
            "anyOf": [
              {
                "field": "tags['TAG1']",
                "exists": false
              },
              {
                "field": "tags['TAG2']",
                "exists": false
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "audit"
      }
    }

謝謝它有效:我正在嘗試為以下類型添加其他排除項,但出現錯誤:

{
  "mode": "All",
  "policyRule": {
    "if": {
      "allOf": [
        {
          "not": {
            "field": "type",
            "equals": "Microsoft.Security/assessments"
          },
          {
            "field": "type",
            "equals": "Microsoft.Compute/VirtualMachines"
          }
        },
                  {
            "anyOf": [
              {
                "field": "tags['TAG1']",
                "exists": false
              },
              {
                "field": "tags['TAG2']",
                "exists": false
              }
            ]
          }
        ]
      },
    "then": {
      "effect": "audit"
    }
  },
  "parameters": {}
}

是否可以在同一策略中排除更多 object?

使用"mode": "indexed"而不是"mode": "All"只會匹配支持位置和標簽的資源。

資料來源: https://docs.microsoft.com/en-us/azure/governance/policy/concepts/definition-structure#resource-manager-modes

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM