Bylaw

Gallery › SQL › Azure built-in policies

Virtual network firewall rule on Azure SQL Database should be enabled to allow traffic from the specified subnet

Converted Policy AuditIfNotExists Mode Indexed Version 1.0.0

Virtual network based firewall rules are used to enable traffic from a specific subnet to Azure SQL Database while ensuring the traffic stays within the Azure boundary.

ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.

Azure Policy JSONSqlServer_VNetRules_Audit.json · 44 lines
{
  "properties": {
    "displayName": "Virtual network firewall rule on Azure SQL Database should be enabled to allow traffic from the specified subnet",
    "description": "Virtual network based firewall rules are used to enable traffic from a specific subnet to Azure SQL Database while ensuring the traffic stays within the Azure boundary.",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "metadata": {
      "version": "1.0.0",
      "category": "SQL"
    },
    "version": "1.0.0",
    "parameters": {
      "subnetId": {
        "type": "string",
        "metadata": {
          "displayName": "Subnet ID",
          "strongType": "Microsoft.Network/virtualNetworks/subnets",
          "description": "The resource ID of the virtual network subnet that should have a rule enabled. Example: /subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default/providers/Microsoft.Network/virtualNetworks/testvnet/subnets/testsubnet"
        }
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "equals": "Microsoft.Sql/servers"
      },
      "then": {
        "effect": "AuditIfNotExists",
        "details": {
          "type": "Microsoft.Sql/servers/virtualNetworkRules",
          "existenceCondition": {
            "field": "Microsoft.Sql/servers/virtualNetworkRules/virtualNetworkSubnetId",
            "equals": "[parameters('subnetId')]"
          }
        }
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/77e8b146-0078-4fb2-b002-e112381199f0",
  "name": "77e8b146-0078-4fb2-b002-e112381199f0"
}
Bylaw77e8b146-0078-4fb2-b002-e112381199f0.bylaw.ps1 · 27 lines
# Converted from SqlServer_VNetRules_Audit.json by ConvertTo-Bylaw.
Policy '77e8b146-0078-4fb2-b002-e112381199f0' {

    Properties @{
        DisplayName   = 'Virtual network firewall rule on Azure SQL Database should be enabled to allow traffic from the specified subnet'
        Description   = 'Virtual network based firewall rules are used to enable traffic from a specific subnet to Azure SQL Database while ensuring the traffic stays within the Azure boundary.'
        Version       = '1.0.0'
        Category      = 'SQL'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

    Parameter SubnetId @{
        Type        = 'string'
        DisplayName = 'Subnet ID'
        Description = 'The resource ID of the virtual network subnet that should have a rule enabled. Example: /subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default/providers/Microsoft.Network/virtualNetworks/testvnet/subnets/testsubnet'
        Metadata    = [ordered]@{ strongType = 'Microsoft.Network/virtualNetworks/subnets' }
    }

    Resource 'Microsoft.Sql/servers'

    AuditIfNotExists 'Microsoft.Sql/servers/virtualNetworkRules' {
        Require 'virtualNetworkSubnetId is the SubnetId parameter' {
            Field virtualNetworkSubnetId | Must -Be (Param SubnetId)
        }
    }
}

Source: built-in-policies/policyDefinitions/SQL/SqlServer_VNetRules_Audit.json in Azure/azure-policy, under the MIT licence.