Bylaw

Gallery › Trusted Launch › Azure built-in policies

Virtual Machine should have TrustedLaunch enabled

Converted Policy Audit Disabled Mode Indexed Version 1.0.0

Enable TrustedLaunch on Virtual Machine for enhanced security, use VM SKU (Gen 2) that supports TrustedLaunch. To learn more about TrustedLaunch, visit https://learn.microsoft.com/en-us/azure/virtual-machines/trusted-launch

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

Azure Policy JSONVirtualMachine_Should_Have_TrustedLaunch enabled.json · 65 lines
{
  "properties": {
    "displayName": "Virtual Machine should have TrustedLaunch enabled",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Enable TrustedLaunch on Virtual Machine for enhanced security, use VM SKU (Gen 2) that supports TrustedLaunch. To learn more about TrustedLaunch, visit https://learn.microsoft.com/en-us/azure/virtual-machines/trusted-launch",
    "metadata": {
      "version": "1.0.0",
      "category": "Trusted Launch"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Compute/virtualMachines"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.Compute/virtualMachines/securityProfile",
                "exists": "false"
              },
              {
                "field": "Microsoft.Compute/virtualMachines/securityProfile.securityType",
                "notEquals": "TrustedLaunch"
              },
              {
                "field": "Microsoft.Compute/virtualMachines/securityProfile.uefiSettings.secureBootEnabled",
                "notEquals": "true"
              },
              {
                "field": "Microsoft.Compute/virtualMachines/securityProfile.uefiSettings.vTpmEnabled",
                "notEquals": "true"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/c95b54ad-0614-4633-ab29-104b01235cbf",
  "name": "c95b54ad-0614-4633-ab29-104b01235cbf"
}
Bylawc95b54ad-0614-4633-ab29-104b01235cbf.bylaw.ps1 · 40 lines
# Converted from VirtualMachine_Should_Have_TrustedLaunch enabled.json by ConvertTo-Bylaw.
Policy 'c95b54ad-0614-4633-ab29-104b01235cbf' {

    Properties @{
        DisplayName   = 'Virtual Machine should have TrustedLaunch enabled'
        Description   = 'Enable TrustedLaunch on Virtual Machine for enhanced security, use VM SKU (Gen 2) that supports TrustedLaunch. To learn more about TrustedLaunch, visit https://learn.microsoft.com/en-us/azure/virtual-machines/trusted-launch'
        Version       = '1.0.0'
        Category      = 'Trusted Launch'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.Compute/virtualMachines' {

        Require 'securityProfile exists' {
            Field securityProfile | Must -Exist
        }

        Require 'securityProfile.securityType is TrustedLaunch' {
            Field securityProfile.securityType | Must -Be 'TrustedLaunch'
        }

        Require 'securityProfile.uefiSettings.secureBootEnabled is true' {
            Field securityProfile.uefiSettings.secureBootEnabled | Must -Be 'true'
        }

        Require 'securityProfile.uefiSettings.vTpmEnabled is true' {
            Field securityProfile.uefiSettings.vTpmEnabled | Must -Be 'true'
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/Trusted Launch/VirtualMachine_Should_Have_TrustedLaunch enabled.json in Azure/azure-policy, under the MIT licence.