Bylaw

Gallery › API Management › Azure built-in policies

API Management subscriptions should not be scoped to all APIs

Converted Policy Audit Deny Disabled Mode All Version 1.1.0

API Management subscriptions should be scoped to a product or an individual API instead of all APIs, which could result in an excessive data exposure.

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

Azure Policy JSONAllApiSubscription_AuditDeny.json · 54 lines
{
  "properties": {
    "displayName": "API Management subscriptions should not be scoped to all APIs",
    "policyType": "BuiltIn",
    "mode": "All",
    "description": "API Management subscriptions should be scoped to a product or an individual API instead of all APIs, which could result in an excessive data exposure.",
    "metadata": {
      "version": "1.1.0",
      "category": "API Management"
    },
    "version": "1.1.0",
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.ApiManagement/service/subscriptions"
          },
          {
            "field": "Microsoft.ApiManagement/service/subscriptions/scope",
            "like": "*/apis"
          },
          {
            "field": "Microsoft.ApiManagement/service/subscriptions/state",
            "equals": "active"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "parameters": {
      "effect": {
        "type": "string",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Audit",
          "Disabled",
          "Deny"
        ],
        "defaultValue": "Audit"
      }
    },
    "versions": [
      "1.1.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/3aa03346-d8c5-4994-a5bc-7652c2a2aef1",
  "name": "3aa03346-d8c5-4994-a5bc-7652c2a2aef1"
}
Bylaw3aa03346-d8c5-4994-a5bc-7652c2a2aef1.bylaw.ps1 · 33 lines
# Converted from AllApiSubscription_AuditDeny.json by ConvertTo-Bylaw.
Policy '3aa03346-d8c5-4994-a5bc-7652c2a2aef1' {

    Properties @{
        DisplayName   = 'API Management subscriptions should not be scoped to all APIs'
        Description   = 'API Management subscriptions should be scoped to a product or an individual API instead of all APIs, which could result in an excessive data exposure.'
        Version       = '1.1.0'
        Category      = 'API Management'
        PolicyVersion = '1.1.0'
        Mode          = 'All'
    }

    Parameter Effect @{
        Type          = 'string'
        AllowedValues = @('Audit', 'Disabled', 'Deny')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource 'Microsoft.ApiManagement/service/subscriptions' {

        When {
            Field scope | Must -BeLike '*/apis'
        }

        Require 'state is not active' {
            Field state | Must -Not -Be 'active' -IfPresent
        }
    }

    Effect (Param Effect)
}

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