Bylaw

Gallery › Network › Azure Community Policy

Prevent cross tenant Private Link for storage

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

This policy prevents private link between tenants for storage.

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

Azure Policy JSONazurepolicy.json · 56 lines
{
  "name": "f151e60c-f336-4b95-bd96-7e419939f01f",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Prevent cross tenant Private Link for storage",
    "description": "This policy prevents private link between tenants for storage.",
    "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.Storage/storageAccounts/privateEndpointConnections",
            "field": "type"
          },
          {
            "anyOf": [
              {
                "exists": false,
                "field": "Microsoft.Storage/storageAccounts/privateEndpointConnections/privateEndpoint.id"
              },
              {
                "notEquals": "[subscription().subscriptionId]",
                "value": "[split(concat(field('Microsoft.Storage/storageAccounts/privateEndpointConnections/privateEndpoint.id'), '//'), '/')[2]]"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylawf151e60c-f336-4b95-bd96-7e419939f01f.bylaw.ps1 · 31 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'f151e60c-f336-4b95-bd96-7e419939f01f' {

    Properties @{
        DisplayName = 'Prevent cross tenant Private Link for storage'
        Description = 'This policy prevents private link between tenants for storage.'
        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.Storage/storageAccounts/privateEndpointConnections' {

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

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

    Effect (Param Effect)
}

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