Bylaw

Gallery › Kubernetes › Azure built-in policies

Azure Kubernetes Clusters should use Azure CNI

Converted Policy Audit Disabled Mode Indexed Version 1.0.1

Azure CNI is a prerequisite for some Azure Kubernetes Service features, including Azure network policies, Windows node pools and virtual nodes add-on. Learn more at: https://aka.ms/aks-azure-cni

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

Azure Policy JSONAKS_EnableCNI.json · 50 lines
{
  "properties": {
    "displayName": "Azure Kubernetes Clusters should use Azure CNI",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Azure CNI is a prerequisite for some Azure Kubernetes Service features, including Azure network policies, Windows node pools and virtual nodes add-on. Learn more at: https://aka.ms/aks-azure-cni",
    "metadata": {
      "version": "1.0.1",
      "category": "Kubernetes"
    },
    "version": "1.0.1",
    "parameters": {
      "effect": {
        "type": "String",
        "defaultValue": "Audit",
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy",
          "portalReview": true
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.ContainerService/managedClusters"
          },
          {
            "field": "Microsoft.ContainerService/managedClusters/networkProfile.networkPlugin",
            "notEquals": "azure"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.1"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/46238e2f-3f6f-4589-9f3f-77bed4116e67",
  "name": "46238e2f-3f6f-4589-9f3f-77bed4116e67"
}
Bylaw46238e2f-3f6f-4589-9f3f-77bed4116e67.bylaw.ps1 · 29 lines
# Converted from AKS_EnableCNI.json by ConvertTo-Bylaw.
Policy '46238e2f-3f6f-4589-9f3f-77bed4116e67' {

    Properties @{
        DisplayName   = 'Azure Kubernetes Clusters should use Azure CNI'
        Description   = 'Azure CNI is a prerequisite for some Azure Kubernetes Service features, including Azure network policies, Windows node pools and virtual nodes add-on. Learn more at: https://aka.ms/aks-azure-cni'
        Version       = '1.0.1'
        Category      = 'Kubernetes'
        PolicyVersion = '1.0.1'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
        Metadata      = [ordered]@{ portalReview = $true }
    }

    Resource 'Microsoft.ContainerService/managedClusters' {

        Require 'networkProfile.networkPlugin is azure' {
            Field networkProfile.networkPlugin | Must -Be 'azure'
        }
    }

    Effect (Param Effect)
}

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