Bylaw

Gallery › Network › Azure Community Policy

Prevent cross tenant Private Link for eventgrid topics

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

This policy prevents private link between tenants for eventgrid topics.

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

Azure Policy JSONazurepolicy.json · 56 lines
{
  "name": "01842530-3cf6-4804-a38b-33cc50ed8c9e",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Prevent cross tenant Private Link for eventgrid topics",
    "description": "This policy prevents private link between tenants for eventgrid topics.",
    "metadata": {
      "category": "Network",
      "createdBy": "",
      "updatedBy": null,
      "updatedOn": null,
      "version": "1.0.0"
    },
    "mode": "All",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Deny, Audit or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Deny",
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "equals": "Microsoft.EventGrid/topics/privateEndpointConnections",
            "field": "type"
          },
          {
            "anyOf": [
              {
                "exists": false,
                "field": "Microsoft.EventGrid/topics/privateEndpointConnections/privateEndpoint.id"
              },
              {
                "notEquals": "[subscription().subscriptionId]",
                "value": "[split(concat(field('Microsoft.EventGrid/topics/privateEndpointConnections/privateEndpoint.id'), '//'), '/')[2]]"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw01842530-3cf6-4804-a38b-33cc50ed8c9e.bylaw.ps1 · 31 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '01842530-3cf6-4804-a38b-33cc50ed8c9e' {

    Properties @{
        DisplayName = 'Prevent cross tenant Private Link for eventgrid topics'
        Description = 'This policy prevents private link between tenants for eventgrid topics.'
        Category    = 'Network'
        Version     = '1.0.0'
        Mode        = 'All'
    }

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

    Resource 'Microsoft.EventGrid/topics/privateEndpointConnections' {

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

        Require 'privateEndpoint.id is as required' {
            Arm '[split(concat(field(''Microsoft.EventGrid/topics/privateEndpointConnections/privateEndpoint.id''), ''//''), ''/'')[2]]' | Must -Be (Arm '[subscription().subscriptionId]')
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Network/prevent-cross-tenant-private-link-for-eventgrid-topics/azurepolicy.json in Azure/Community-Policy, under the MIT licence.