Bylaw

Gallery › Mission › Azure built-in policies

Azure SQL servers in this tenant should deny private endpoints in external subscriptions

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

This policy applies exclusively to Mission Platform products and services; usage outside of these scopes is not supported. It blocks approval of SQL private endpoint connections from subscriptions outside the mission tenant to preserve enclave boundaries and prevent data exfiltration (see https://learn.microsoft.com/azure/private-link/private-link-overview).

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

Azure Policy JSONsqlDenyExternalPrivateEndPointsToSQLServers.json · 78 lines
{
  "properties": {
    "displayName": "Azure SQL servers in this tenant should deny private endpoints in external subscriptions",
    "policyType": "BuiltIn",
    "mode": "All",
    "description": "This policy applies exclusively to Mission Platform products and services; usage outside of these scopes is not supported. It blocks approval of SQL private endpoint connections from subscriptions outside the mission tenant to preserve enclave boundaries and prevent data exfiltration (see https://learn.microsoft.com/azure/private-link/private-link-overview).",
    "metadata": {
      "version": "1.0.0",
      "category": "Mission"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "defaultValue": "Audit"
      },
      "excludedSubIDs": {
        "type": "Array",
        "metadata": {
          "displayName": "Excluded Subscription IDs",
          "description": "List or array of the excluded subscription IDs"
        },
        "defaultValue": []
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.SQL/servers/privateEndpointConnections"
          },
          {
            "field": "Microsoft.SQL/servers/privateEndpointConnections/privateLinkServiceConnectionState.status",
            "equals": "Approved"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.SQL/servers/privateEndpointConnections/privateEndpoint.id",
                "exists": false
              },
              {
                "allOf": [
                  {
                    "value": "[split(concat(field('Microsoft.SQL/servers/privateEndpointConnections/privateEndpoint.id'), '//'), '/')[2]]",
                    "notEquals": "[subscription().subscriptionId]"
                  },
                  {
                    "value": "[split(concat(field('Microsoft.SQL/servers/privateEndpointConnections/privateEndpoint.id'), '//'), '/')[2]]",
                    "notIn": "[parameters('excludedSubIDs')]"
                  }
                ]
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/b9ea0c2d-5c16-4d86-8e09-af82a239a0a4",
  "name": "b9ea0c2d-5c16-4d86-8e09-af82a239a0a4"
}
Bylawb9ea0c2d-5c16-4d86-8e09-af82a239a0a4.bylaw.ps1 · 45 lines
# Converted from sqlDenyExternalPrivateEndPointsToSQLServers.json by ConvertTo-Bylaw.
Policy 'b9ea0c2d-5c16-4d86-8e09-af82a239a0a4' {

    Properties @{
        DisplayName   = 'Azure SQL servers in this tenant should deny private endpoints in external subscriptions'
        Description   = 'This policy applies exclusively to Mission Platform products and services; usage outside of these scopes is not supported. It blocks approval of SQL private endpoint connections from subscriptions outside the mission tenant to preserve enclave boundaries and prevent data exfiltration (see https://learn.microsoft.com/azure/private-link/private-link-overview).'
        Version       = '1.0.0'
        Category      = 'Mission'
        PolicyVersion = '1.0.0'
        Mode          = 'All'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Deny', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }
    Parameter ExcludedSubIDs @{
        Type        = 'Array'
        Default     = @()
        DisplayName = 'Excluded Subscription IDs'
        Description = 'List or array of the excluded subscription IDs'
    }

    Resource 'Microsoft.SQL/servers/privateEndpointConnections' {

        When {
            Field privateLinkServiceConnectionState.status | Must -Be 'Approved'
        }

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

        Require 'privateEndpoint.id is as required' {
            AnyOf {
                Arm '[split(concat(field(''Microsoft.SQL/servers/privateEndpointConnections/privateEndpoint.id''), ''//''), ''/'')[2]]' | Must -Be (Arm '[subscription().subscriptionId]')
                Arm '[split(concat(field(''Microsoft.SQL/servers/privateEndpointConnections/privateEndpoint.id''), ''//''), ''/'')[2]]' | Must -BeIn (Param ExcludedSubIDs)
            }
        }
    }

    Effect (Param Effect)
}

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