Linux 和 Windows 机器的 Azure 标记策略
Azure tagging policy for Linux and Windows machines
有一个 ARM 策略用于检查 Azure 中任何 VM 上是否存在特定标记:
{
"mode": "Indexed",
"policyRule": {
"if": {
"AllOf": [
{
"field": "type",
"in": [
"microsoft.compute/virtualmachines",
"Microsoft.ClassicCompute/virtualMachines"
]
},
{
"field": "[concat('tags[', parameters('tagName'), ']')]",
"exists": "false"
}
]
},
"then": {
"effect": "audit"
}
},
"parameters": {
"tagName": {
"type": "String",
"metadata": {
"displayName": "tagName",
"description": "Tag used to unequally identify a VM"
}
}
}
}
问题:
如何创建单独的策略,一个用于 Linux,另一个用于 Windows VM?我找不到如何过滤的方法。 IE。对于 Windows 我使用此策略脚本:
{
"mode": "Indexed",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Compute/virtualMachines"
},
{
"field": "Microsoft.Compute/imagePublisher",
"in": [
"MicrosoftWindowsServer",
"MicrosoftSQLServer"
]
},
{
"field": "[concat('tags[', parameters('tagName'), ']')]",
"exists": "false"
}
]
},
"then": {
"effect": "audit"
}
},
"parameters": {
"tagName": {
"type": "String",
"metadata": {
"displayName": "tagName",
"description": "Tag used to help unequally identify a VM"
}
}
}
}
但上面显示了 Windows 和 Linux,因为它的逻辑类似于“如果 VM 是 windows 并且具有特定的标签,则表示兼容;否则,如果没有特定的标签或VM Linux,视为不合规。
需求:
1x 策略以查看只有 Windows 个 VM 合规(根据标签)。
1x 策略以查看只有 Linux 个 VM 合规(根据标签)。
尝试使用 Microsoft。Compute/virtualMachines/imagePublisher 而不是 Microsoft。Compute/imagePublisher
{
"mode": "Indexed",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Compute/virtualMachines"
},
{
"field": "Microsoft.Compute/imagePublisher",
"in": [
"MicrosoftWindowsServer",
"MicrosoftSQLServer"
]
}
]
},
"then": {
"effect": "auditIfNotExists",
"details": {
"type": "Microsoft.Compute/virtualMachines",
"name": "[field('name')]",
"existenceCondition": {
"field": "[concat('tags[', parameters('tagName'), ']')]",
"exists": "true"
}
}
}
},
"parameters": {
"tagName": {
"type": "String",
"metadata": {
"displayName": "tagName",
"description": "Tag used to help unequally identify a VM"
}
}
}
最终想到这个对我有用
有一个 ARM 策略用于检查 Azure 中任何 VM 上是否存在特定标记:
{
"mode": "Indexed",
"policyRule": {
"if": {
"AllOf": [
{
"field": "type",
"in": [
"microsoft.compute/virtualmachines",
"Microsoft.ClassicCompute/virtualMachines"
]
},
{
"field": "[concat('tags[', parameters('tagName'), ']')]",
"exists": "false"
}
]
},
"then": {
"effect": "audit"
}
},
"parameters": {
"tagName": {
"type": "String",
"metadata": {
"displayName": "tagName",
"description": "Tag used to unequally identify a VM"
}
}
}
}
问题:
如何创建单独的策略,一个用于 Linux,另一个用于 Windows VM?我找不到如何过滤的方法。 IE。对于 Windows 我使用此策略脚本:
{
"mode": "Indexed",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Compute/virtualMachines"
},
{
"field": "Microsoft.Compute/imagePublisher",
"in": [
"MicrosoftWindowsServer",
"MicrosoftSQLServer"
]
},
{
"field": "[concat('tags[', parameters('tagName'), ']')]",
"exists": "false"
}
]
},
"then": {
"effect": "audit"
}
},
"parameters": {
"tagName": {
"type": "String",
"metadata": {
"displayName": "tagName",
"description": "Tag used to help unequally identify a VM"
}
}
}
}
但上面显示了 Windows 和 Linux,因为它的逻辑类似于“如果 VM 是 windows 并且具有特定的标签,则表示兼容;否则,如果没有特定的标签或VM Linux,视为不合规。
需求:
1x 策略以查看只有 Windows 个 VM 合规(根据标签)。
1x 策略以查看只有 Linux 个 VM 合规(根据标签)。
尝试使用 Microsoft。Compute/virtualMachines/imagePublisher 而不是 Microsoft。Compute/imagePublisher
{
"mode": "Indexed",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Compute/virtualMachines"
},
{
"field": "Microsoft.Compute/imagePublisher",
"in": [
"MicrosoftWindowsServer",
"MicrosoftSQLServer"
]
}
]
},
"then": {
"effect": "auditIfNotExists",
"details": {
"type": "Microsoft.Compute/virtualMachines",
"name": "[field('name')]",
"existenceCondition": {
"field": "[concat('tags[', parameters('tagName'), ']')]",
"exists": "true"
}
}
}
},
"parameters": {
"tagName": {
"type": "String",
"metadata": {
"displayName": "tagName",
"description": "Tag used to help unequally identify a VM"
}
}
}
最终想到这个对我有用