Bylaw

Gallery › Azure Arc › Azure built-in policies

Configure Azure Arc Private Link Scopes with private endpoints

Converted Policy DeployIfNotExists Disabled Mode Indexed Version 2.0.0

Private endpoints connect your virtual networks to Azure services without a public IP address at the source or destination. By mapping private endpoints to Azure Arc Private Link Scopes, you can reduce data leakage risks. Learn more about private links at: https://aka.ms/arc/privatelink.

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

Azure Policy JSONArc_PrivateEndpoint_DINE.json · 164 lines
{
  "properties": {
    "displayName": "Configure Azure Arc Private Link Scopes with private endpoints",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Private endpoints connect your virtual networks to Azure services without a public IP address at the source or destination. By mapping private endpoints to Azure Arc Private Link Scopes, you can reduce data leakage risks. Learn more about private links at: https://aka.ms/arc/privatelink.",
    "metadata": {
      "version": "2.0.0",
      "category": "Azure Arc"
    },
    "version": "2.0.0",
    "parameters": {
      "privateEndpointSubnetId": {
        "type": "String",
        "metadata": {
          "displayName": "Private endpoint subnet ID",
          "description": "A subnet with private endpoint network policies disabled.",
          "strongType": "Microsoft.Network/virtualNetworks/subnets"
        }
      },
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "DeployIfNotExists",
          "Disabled"
        ],
        "defaultValue": "DeployIfNotExists"
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "equals": "Microsoft.HybridCompute/privateLinkScopes"
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.HybridCompute/privateLinkScopes/privateEndpointConnections",
          "existenceCondition": {
            "field": "Microsoft.HybridCompute/privateLinkScopes/privateEndpointConnections/privateLinkServiceConnectionState.status",
            "equals": "Approved"
          },
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/4d97b98b-1d4f-4787-a291-c67834d212e7",
            "/providers/Microsoft.Authorization/roleDefinitions/cd570a14-e51a-42ad-bac8-bafd67325302",
            "/providers/Microsoft.Authorization/roleDefinitions/34e09817-6cbe-4d01-b1a2-e0eac5743d41"
          ],
          "deployment": {
            "properties": {
              "mode": "incremental",
              "parameters": {
                "name": {
                  "value": "[field('name')]"
                },
                "serviceId": {
                  "value": "[field('id')]"
                },
                "privateEndpointSubnetId": {
                  "value": "[parameters('privateEndpointSubnetId')]"
                }
              },
              "template": {
                "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {
                  "name": {
                    "type": "string"
                  },
                  "serviceId": {
                    "type": "string"
                  },
                  "privateEndpointSubnetId": {
                    "type": "string"
                  }
                },
                "variables": {
                  "privateEndpointName": "[concat('pe-',substring(parameters('name'),0,min(length(parameters('name')),50)),'-',uniquestring(deployment().name))]"
                },
                "resources": [
                  {
                    "type": "Microsoft.Resources/deployments",
                    "name": "[variables('privateEndpointName')]",
                    "apiVersion": "2020-06-01",
                    "properties": {
                      "mode": "Incremental",
                      "expressionEvaluationOptions": {
                        "scope": "inner"
                      },
                      "template": {
                        "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
                        "contentVersion": "1.0.0.0",
                        "parameters": {
                          "serviceId": {
                            "type": "string"
                          },
                          "privateEndpointSubnetId": {
                            "type": "string"
                          },
                          "subnetLocation": {
                            "type": "string"
                          }
                        },
                        "variables": {
                          "privateEndpointName": "[deployment().name]"
                        },
                        "resources": [
                          {
                            "name": "[variables('privateEndpointName')]",
                            "type": "Microsoft.Network/privateEndpoints",
                            "apiVersion": "2020-07-01",
                            "location": "[parameters('subnetLocation')]",
                            "tags": {},
                            "properties": {
                              "subnet": {
                                "id": "[parameters('privateEndpointSubnetId')]"
                              },
                              "privateLinkServiceConnections": [
                                {
                                  "name": "[variables('privateEndpointName')]",
                                  "properties": {
                                    "privateLinkServiceId": "[parameters('serviceId')]",
                                    "groupIds": [
                                      "hybridcompute"
                                    ],
                                    "requestMessage": "autoapprove"
                                  }
                                }
                              ],
                              "manualPrivateLinkServiceConnections": []
                            }
                          }
                        ]
                      },
                      "parameters": {
                        "serviceId": {
                          "value": "[parameters('serviceId')]"
                        },
                        "privateEndpointSubnetId": {
                          "value": "[parameters('privateEndpointSubnetId')]"
                        },
                        "subnetLocation": {
                          "value": "[reference(first(take(split(parameters('privateEndpointSubnetId'),'/subnets'),1)),'2020-07-01','Full').location]"
                        }
                      }
                    }
                  }
                ]
              }
            }
          }
        }
      }
    },
    "versions": [
      "2.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/d6eeba80-df61-4de5-8772-bc1b7852ba6b",
  "name": "d6eeba80-df61-4de5-8772-bc1b7852ba6b"
}
Bylawd6eeba80-df61-4de5-8772-bc1b7852ba6b.bylaw.ps1 · 38 lines
# Converted from Arc_PrivateEndpoint_DINE.json by ConvertTo-Bylaw.
Policy 'd6eeba80-df61-4de5-8772-bc1b7852ba6b' {

    Properties @{
        DisplayName   = 'Configure Azure Arc Private Link Scopes with private endpoints'
        Description   = 'Private endpoints connect your virtual networks to Azure services without a public IP address at the source or destination. By mapping private endpoints to Azure Arc Private Link Scopes, you can reduce data leakage risks. Learn more about private links at: https://aka.ms/arc/privatelink.'
        Version       = '2.0.0'
        Category      = 'Azure Arc'
        PolicyVersion = '2.0.0'
        Mode          = 'Indexed'
    }

    Parameter PrivateEndpointSubnetId @{
        Type        = 'String'
        DisplayName = 'Private endpoint subnet ID'
        Description = 'A subnet with private endpoint network policies disabled.'
        Metadata    = [ordered]@{ strongType = 'Microsoft.Network/virtualNetworks/subnets' }
    }
    Parameter Effect @{
        AllowedValues = @('DeployIfNotExists', 'Disabled')
        Default       = 'DeployIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource 'Microsoft.HybridCompute/privateLinkScopes'

    DeployIfNotExists 'Microsoft.HybridCompute/privateLinkScopes/privateEndpointConnections' -Role 'Network Contributor', 'Azure Connected Machine Resource Administrator', 'Kubernetes Cluster - Azure Arc Onboarding' -Effect (Param Effect) {
        Require 'privateLinkServiceConnectionState.status is Approved' {
            Field privateLinkServiceConnectionState.status | Must -Be 'Approved'
        }
        Deployment -TemplateFile './templates/d6eeba80-df61-4de5-8772-bc1b7852ba6b.json' -Parameters ([ordered]@{
                name                    = (Arm '[field(''name'')]')
                serviceId               = (Arm '[field(''id'')]')
                privateEndpointSubnetId = (Param PrivateEndpointSubnetId)
            })
    }
}

Its deployment templates are written beside it:

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