Bylaw

Gallery › VirtualEnclaves › Azure built-in policies

Do not allow creation of resource types outside of the allowlist

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0

This policy prevents deployment of resource types outside of the explicitly allowed types, in order to maintain security in a virtual enclave. https://aka.ms/VirtualEnclaves

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

Azure Policy JSONAllowedResourceTypesAndProviders_Deny.json · 80 lines
{
  "properties": {
    "displayName": "Do not allow creation of resource types outside of the allowlist",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "This policy prevents deployment of resource types outside of the explicitly allowed types, in order to maintain security in a virtual enclave. https://aka.ms/VirtualEnclaves",
    "metadata": {
      "version": "1.0.0",
      "category": "VirtualEnclaves"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "String",
        "defaultValue": "Deny",
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "The effect determines what happens when the policy rule is evaluated to match"
        }
      },
      "allowedResourceProviders": {
        "metadata": {
          "description": "List of allowed resource providers or parent resource types as strings, such as microsoft.storage or microsoft.servicebus",
          "displayName": "Allowed resource providers"
        },
        "defaultValue": [],
        "type": "Array"
      },
      "allowedResourceTypes": {
        "metadata": {
          "description": "List of allowed resource types as strings, such as microsoft.storage/storageaccounts",
          "displayName": "Allowed resource types"
        },
        "defaultValue": [],
        "type": "Array"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "count": {
              "value": "[parameters('allowedResourceTypes')]",
              "name": "resourceType",
              "where": {
                "field": "type",
                "equals": "[current('resourceType')]"
              }
            },
            "equals": 0
          },
          {
            "count": {
              "value": "[parameters('allowedResourceProviders')]",
              "name": "resourceProvider",
              "where": {
                "field": "type",
                "like": "[concat(current('resourceProvider'), '/*')]"
              }
            },
            "equals": 0
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/ead33d15-8ff9-44d8-be85-24144ecc859e",
  "name": "ead33d15-8ff9-44d8-be85-24144ecc859e"
}
Bylawead33d15-8ff9-44d8-be85-24144ecc859e.bylaw.ps1 · 48 lines
# Converted from AllowedResourceTypesAndProviders_Deny.json by ConvertTo-Bylaw.
Policy 'ead33d15-8ff9-44d8-be85-24144ecc859e' {

    Properties @{
        DisplayName   = 'Do not allow creation of resource types outside of the allowlist'
        Description   = 'This policy prevents deployment of resource types outside of the explicitly allowed types, in order to maintain security in a virtual enclave. https://aka.ms/VirtualEnclaves'
        Version       = '1.0.0'
        Category      = 'VirtualEnclaves'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Deny', 'Disabled')
        Default       = 'Deny'
        DisplayName   = 'Effect'
        Description   = 'The effect determines what happens when the policy rule is evaluated to match'
    }
    Parameter AllowedResourceProviders @{
        Type        = 'Array'
        Default     = @()
        DisplayName = 'Allowed resource providers'
        Description = 'List of allowed resource providers or parent resource types as strings, such as microsoft.storage or microsoft.servicebus'
    }
    Parameter AllowedResourceTypes @{
        Type        = 'Array'
        Default     = @()
        DisplayName = 'Allowed resource types'
        Description = 'List of allowed resource types as strings, such as microsoft.storage/storageaccounts'
    }

    Resource * {

        When {
            Count -Value (Param AllowedResourceTypes) -Name resourceType -Where {
                Field type | Must -Be (Current resourceType)
            } | Must -Be 0
        }

        Require 'type is as required' {
            Count -Value (Param AllowedResourceProviders) -Name resourceProvider -Where {
                Field type | Must -BeLike (Arm '[concat(current(''resourceProvider''), ''/*'')]')
            } | Must -Not -Be 0
        }
    }

    Effect (Param Effect)
}

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