Bylaw

Gallery › API Management › Azure built-in policies

API Management should disable public network access to the service configuration endpoints

Converted Policy AuditIfNotExists Disabled Mode Indexed Version 1.0.1

To improve the security of API Management services, restrict connectivity to service configuration endpoints, like direct access management API, Git configuration management endpoint, or self-hosted gateways configuration endpoint.

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

Azure Policy JSONPublicEndpoint_AINE.json · 71 lines
{
  "properties": {
    "displayName": "API Management should disable public network access to the service configuration endpoints",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "To improve the security of API Management services, restrict connectivity to service configuration endpoints, like direct access management API, Git configuration management endpoint, or self-hosted gateways configuration endpoint.",
    "metadata": {
      "version": "1.0.1",
      "category": "API Management"
    },
    "version": "1.0.1",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "defaultValue": "AuditIfNotExists"
      },
      "endpointType": {
        "type": "String",
        "metadata": {
          "displayName": "Public Endpoint Type",
          "description": "Public Endpoint Type for which to enforce the access check"
        },
        "allowedValues": [
          "Management",
          "Git",
          "Gateway Configuration"
        ],
        "defaultValue": "Management"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.ApiManagement/service"
          },
          {
            "field": "Microsoft.ApiManagement/service/sku.name",
            "notEquals": "Consumption"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.ApiManagement/service/tenant",
          "name": "[if(equals(parameters('endpointType'), 'Management'), 'access', if(equals(parameters('endpointType'), 'Git'), 'gitaccess', 'gatewayaccess'))]",
          "evaluationDelay": "AfterProvisioningSuccess",
          "existenceCondition": {
            "field": "Microsoft.ApiManagement/service/tenant/enabled",
            "equals": false
          }
        }
      }
    },
    "versions": [
      "1.0.1"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/df73bd95-24da-4a4f-96b9-4e8b94b402bd",
  "name": "df73bd95-24da-4a4f-96b9-4e8b94b402bd"
}
Bylawdf73bd95-24da-4a4f-96b9-4e8b94b402bd.bylaw.ps1 · 38 lines
# Converted from PublicEndpoint_AINE.json by ConvertTo-Bylaw.
Policy 'df73bd95-24da-4a4f-96b9-4e8b94b402bd' {

    Properties @{
        DisplayName   = 'API Management should disable public network access to the service configuration endpoints'
        Description   = 'To improve the security of API Management services, restrict connectivity to service configuration endpoints, like direct access management API, Git configuration management endpoint, or self-hosted gateways configuration endpoint.'
        Version       = '1.0.1'
        Category      = 'API Management'
        PolicyVersion = '1.0.1'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('AuditIfNotExists', 'Disabled')
        Default       = 'AuditIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }
    Parameter EndpointType @{
        AllowedValues = @('Management', 'Git', 'Gateway Configuration')
        Default       = 'Management'
        DisplayName   = 'Public Endpoint Type'
        Description   = 'Public Endpoint Type for which to enforce the access check'
    }

    Resource 'Microsoft.ApiManagement/service' {

        Require 'sku.name is Consumption' {
            Field sku.name | Must -Be 'Consumption'
        }
    }

    AuditIfNotExists 'Microsoft.ApiManagement/service/tenant' -Name (Arm '[if(equals(parameters(''endpointType''), ''Management''), ''access'', if(equals(parameters(''endpointType''), ''Git''), ''gitaccess'', ''gatewayaccess''))]') -EvaluationDelay AfterProvisioningSuccess -Effect (Param Effect) {
        Require 'enabled is false' {
            Field enabled | Must -Be $false
        }
    }
}

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