Bylaw

Gallery › API Management › Azure built-in policies

API Management services should use a virtual network

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.2

Azure Virtual Network deployment provides enhanced security, isolation and allows you to place your API Management service in a non-internet routable network that you control access to. These networks can then be connected to your on-premises networks using various VPN technologies, which enables access to your backend services within the network and/or on-premises. The developer portal and API gateway, can be configured to be accessible either from the Internet or only within the virtual network.

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

Azure Policy JSONVNETEnabled_Audit.json · 80 lines
{
  "properties": {
    "displayName": "API Management services should use a virtual network",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Azure Virtual Network deployment provides enhanced security, isolation and allows you to place your API Management service in a non-internet routable network that you control access to. These networks can then be connected to your on-premises networks using various VPN technologies, which enables access to your backend services within the network and/or on-premises. The developer portal and API gateway, can be configured to be accessible either from the Internet or only within the virtual network.",
    "metadata": {
      "version": "1.0.2",
      "category": "API Management"
    },
    "version": "1.0.2",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "defaultValue": "Audit"
      },
      "evaluatedSkuNames": {
        "type": "Array",
        "metadata": {
          "displayName": "API Management SKU Names",
          "description": "List of API Management SKUs against which this policy will be evaluated."
        },
        "allowedValues": [
          "Developer",
          "Basic",
          "Standard",
          "Premium",
          "Consumption"
        ],
        "defaultValue": [
          "Developer",
          "Premium"
        ]
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.ApiManagement/service"
          },
          {
            "field": "Microsoft.ApiManagement/service/sku.name",
            "in": "[parameters('evaluatedSkuNames')]"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.ApiManagement/service/virtualNetworkType",
                "exists": "false"
              },
              {
                "field": "Microsoft.ApiManagement/service/virtualNetworkType",
                "equals": "None"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.2"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/ef619a2c-cc4d-4d03-b2ba-8c94a834d85b",
  "name": "ef619a2c-cc4d-4d03-b2ba-8c94a834d85b"
}
Bylawef619a2c-cc4d-4d03-b2ba-8c94a834d85b.bylaw.ps1 · 43 lines
# Converted from VNETEnabled_Audit.json by ConvertTo-Bylaw.
Policy 'ef619a2c-cc4d-4d03-b2ba-8c94a834d85b' {

    Properties @{
        DisplayName   = 'API Management services should use a virtual network'
        Description   = 'Azure Virtual Network deployment provides enhanced security, isolation and allows you to place your API Management service in a non-internet routable network that you control access to. These networks can then be connected to your on-premises networks using various VPN technologies, which enables access to your backend services within the network and/or on-premises. The developer portal and API gateway, can be configured to be accessible either from the Internet or only within the virtual network.'
        Version       = '1.0.2'
        Category      = 'API Management'
        PolicyVersion = '1.0.2'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Deny', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }
    Parameter EvaluatedSkuNames @{
        Type          = 'Array'
        AllowedValues = @('Developer', 'Basic', 'Standard', 'Premium', 'Consumption')
        Default       = @('Developer', 'Premium')
        DisplayName   = 'API Management SKU Names'
        Description   = 'List of API Management SKUs against which this policy will be evaluated.'
    }

    Resource 'Microsoft.ApiManagement/service' {

        When {
            Field sku.name | Must -BeIn (Param EvaluatedSkuNames)
        }

        Require 'virtualNetworkType exists' {
            Field virtualNetworkType | Must -Exist
        }

        Require 'virtualNetworkType is not None' {
            Field virtualNetworkType | Must -Not -Be 'None' -IfPresent
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/API Management/VNETEnabled_Audit.json in Azure/azure-policy, under the MIT licence.