Gallery › Mission › Azure built-in policies
CosmosDB should restrict external private endpoints access
Converted Policy Audit Deny Disabled Mode All Version 1.1.0
This policy applies exclusively to Mission Platform products and services; usage outside of these scopes is not supported. This policy enforces restrictions on external private endpoints linked to Cosmos DB to maintain network isolation and prevent unauthorized cross-tenant access.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONCosmosDBRestrictExternalPrivateEndpoints.json · 79 lines
{
"properties": {
"displayName": "CosmosDB should restrict external private endpoints access",
"policyType": "BuiltIn",
"mode": "All",
"description": "This policy applies exclusively to Mission Platform products and services; usage outside of these scopes is not supported. This policy enforces restrictions on external private endpoints linked to Cosmos DB to maintain network isolation and prevent unauthorized cross-tenant access.",
"metadata": {
"version": "1.1.0",
"category": "Mission"
},
"version": "1.1.0",
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "CosmosDB external private endpoints access effect",
"description": "Specify the access restriction of private endpoints to a CosmosDB effect"
},
"allowedValues": [
"Audit",
"Deny",
"Disabled"
],
"defaultValue": "Audit"
},
"excludedSubscriptionIDs": {
"type": "Array",
"metadata": {
"description": "The list of excluded Subscription Ids.",
"displayName": "Excluded subscription IDs"
},
"defaultValue": []
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.DocumentDB/databaseAccounts/privateEndpointConnections"
},
{
"field": "Microsoft.DocumentDB/databaseAccounts/privateEndpointConnections/privateLinkServiceConnectionState.status",
"equals": "Approved"
},
{
"anyOf": [
{
"field": "Microsoft.DocumentDB/databaseAccounts/privateEndpointConnections/privateEndpoint.id",
"exists": false
},
{
"allOf": [
{
"value": "[split(concat(field('Microsoft.DocumentDB/databaseAccounts/privateEndpointConnections/privateEndpoint.id'), '//'), '/')[2]]",
"notEquals": "[subscription().subscriptionId]"
},
{
"value": "[split(concat(field('Microsoft.DocumentDB/databaseAccounts/privateEndpointConnections/privateEndpoint.id'), '//'), '/')[2]]",
"notIn": "[parameters('excludedSubscriptionIDs')]"
}
]
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
},
"versions": [
"1.1.0",
"1.0.0"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/ea79b84d-f538-475d-a6ef-7951747a3455",
"name": "ea79b84d-f538-475d-a6ef-7951747a3455"
}Bylawea79b84d-f538-475d-a6ef-7951747a3455.bylaw.ps1 · 45 lines
# Converted from CosmosDBRestrictExternalPrivateEndpoints.json by ConvertTo-Bylaw.
Policy 'ea79b84d-f538-475d-a6ef-7951747a3455' {
Properties @{
DisplayName = 'CosmosDB should restrict external private endpoints access'
Description = 'This policy applies exclusively to Mission Platform products and services; usage outside of these scopes is not supported. This policy enforces restrictions on external private endpoints linked to Cosmos DB to maintain network isolation and prevent unauthorized cross-tenant access.'
Version = '1.1.0'
Category = 'Mission'
PolicyVersion = '1.1.0'
Mode = 'All'
}
Parameter Effect @{
AllowedValues = @('Audit', 'Deny', 'Disabled')
Default = 'Audit'
DisplayName = 'CosmosDB external private endpoints access effect'
Description = 'Specify the access restriction of private endpoints to a CosmosDB effect'
}
Parameter ExcludedSubscriptionIDs @{
Type = 'Array'
Default = @()
DisplayName = 'Excluded subscription IDs'
Description = 'The list of excluded Subscription Ids.'
}
Resource 'Microsoft.DocumentDB/databaseAccounts/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.DocumentDB/databaseAccounts/privateEndpointConnections/privateEndpoint.id''), ''//''), ''/'')[2]]' | Must -Be (Arm '[subscription().subscriptionId]')
Arm '[split(concat(field(''Microsoft.DocumentDB/databaseAccounts/privateEndpointConnections/privateEndpoint.id''), ''//''), ''/'')[2]]' | Must -BeIn (Param ExcludedSubscriptionIDs)
}
}
}
Effect (Param Effect)
}Source: built-in-policies/policyDefinitions/Mission/CosmosDBRestrictExternalPrivateEndpoints.json in Azure/azure-policy, under the MIT licence.
Bylaw