Bylaw

Gallery › Desktop Virtualization › Azure built-in policies

Configure Azure Virtual Desktop hostpools to disable public network access only for session hosts

Converted Policy Disabled Modify Mode Indexed Version 1.0.0

Disable public network access for your Azure Virtual Desktop hostpool session hosts, but allow public access for end users. This allows users to still access AVD service while ensuring the session host is only accessible through private routes. Learn more at: https://aka.ms/avdprivatelink.

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

Azure Policy JSONDVHostpool_PrivateNetworkPublicClient_Modify.json · 63 lines
{
  "properties": {
    "displayName": "Configure Azure Virtual Desktop hostpools to disable public network access only for session hosts",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Disable public network access for your Azure Virtual Desktop hostpool session hosts, but allow public access for end users. This allows users to still access AVD service while ensuring the session host is only accessible through private routes. Learn more at: https://aka.ms/avdprivatelink.",
    "metadata": {
      "version": "1.0.0",
      "category": "Desktop Virtualization"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Modify",
          "Disabled"
        ],
        "defaultValue": "Modify"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.DesktopVirtualization/hostpools"
          },
          {
            "field": "Microsoft.DesktopVirtualization/hostPools/publicNetworkAccess",
            "notEquals": "EnabledForClientsOnly"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/e307426c-f9b6-4e81-87de-d99efb3c32bc"
          ],
          "conflictEffect": "audit",
          "operations": [
            {
              "condition": "[greaterOrEquals(requestContext().apiVersion, '2022-04-01-preview')]",
              "operation": "addOrReplace",
              "field": "Microsoft.DesktopVirtualization/hostPools/publicNetworkAccess",
              "value": "EnabledForClientsOnly"
            }
          ]
        }
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/e84e8a9a-f43e-46e3-9458-bbcfb2d7e429",
  "name": "e84e8a9a-f43e-46e3-9458-bbcfb2d7e429"
}
Bylawe84e8a9a-f43e-46e3-9458-bbcfb2d7e429.bylaw.ps1 · 30 lines
# Converted from DVHostpool_PrivateNetworkPublicClient_Modify.json by ConvertTo-Bylaw.
Policy 'e84e8a9a-f43e-46e3-9458-bbcfb2d7e429' {

    Properties @{
        DisplayName   = 'Configure Azure Virtual Desktop hostpools to disable public network access only for session hosts'
        Description   = 'Disable public network access for your Azure Virtual Desktop hostpool session hosts, but allow public access for end users. This allows users to still access AVD service while ensuring the session host is only accessible through private routes. Learn more at: https://aka.ms/avdprivatelink.'
        Version       = '1.0.0'
        Category      = 'Desktop Virtualization'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.DesktopVirtualization/hostpools' {

        Require 'publicNetworkAccess is EnabledForClientsOnly' {
            Field publicNetworkAccess | Must -Be 'EnabledForClientsOnly'
        }
    }

    Modify -Role 'Desktop Virtualization Host Pool Contributor' -ConflictEffect Audit -Effect (Param Effect) {
        Field publicNetworkAccess | AddOrReplace 'EnabledForClientsOnly' -Condition (Arm '[greaterOrEquals(requestContext().apiVersion, ''2022-04-01-preview'')]')
    }
}

Source: built-in-policies/policyDefinitions/Desktop Virtualization/DVHostpool_PrivateNetworkPublicClient_Modify.json in Azure/azure-policy, under the MIT licence.