【问题标题】:Condition existence check in Azure : deny PolicyAzure 中的条件存在检查:拒绝策略
【发布时间】:2022-01-03 00:30:03
【问题描述】:

是否可以根据存在逻辑创建策略定义以拒绝创建。例如 - 如果 EnableHttpsTrafficOnly 在存储帐户上设置为 false,我想拒绝创建存储 blob 或文件共享。请注意,此策略应仅拒绝创建 blob 或共享资源,而不应拒绝创建存储帐户。

使用以下策略,但它不起作用

"allOf": [
{
"not": {
"field": "Microsoft.Storage/storageAccounts/supportsHttpsTrafficOnly",
"equals": "true"
}
},
{
"allOf": [
{
"source": "action",
"like": "Microsoft.Storage/storageAccounts/fileServices/shares/*"
},
{
"field": "Microsoft.Storage/storageAccounts/fileServices/shares/enabledProtocols",
"equals": "SMB"
}
]
}
]
}```

【问题讨论】:

    标签: json azure azure-storage azure-policy


    【解决方案1】:

    关于问题-

    是否可以根据存在逻辑创建拒绝创建的策略定义?

    答案是,您可以使用自定义策略定义,根据存在逻辑创建策略定义。您首先确定资源属性并应用条件来设置要使用的效果。

    我尝试使用以下策略定义重现您尝试执行的操作,但也没有成功。

    {  
        "mode": "All",  
        "policyRule": {  
            "if": {  
                "allOf": [  
                    {  
                        "field": "type",  
                        "equals": "Microsoft.Storage/storageAccounts/blobServices"  
                    },  
                    {         
                        "field": "Microsoft.Storage/storageAccounts/supportsHttpsTrafficOnly",
                        "notEquals": "true"
                    }
                ]  
            },  
            "then": {  
                "effect": "deny"  
            }  
        },  
        "parameters": {}  
    }
    

    所以我认为我们不能拒绝基于supportsHttpsTrafficOnly 创建存储blob 或文件共享。但是由于supportsHttpsTrafficOnly 是StorageAccountPropertiesCreateParameters 之一,我们可以对存储帐户设置拒绝创建策略,如下面的代码sn-p 所示。

    {
        "if": {
            "allOf": [
            {
                "field": "type",
                "equals": "Microsoft.Storage/storageAccounts"
            },
            {
                "field": "Microsoft.Storage/storageAccounts/supportsHttpsTrafficOnly",
                "notEquals": "true"
            }
            ]
        },
        "then": {
            "effect": "Deny"
        }
    }
    

    我建议阅读Create a custom policy definitionWalkthrough using Azure Policy to audit and enforce compliance 文档以了解更多信息。

    【讨论】:

      猜你喜欢
      • 2022-01-04
      • 2022-01-02
      • 1970-01-01
      • 1970-01-01
      • 2021-03-28
      • 1970-01-01
      • 2021-11-05
      • 1970-01-01
      • 2022-07-06
      相关资源
      最近更新 更多