Bylaw

Gallery › Automanage › Azure built-in policies

[Preview]: A managed identity should be enabled on your machines

Converted Policy Audit Disabled Mode Indexed Version 1.0.0-preview Preview

Resources managed by Automanage should have a managed identity.

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

Azure Policy JSONIdentity_Audit.json · 57 lines
{
  "properties": {
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "displayName": "[Preview]: A managed identity should be enabled on your machines",
    "description": "Resources managed by Automanage should have a managed identity.",
    "metadata": {
      "version": "1.0.0-preview",
      "category": "Automanage",
      "preview": true
    },
    "version": "1.0.0-preview",
    "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",
            "in": [
              "Microsoft.Compute/virtualMachines",
              "Microsoft.HybridCompute/machines"
            ]
          },
          {
            "field": "identity.type",
            "notContains": "SystemAssigned"
          },
          {
            "field": "identity.type",
            "notContains": "UserAssigned"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0-PREVIEW"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/e4953962-5ae4-43eb-bb92-d66fd5563487",
  "name": "e4953962-5ae4-43eb-bb92-d66fd5563487"
}
Bylawe4953962-5ae4-43eb-bb92-d66fd5563487.bylaw.ps1 · 34 lines
# Converted from Identity_Audit.json by ConvertTo-Bylaw.
Policy 'e4953962-5ae4-43eb-bb92-d66fd5563487' {

    Properties @{
        DisplayName   = '[Preview]: A managed identity should be enabled on your machines'
        Description   = 'Resources managed by Automanage should have a managed identity.'
        Version       = '1.0.0-preview'
        Category      = 'Automanage'
        Preview       = $true
        PolicyVersion = '1.0.0-preview'
        Mode          = 'Indexed'
    }

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

    Resource * {

        When {
            Field type | Must -BeIn @('Microsoft.Compute/virtualMachines', 'Microsoft.HybridCompute/machines')
            Field identity.type | Must -Not -ContainText 'SystemAssigned'
        }

        Require 'identity.type contains UserAssigned' {
            Field identity.type | Must -ContainText 'UserAssigned'
        }
    }

    Effect (Param Effect)
}

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