Gallery › Kubernetes › Azure built-in policies
[Preview]: Configure Azure Arc enabled Kubernetes clusters to install Microsoft Defender for Cloud extension
Converted Policy DeployIfNotExists Disabled Mode Indexed Version 7.3.0-preview Preview
Microsoft Defender for Cloud extension for Azure Arc provides threat protection for your Arc enabled Kubernetes clusters. The extension collects data from all nodes in the cluster and sends it to the Azure Defender for Kubernetes backend in the cloud for further analysis. Learn more in https://docs.microsoft.com/azure/defender-for-cloud/defender-for-containers-enable?pivots=defender-for-container-arc.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
{
"properties": {
"displayName": "[Preview]: Configure Azure Arc enabled Kubernetes clusters to install Microsoft Defender for Cloud extension",
"policyType": "BuiltIn",
"mode": "Indexed",
"description": "Microsoft Defender for Cloud extension for Azure Arc provides threat protection for your Arc enabled Kubernetes clusters. The extension collects data from all nodes in the cluster and sends it to the Azure Defender for Kubernetes backend in the cloud for further analysis. Learn more in https://docs.microsoft.com/azure/defender-for-cloud/defender-for-containers-enable?pivots=defender-for-container-arc.",
"metadata": {
"version": "7.3.0-preview",
"category": "Kubernetes",
"preview": "true"
},
"version": "7.3.0-preview",
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
},
"allowedValues": [
"DeployIfNotExists",
"Disabled"
],
"defaultValue": "DeployIfNotExists"
},
"logAnalyticsWorkspaceResourceId": {
"type": "String",
"metadata": {
"displayName": "LogAnalyticsWorkspaceResourceId",
"description": "Optional Log Analytics workspace resource id. If provided, will be used as part of the feature configuration. Otherwise, default workspace will be provisioned. Value format should be '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/{resourcegroup}/providers/Microsoft.OperationalInsights/workspaces/{logAnalyticsWorkspaceName}'",
"strongType": "Microsoft.OperationalInsights/workspaces",
"assignPermissions": true
},
"defaultValue": ""
},
"excludedDistributions": {
"type": "Array",
"metadata": {
"displayName": "ExcludedDistributions",
"description": "Distributions to be excluded from the policy"
},
"defaultValue": [
"aks",
"aks_management",
"eks",
"gke"
]
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Kubernetes/connectedClusters"
},
{
"field": "Microsoft.Kubernetes/connectedClusters/distribution",
"notIn": "[parameters('excludedDistributions')]"
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.KubernetesConfiguration/extensions",
"deploymentScope": "subscription",
"existenceCondition": {
"allOf": [
{
"field": "Microsoft.KubernetesConfiguration/extensions/extensionType",
"equals": "microsoft.azuredefender.kubernetes"
},
{
"field": "Microsoft.KubernetesConfiguration/extensions/provisioningState",
"equals": "Succeeded"
}
]
},
"roleDefinitionIds": [
"/providers/microsoft.authorization/roleDefinitions/5e93ba01-8f92-4c7a-b12a-801e3df23824",
"/providers/microsoft.authorization/roleDefinitions/8bb6f106-b146-4ee6-a3f9-b9c5a96e0ae5"
],
"deployment": {
"location": "westeurope",
"properties": {
"mode": "incremental",
"parameters": {
"clusterRegion": {
"value": "[field('location')]"
},
"clusterResourceId": {
"value": "[field('id')]"
},
"logAnalyticsWorkspaceResourceId": {
"value": "[parameters('logAnalyticsWorkspaceResourceId')]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"clusterRegion": {
"type": "string"
},
"clusterResourceId": {
"type": "string"
},
"logAnalyticsWorkspaceResourceId": {
"type": "string"
}
},
"variables": {
"locationLongNameToShortMap": {
"australiacentral": "CAU",
"australiacentral2": "CBR2",
"australiaeast": "EAU",
"australiasoutheast": "SEAU",
"brazilsouth": "CQ",
"brazilsoutheast": "BRSE",
"canadacentral": "CCA",
"canadaeast": "YQ",
"centralindia": "CIN",
"centralus": "CUS",
"eastasia": "EA",
"eastus": "EUS",
"eastus2": "EUS2",
"eastus2euap": "eus2p",
"germanywestcentral": "DEWC",
"francecentral": "PAR",
"francesouth": "MRS",
"japaneast": "EJP",
"japanwest": "OS",
"jioindiacentral": "JINC",
"jioindiawest": "JINW",
"koreacentral": "SE",
"koreasouth": "PS",
"northcentralus": "NCUS",
"northeurope": "NEU",
"norwayeast": "NOE",
"norwaywest": "NOW",
"southafricanorth": "JNB",
"southcentralus": "SCUS",
"southeastasia": "SEA",
"southindia": "MA",
"swedencentral": "SEC",
"switzerlandnorth": "CHN",
"switzerlandwest": "CHW",
"uaecentral": "AUH",
"uaenorth": "DXB",
"uksouth": "SUK",
"ukwest": "WUK",
"westcentralus": "WCUS",
"westeurope": "WEU",
"westus": "WUS",
"westus2": "WUS2",
"westus3": "USW3"
},
"locationCode": "[variables('locationLongNameToShortMap')[parameters('clusterRegion')]]",
"subscriptionId": "[subscription().subscriptionId]",
"shouldProvisionDefaultResources": "[empty(parameters('logAnalyticsWorkspaceResourceId'))]",
"defaultRGName": "[concat('DefaultResourceGroup-', variables('locationCode'))]",
"workspaceName": "[concat('DefaultWorkspace-', variables('subscriptionId'),'-', variables('locationCode'))]",
"deployDefaultAscResourceGroup": "[concat('deployDefaultAscResourceGroup-', uniqueString(deployment().name))]",
"defaultWorkspaceResourceId": "[concat('/subscriptions/', variables('subscriptionId'), '/resourcegroups/', variables('defaultRGName'), '/providers/Microsoft.OperationalInsights/workspaces/', variables('workspaceName'))]",
"desiredWorkspaceResourceId": "[if(variables('shouldProvisionDefaultResources'), variables('defaultWorkspaceResourceId'), parameters('logAnalyticsWorkspaceResourceId'))]"
},
"resources": [
{
"condition": "[variables('shouldProvisionDefaultResources')]",
"type": "Microsoft.Resources/resourceGroups",
"name": "[variables('defaultRGName')]",
"apiVersion": "2019-05-01",
"location": "[parameters('clusterRegion')]"
},
{
"condition": "[variables('shouldProvisionDefaultResources')]",
"type": "Microsoft.Resources/deployments",
"name": "[variables('deployDefaultAscResourceGroup')]",
"apiVersion": "2020-06-01",
"resourceGroup": "[variables('defaultRGName')]",
"properties": {
"mode": "Incremental",
"expressionEvaluationOptions": {
"scope": "inner"
},
"parameters": {
"clusterRegion": {
"value": "[parameters('clusterRegion')]"
},
"workspaceName": {
"value": "[variables('workspaceName')]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"clusterRegion": {
"type": "string"
},
"workspaceName": {
"type": "string"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.OperationalInsights/workspaces",
"name": "[parameters('workspaceName')]",
"apiVersion": "2021-06-01",
"location": "[parameters('clusterRegion')]",
"properties": {
"sku": {
"name": "pernode"
},
"retentionInDays": 30,
"features": {
"searchVersion": 1
}
}
}
]
}
},
"dependsOn": [
"[resourceId('Microsoft.Resources/resourceGroups', variables('defaultRGName'))]"
]
},
{
"type": "Microsoft.Resources/deployments",
"name": "[concat('arc-k8s-defender-extension', '-', uniqueString(parameters('clusterResourceId')))]",
"apiVersion": "2020-10-01",
"subscriptionId": "[variables('subscriptionId')]",
"resourceGroup": "[split(parameters('clusterResourceId'),'/')[4]]",
"properties": {
"mode": "Incremental",
"expressionEvaluationOptions": {
"scope": "inner"
},
"parameters": {
"workspaceResourceId": {
"value": "[variables('desiredWorkspaceResourceId')]"
},
"clusterResourceId": {
"value": "[parameters('clusterResourceId')]"
},
"clusterRegion": {
"value": "[parameters('clusterRegion')]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workspaceResourceId": {
"type": "string"
},
"clusterResourceId": {
"type": "string"
},
"clusterRegion": {
"type": "string"
}
},
"resources": [
{
"type": "Microsoft.KubernetesConfiguration/extensions",
"apiVersion": "2023-05-01",
"name": "microsoft.azuredefender.kubernetes",
"location": "[parameters('clusterRegion')]",
"identity": {
"type": "systemassigned"
},
"properties": {
"extensionType": "microsoft.azuredefender.kubernetes",
"configurationSettings": {
"logAnalyticsWorkspaceResourceID": "[parameters('workspaceResourceId')]"
},
"configurationProtectedSettings": {
"omsagent.secret.wsid": "[reference(parameters('workspaceResourceId'), '2015-03-20').customerId]",
"omsagent.secret.key": "[listKeys(parameters('workspaceResourceId'), '2015-03-20').primarySharedKey]"
},
"autoUpgradeMinorVersion": true,
"releaseTrain": "Stable",
"scope": {
"Cluster": {
"releaseNamespace": "mdc"
}
}
},
"scope": "[concat('Microsoft.Kubernetes/connectedClusters/', split(parameters('clusterResourceId'),'/')[8])]"
}
]
}
},
"dependsOn": [
"[variables('deployDefaultAscResourceGroup')]"
]
}
]
}
}
}
}
}
},
"versions": [
"7.3.0-PREVIEW",
"7.2.0-PREVIEW",
"7.1.0-PREVIEW"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/708b60a6-d253-4fe0-9114-4be4c00f012c",
"name": "708b60a6-d253-4fe0-9114-4be4c00f012c"
}# Converted from ASC_Azure_Defender_Arc_Extension_DINE.json by ConvertTo-Bylaw.
Policy '708b60a6-d253-4fe0-9114-4be4c00f012c' {
Properties @{
DisplayName = '[Preview]: Configure Azure Arc enabled Kubernetes clusters to install Microsoft Defender for Cloud extension'
Description = 'Microsoft Defender for Cloud extension for Azure Arc provides threat protection for your Arc enabled Kubernetes clusters. The extension collects data from all nodes in the cluster and sends it to the Azure Defender for Kubernetes backend in the cloud for further analysis. Learn more in https://docs.microsoft.com/azure/defender-for-cloud/defender-for-containers-enable?pivots=defender-for-container-arc.'
Version = '7.3.0-preview'
Category = 'Kubernetes'
PolicyVersion = '7.3.0-preview'
Mode = 'Indexed'
Metadata = [ordered]@{ preview = 'true' }
}
Parameter Effect @{
AllowedValues = @('DeployIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Parameter LogAnalyticsWorkspaceResourceId @{
Default = ''
DisplayName = 'LogAnalyticsWorkspaceResourceId'
Description = 'Optional Log Analytics workspace resource id. If provided, will be used as part of the feature configuration. Otherwise, default workspace will be provisioned. Value format should be ''/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/{resourcegroup}/providers/Microsoft.OperationalInsights/workspaces/{logAnalyticsWorkspaceName}'''
Metadata = [ordered]@{ strongType = 'Microsoft.OperationalInsights/workspaces'; assignPermissions = $true }
}
Parameter ExcludedDistributions @{
Type = 'Array'
Default = @('aks', 'aks_management', 'eks', 'gke')
DisplayName = 'ExcludedDistributions'
Description = 'Distributions to be excluded from the policy'
}
Resource 'Microsoft.Kubernetes/connectedClusters' {
Require 'distribution is one of the ExcludedDistributions parameter' {
Field distribution | Must -BeIn (Param ExcludedDistributions)
}
}
DeployIfNotExists 'Microsoft.KubernetesConfiguration/extensions' -Role 'Defender Containers Sensor', 'Defender Kubernetes Agent Operator' -Effect (Param Effect) {
Require 'extensionType is microsoft.azuredefender.kubernetes and provisioningState is Succeeded' {
Field extensionType | Must -Be 'microsoft.azuredefender.kubernetes'
Field provisioningState | Must -Be 'Succeeded'
}
Deployment @{
TemplateFile = './templates/708b60a6-d253-4fe0-9114-4be4c00f012c.json'
Scope = 'Subscription'
Location = 'westeurope'
Parameters = [ordered]@{
clusterRegion = (Arm '[field(''location'')]')
clusterResourceId = (Arm '[field(''id'')]')
logAnalyticsWorkspaceResourceId = (Param LogAnalyticsWorkspaceResourceId)
}
}
}
}Its deployment templates are written beside it:
templates/708b60a6-d253-4fe0-9114-4be4c00f012c.json
Source: built-in-policies/policyDefinitions/Kubernetes/ASC_Azure_Defender_Arc_Extension_DINE.json in Azure/azure-policy, under the MIT licence.
Bylaw