azure-policy icon indicating copy to clipboard operation
azure-policy copied to clipboard

Alias request: Microsoft.Sql/servers/virtualNetworkRules

Open sewalshmsft opened this issue 8 years ago • 2 comments

Scenario

Enhance the security of Azure SQL by requiring newly deployed server instances to use Virtual Network Service Endpoints.

Definition

{
    "properties": {
        "displayName": "Prevent deployment of Azure SQL without Virtual Network Service Endpoints",
        "description": "Enforce use of Virtual Netework Service Endpoint for Azure SQL by ensure the deployment contains a virtualNetworkRule",
        "parameters": {},
        "policyRule": {
            "if": {
                "allOf": [
                    {
                        "field": "type",
                        "equals": "Microsoft.Sql/servers/virtualNetworkRules"
                    },
                    {
                        "field": "Microsoft.Sql/servers/virtualNetworkRules/[*]",
                        "exists": "false"
                    }
                ]
            },
            "then": {
                "effect": "deny"
            }
        }
    }
}

sewalshmsft avatar Oct 01 '18 20:10 sewalshmsft

This will be needed in Azure MAG as well.

RichShillingtonMSFT avatar Oct 05 '18 17:10 RichShillingtonMSFT

Microsoft.Sql/servers/virtualNetworkRules are child resources of Microsoft.Sql/servers. You cannot use aliases to access the properties of a child resource.

The deny effect may only be used in policies which evaluate a single resource. Since your scenario involves multiple resourceTypes, the best you can do is AuditIfNotExists, e.g.


{
  "if": {
    "field": "type",
    "equals": "Microsoft.Sql/servers"
  },
  "then": {
    "effect": "AuditIfNotExists",
    "details": {
      "type": "Microsoft.Sql/servers/virtualNetworkRules"
    }
  }
}

If you have a specific vnet template in mind, you can use DeployIfNotExists to automatically set up the vnet for new SQL servers.

camillemarie avatar Nov 29 '18 02:11 camillemarie