Bylaw

Gallery › Compute › Azure Community Policy

Only allow images from certain image publishers to be deployed

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

This policy ensures that only certain image publisher offerings are usable from the image repository

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

Azure Policy JSONazurepolicy.json · 57 lines
{
  "name": "93998338-fca3-4e49-b605-e9eeed2bae79",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Only allow images from certain image publishers to be deployed",
    "description": "This policy ensures that only certain image publisher offerings are usable from the image repository",
    "metadata": {
      "version": "1.0.0",
      "category": "Compute"
    },
    "mode": "All",
    "parameters": {
      "listOfAllowedimagePublishers": {
        "type": "Array",
        "metadata": {
          "description": "The list of publishers to audit against. Example: 'MicrosoftWindowsServer'",
          "displayName": "Allowed image publishers"
        }
      },
      "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",
            "in": [
              "Microsoft.Compute/virtualMachines",
              "Microsoft.Compute/VirtualMachineScaleSets"
            ]
          },
          {
            "not": {
              "field": "Microsoft.Compute/imagePublisher",
              "in": "[parameters('listOfAllowedimagePublishers')]"
            }
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw93998338-fca3-4e49-b605-e9eeed2bae79.bylaw.ps1 · 36 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '93998338-fca3-4e49-b605-e9eeed2bae79' {

    Properties @{
        DisplayName = 'Only allow images from certain image publishers to be deployed'
        Description = 'This policy ensures that only certain image publisher offerings are usable from the image repository'
        Version     = '1.0.0'
        Category    = 'Compute'
        Mode        = 'All'
    }

    Parameter ListOfAllowedimagePublishers @{
        Type        = 'Array'
        DisplayName = 'Allowed image publishers'
        Description = 'The list of publishers to audit against. Example: ''MicrosoftWindowsServer'''
    }
    Parameter Effect @{
        AllowedValues = @('Deny', 'Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Deny, Audit or Disabled the execution of the Policy'
    }

    Resource * {

        When {
            Field type | Must -BeIn @('Microsoft.Compute/virtualMachines', 'Microsoft.Compute/VirtualMachineScaleSets')
        }

        Require 'imagePublisher is one of the ListOfAllowedimagePublishers parameter' {
            Field 'Microsoft.Compute/imagePublisher' | Must -BeIn (Param ListOfAllowedimagePublishers)
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Compute/only-allow-images-from-certain-image-publishers-to-be-deployed/azurepolicy.json in Azure/Community-Policy, under the MIT licence.