Bylaw

Gallery › Compute › Azure Community Policy

Not allowed VM Extensions

Converted Policy Audit Deny Disabled Mode All Version 2.0.0

This policy governs which VM extensions that are explicitly denied.

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

Azure Policy JSONazurepolicy.json · 64 lines
{
  "name": "24a44bf6-3651-44f4-bb82-68c80e1c9a48",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Not allowed VM Extensions",
    "description": "This policy governs which VM extensions that are explicitly denied.",
    "metadata": {
      "version": "2.0.0",
      "category": "Compute"
    },
    "mode": "All",
    "parameters": {
      "notAllowedExtensions": {
        "type": "Array",
        "metadata": {
          "displayName": "Denied extension",
          "description": "The list of extensions that will be denied."
        }
      },
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Deny, Audit or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Deny",
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Compute/virtualMachines/extensions"
          },
          {
            "field": "Microsoft.Compute/virtualMachines/extensions/type",
            "in": "[parameters('notAllowedExtensions')]"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.Compute/virtualMachines/extensions/publisher",
                "equals": "Microsoft.Azure.AzureDefenderForServers"
              },
              {
                "field": "Microsoft.Compute/virtualMachines/extensions/publisher",
                "equals": "Microsoft.Compute"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw24a44bf6-3651-44f4-bb82-68c80e1c9a48.bylaw.ps1 · 40 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '24a44bf6-3651-44f4-bb82-68c80e1c9a48' {

    Properties @{
        DisplayName = 'Not allowed VM Extensions'
        Description = 'This policy governs which VM extensions that are explicitly denied.'
        Version     = '2.0.0'
        Category    = 'Compute'
        Mode        = 'All'
    }

    Parameter NotAllowedExtensions @{
        Type        = 'Array'
        DisplayName = 'Denied extension'
        Description = 'The list of extensions that will be denied.'
    }
    Parameter Effect @{
        AllowedValues = @('Deny', 'Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Deny, Audit or Disabled the execution of the Policy'
    }

    Resource 'Microsoft.Compute/virtualMachines/extensions' {

        When {
            Field 'Microsoft.Compute/virtualMachines/extensions/type' | Must -BeIn (Param NotAllowedExtensions)
        }

        Require 'publisher is not Microsoft.Azure.AzureDefenderForServers' {
            Field publisher | Must -Not -Be 'Microsoft.Azure.AzureDefenderForServers' -IfPresent
        }

        Require 'publisher is not Microsoft.Compute' {
            Field publisher | Must -Not -Be 'Microsoft.Compute' -IfPresent
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Compute/not-allowed-vm-extensions/azurepolicy.json in Azure/Community-Policy, under the MIT licence.