Bylaw

Gallery › Machine Learning › Azure Landing Zones Library

Deny AKS cluster creation in Azure Machine Learning

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0

Deny AKS cluster creation in Azure Machine Learning and enforce connecting to existing clusters.

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

Azure Policy JSONDeny-MachineLearning-Aks.alz_policy_definition.json · 62 lines
{
  "name": "Deny-MachineLearning-Aks",
  "properties": {
    "description": "Deny AKS cluster creation in Azure Machine Learning and enforce connecting to existing clusters.",
    "displayName": "Deny AKS cluster creation in Azure Machine Learning",
    "metadata": {
      "alzCloudEnvironments": [
        "AzureCloud"
      ],
      "category": "Machine Learning",
      "source": "https://github.com/Azure/Enterprise-Scale/",
      "version": "1.0.0"
    },
    "mode": "Indexed",
    "parameters": {
      "effect": {
        "allowedValues": [
          "Audit",
          "Disabled",
          "Deny"
        ],
        "defaultValue": "Deny",
        "metadata": {
          "description": "Enable or disable the execution of the policy",
          "displayName": "Effect"
        },
        "type": "String"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "equals": "Microsoft.MachineLearningServices/workspaces/computes",
            "field": "type"
          },
          {
            "equals": "AKS",
            "field": "Microsoft.MachineLearningServices/workspaces/computes/computeType"
          },
          {
            "anyOf": [
              {
                "exists": false,
                "field": "Microsoft.MachineLearningServices/workspaces/computes/resourceId"
              },
              {
                "equals": true,
                "value": "[empty(field('Microsoft.MachineLearningServices/workspaces/computes/resourceId'))]"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "policyType": "Custom"
  },
  "type": "Microsoft.Authorization/policyDefinitions"
}
BylawDeny-MachineLearning-Aks.bylaw.ps1 · 36 lines
# Converted from Deny-MachineLearning-Aks.alz_policy_definition.json by ConvertTo-Bylaw.
Policy 'Deny-MachineLearning-Aks' {

    Properties @{
        DisplayName = 'Deny AKS cluster creation in Azure Machine Learning'
        Description = 'Deny AKS cluster creation in Azure Machine Learning and enforce connecting to existing clusters.'
        Category    = 'Machine Learning'
        Version     = '1.0.0'
        Mode        = 'Indexed'
        Metadata    = [ordered]@{ alzCloudEnvironments = @('AzureCloud'); source = 'https://github.com/Azure/Enterprise-Scale/' }
    }

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

    Resource 'Microsoft.MachineLearningServices/workspaces/computes' {

        When {
            Field computeType | Must -Be 'AKS'
        }

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

        Require 'resourceId is as required' {
            Arm '[empty(field(''Microsoft.MachineLearningServices/workspaces/computes/resourceId''))]' | Must -Not -Be $true
        }
    }

    Effect (Param Effect)
}

Source: policy_definitions/Deny-MachineLearning-Aks.alz_policy_definition.json in Azure/Azure-Landing-Zones-Library, under the MIT licence.