Bylaw

Gallery › Monitoring › Azure built-in policies

Linux Arc-enabled machines should have Azure Monitor Agent installed

Converted Policy AuditIfNotExists Disabled Mode Indexed Version 1.2.0

Linux Arc-enabled machines should be monitored and secured through the deployed Azure Monitor Agent. The Azure Monitor Agent collects telemetry data from the guest OS. This policy will audit Arc-enabled machines in supported regions. Learn more: https://aka.ms/AMAOverview.

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

Azure Policy JSONAzureMonitor_Agent_Linux_HybridVM_Audit.json · 131 lines
{
  "properties": {
    "displayName": "Linux Arc-enabled machines should have Azure Monitor Agent installed",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Linux Arc-enabled machines should be monitored and secured through the deployed Azure Monitor Agent. The Azure Monitor Agent collects telemetry data from the guest OS. This policy will audit Arc-enabled machines in supported regions. Learn more: https://aka.ms/AMAOverview.",
    "metadata": {
      "version": "1.2.0",
      "category": "Monitoring"
    },
    "version": "1.2.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy."
        },
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "defaultValue": "AuditIfNotExists"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.HybridCompute/machines"
          },
          {
            "field": "Microsoft.HybridCompute/machines/osName",
            "equals": "linux"
          },
          {
            "field": "location",
            "in": [
              "australiacentral",
              "australiacentral2",
              "australiaeast",
              "australiasoutheast",
              "brazilsouth",
              "brazilsoutheast",
              "canadacentral",
              "canadaeast",
              "centralindia",
              "centralus",
              "centraluseuap",
              "eastasia",
              "eastus",
              "eastus2",
              "eastus2euap",
              "francecentral",
              "francesouth",
              "germanynorth",
              "germanywestcentral",
              "israelcentral",
              "italynorth",
              "japaneast",
              "japanwest",
              "jioindiacentral",
              "jioindiawest",
              "koreacentral",
              "koreasouth",
              "malaysiasouth",
              "mexicocentral",
              "northcentralus",
              "northeurope",
              "norwayeast",
              "norwaywest",
              "polandcentral",
              "qatarcentral",
              "southafricanorth",
              "southafricawest",
              "southcentralus",
              "southeastasia",
              "southindia",
              "spaincentral",
              "swedencentral",
              "swedensouth",
              "switzerlandnorth",
              "switzerlandwest",
              "taiwannorth",
              "taiwannorthwest",
              "uaecentral",
              "uaenorth",
              "uksouth",
              "ukwest",
              "westcentralus",
              "westeurope",
              "westindia",
              "westus",
              "westus2",
              "westus3"
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.HybridCompute/machines/extensions",
          "existenceCondition": {
            "allOf": [
              {
                "field": "Microsoft.HybridCompute/machines/extensions/type",
                "equals": "AzureMonitorLinuxAgent"
              },
              {
                "field": "Microsoft.HybridCompute/machines/extensions/publisher",
                "equals": "Microsoft.Azure.Monitor"
              },
              {
                "field": "Microsoft.HybridCompute/machines/extensions/provisioningState",
                "equals": "Succeeded"
              }
            ]
          }
        }
      }
    },
    "versions": [
      "1.2.0",
      "1.1.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/f17d891d-ff20-46f2-bad3-9e0a5403a4d3",
  "name": "f17d891d-ff20-46f2-bad3-9e0a5403a4d3"
}
Bylawf17d891d-ff20-46f2-bad3-9e0a5403a4d3.bylaw.ps1 · 38 lines
# Converted from AzureMonitor_Agent_Linux_HybridVM_Audit.json by ConvertTo-Bylaw.
Policy 'f17d891d-ff20-46f2-bad3-9e0a5403a4d3' {

    Properties @{
        DisplayName   = 'Linux Arc-enabled machines should have Azure Monitor Agent installed'
        Description   = 'Linux Arc-enabled machines should be monitored and secured through the deployed Azure Monitor Agent. The Azure Monitor Agent collects telemetry data from the guest OS. This policy will audit Arc-enabled machines in supported regions. Learn more: https://aka.ms/AMAOverview.'
        Version       = '1.2.0'
        Category      = 'Monitoring'
        PolicyVersion = '1.2.0'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.HybridCompute/machines' {

        When {
            Field osName | Must -Be 'linux'
        }

        Require 'location is not one of 57 values' {
            Field location | Must -Not -BeIn @('australiacentral', 'australiacentral2', 'australiaeast', 'australiasoutheast', 'brazilsouth', 'brazilsoutheast', 'canadacentral', 'canadaeast', 'centralindia', 'centralus', 'centraluseuap', 'eastasia', 'eastus', 'eastus2', 'eastus2euap', 'francecentral', 'francesouth', 'germanynorth', 'germanywestcentral', 'israelcentral', 'italynorth', 'japaneast', 'japanwest', 'jioindiacentral', 'jioindiawest', 'koreacentral', 'koreasouth', 'malaysiasouth', 'mexicocentral', 'northcentralus', 'northeurope', 'norwayeast', 'norwaywest', 'polandcentral', 'qatarcentral', 'southafricanorth', 'southafricawest', 'southcentralus', 'southeastasia', 'southindia', 'spaincentral', 'swedencentral', 'swedensouth', 'switzerlandnorth', 'switzerlandwest', 'taiwannorth', 'taiwannorthwest', 'uaecentral', 'uaenorth', 'uksouth', 'ukwest', 'westcentralus', 'westeurope', 'westindia', 'westus', 'westus2', 'westus3') -IfPresent
        }
    }

    AuditIfNotExists 'Microsoft.HybridCompute/machines/extensions' -Effect (Param Effect) {
        Require 'type, publisher and provisioningState are as required' {
            Field 'Microsoft.HybridCompute/machines/extensions/type' | Must -Be 'AzureMonitorLinuxAgent'
            Field publisher | Must -Be 'Microsoft.Azure.Monitor'
            Field provisioningState | Must -Be 'Succeeded'
        }
    }
}

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