Bylaw

Gallery › Machine Learning › Azure built-in policies

Azure Machine Learning Computes should be in a virtual network

Converted Policy Audit Disabled Mode All Version 1.0.1

Azure Virtual Networks provide enhanced security and isolation for your Azure Machine Learning Compute Clusters and Instances, as well as subnets, access control policies, and other features to further restrict access. When a compute is configured with a virtual network, it is not publicly addressable and can only be accessed from virtual machines and applications within the virtual network.

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

Azure Policy JSONVnet_Audit.json · 64 lines
{
  "properties": {
    "displayName": "Azure Machine Learning Computes should be in a virtual network",
    "policyType": "BuiltIn",
    "mode": "All",
    "description": "Azure Virtual Networks provide enhanced security and isolation for your Azure Machine Learning Compute Clusters and Instances, as well as subnets, access control policies, and other features to further restrict access. When a compute is configured with a virtual network, it is not publicly addressable and can only be accessed from virtual machines and applications within the virtual network.",
    "metadata": {
      "version": "1.0.1",
      "category": "Machine Learning"
    },
    "version": "1.0.1",
    "parameters": {
      "effect": {
        "type": "String",
        "defaultValue": "Audit",
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "The effect determines what happens when the policy rule is evaluated to match."
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.MachineLearningServices/workspaces/computes"
          },
          {
            "field": "Microsoft.MachineLearningServices/workspaces/computes/computeType",
            "in": [
              "AmlCompute",
              "ComputeInstance"
            ]
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.MachineLearningServices/workspaces/computes/subnet.id",
                "exists": false
              },
              {
                "value": "[empty(field('Microsoft.MachineLearningServices/workspaces/computes/subnet.id'))]",
                "equals": true
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.1"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/7804b5c7-01dc-4723-969b-ae300cc07ff1",
  "name": "7804b5c7-01dc-4723-969b-ae300cc07ff1"
}
Bylaw7804b5c7-01dc-4723-969b-ae300cc07ff1.bylaw.ps1 · 36 lines
# Converted from Vnet_Audit.json by ConvertTo-Bylaw.
Policy '7804b5c7-01dc-4723-969b-ae300cc07ff1' {

    Properties @{
        DisplayName   = 'Azure Machine Learning Computes should be in a virtual network'
        Description   = 'Azure Virtual Networks provide enhanced security and isolation for your Azure Machine Learning Compute Clusters and Instances, as well as subnets, access control policies, and other features to further restrict access. When a compute is configured with a virtual network, it is not publicly addressable and can only be accessed from virtual machines and applications within the virtual network.'
        Version       = '1.0.1'
        Category      = 'Machine Learning'
        PolicyVersion = '1.0.1'
        Mode          = 'All'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'The effect determines what happens when the policy rule is evaluated to match.'
    }

    Resource 'Microsoft.MachineLearningServices/workspaces/computes' {

        When {
            Field computeType | Must -BeIn @('AmlCompute', 'ComputeInstance')
        }

        Require 'subnet.id exists' {
            Field subnet.id | Must -Exist
        }

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

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/Machine Learning/Vnet_Audit.json in Azure/azure-policy, under the MIT licence.