使用 Azure Policy 创建资源组时,我想强制将用户 ID 和电子邮件地址等帐户信息作为标签。
经过参考,可以标记一个固定的单词,但不知道如何动态获取上述账户信息。
如果您认识任何人,请教我如何做。
谢谢。
DeployIfNotExists
我正在尝试根据现有策略创建策略AuditIfNotExists
。部署时不会出错,但会错误提示“没有相关资源与策略定义中的效果详细信息匹配”。当评估政策时。AuditIfnotExists
当我将其部署到同一管理组时,该策略确实运行良好。我想知道我是否错过了什么。
此策略用于创建删除 NSG 组(如果不存在)的警报。这是DeployIfNotExists
政策 - 你们觉得有什么问题吗?任何意见表示赞赏。谢谢。
{
"$schema":"https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion":"1.0.0.0",
"parameters":{
"effect":{
"type":"string",
"metadata":{
"displayName":"Effect",
"description":"Enable or disable the execution of the policy"
},
"allowedValues":[
"AuditIfNotExists",
"deployIfNotExists",
"Disabled"
],
"defaultValue":"deployIfNotExists"
}
},
"variables":{
"actionGroupName":"dsactiongroup"
},
"resources":[
{
"name":"CIS5.2.3-EnsureAuditDeleteNSG",
"type":"Microsoft.Authorization/policyDefinitions",
"apiVersion":"2019-09-01",
"properties":{
"policyType":"Custom",
"displayName":"CIS 5.2.3 Ensure that Activity Log Alert exists for Delete Network Security Group (Scored)",
"description":"Monitor Activity Alerts exist for specific activities.",
"mode":"all",
"metadata":{
"category":"Audit"
},
"parameters":{
},
"policyRule":{
"if":{
"allOf":[
{
"field":"type", …
Run Code Online (Sandbox Code Playgroud) 我目前正在尝试了解 Azure 政策。我想我已经了解了别名,但我无法理解在哪里可以找到 ExistenceCondition equals 字段的正确值
我应用的政策规则:
"if":{
"allOf":[
{
"field":"type",
"equals":"Microsoft.Insights/metricalerts"
},
{
"field":"Microsoft.Insights/metricalerts/enabled",
"equals":"true"
},
{
"field":"Microsoft.Insights/metricalerts/actions[*]",
"less":"1"
}
]
}
Run Code Online (Sandbox Code Playgroud) 我制定了以下非常基本的政策,旨在对新资源组强制执行命名约定。
{
"mode": "All",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Resources/resourceGroups"
},
{
"field": "name",
"notLike": "rg-*"
}
]
},
"then": {
"effect": "deny"
}
},
"parameters": {}
}
Run Code Online (Sandbox Code Playgroud)
该策略是在订阅级别分配的,并且policy enforcement = enabled
。没有排除情况,正如您从策略中看到的,效果设置为deny
。
然而,这个政策根本就没有任何效果。我可以noncompliant
随意创建名称为 , ... 的新资源组。另外,我等了30多分钟政策才生效(实际上我等了24小时多)。
有趣的是,以下策略生效(几乎在分配后立即生效),唯一的区别是资源类型的比较。
{
"mode": "All",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/virtualNetworks"
},
{
"field": "name",
"notLike": "vnet-*"
}
]
},
"then": {
"effect": "deny"
}
},
"parameters": {}
} …
Run Code Online (Sandbox Code Playgroud) 我的资源组有一个environment
标签,其中只允许特定值:"dev,test,prod"
。我想使用 Azure 策略强制执行此操作,该策略将拒绝所有标记中没有此"dev,test,prod"
值之一的资源组创建environment
。我的策略代码如下:
{
"properties": {
"displayName": "Allowed tag values for Resource Groups",
"description": "This policy enables you to restrict the tag values for Resource Groups.",
"policyType": "Custom",
"mode": "Indexed",
"metadata": {
"version": "1.0.0",
"category": "Tags"
},
"parameters": {
"allowedTagValues": {
"type": "array",
"metadata": {
"description": "The list of tag values that can be specified when deploying resource groups",
"displayName": "Allowed tag values"
},
"defaultValue": [
"dev","test","prod"
] …
Run Code Online (Sandbox Code Playgroud)