Bylaw

Gallery › Kubernetes › Azure Landing Zones Library

Detect AKS clusters using kubenet network plugin

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0

Detects Azure Kubernetes Service (AKS) clusters that are configured to use the 'kubenet' network plugin that will be deprecated 31 March 2028. For more information review https://learn.microsoft.com/en-us/azure/aks/configure-kubenet

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

Azure Policy JSONAudit-AKS-kubenet.alz_policy_definition.json · 50 lines
{
  "name": "Audit-AKS-kubenet",
  "properties": {
    "description": "Detects Azure Kubernetes Service (AKS) clusters that are configured to use the 'kubenet' network plugin that will be deprecated 31 March 2028. For more information review https://learn.microsoft.com/en-us/azure/aks/configure-kubenet",
    "displayName": "Detect AKS clusters using kubenet network plugin",
    "metadata": {
      "alzCloudEnvironments": [
        "AzureCloud"
      ],
      "category": "Kubernetes",
      "source": "https://github.com/Azure/Enterprise-Scale/",
      "version": "1.0.0"
    },
    "mode": "Indexed",
    "parameters": {
      "effect": {
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "defaultValue": "Audit",
        "metadata": {
          "description": "Enable or disable the execution of the policy.",
          "displayName": "Effect"
        },
        "type": "String"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "equals": "Microsoft.ContainerService/managedClusters",
            "field": "type"
          },
          {
            "equals": "kubenet",
            "field": "Microsoft.ContainerService/managedClusters/networkProfile.networkPlugin"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "policyType": "Custom"
  },
  "type": "Microsoft.Authorization/policyDefinitions"
}
BylawAudit-AKS-kubenet.bylaw.ps1 · 28 lines
# Converted from Audit-AKS-kubenet.alz_policy_definition.json by ConvertTo-Bylaw.
Policy 'Audit-AKS-kubenet' {

    Properties @{
        DisplayName = 'Detect AKS clusters using kubenet network plugin'
        Description = 'Detects Azure Kubernetes Service (AKS) clusters that are configured to use the ''kubenet'' network plugin that will be deprecated 31 March 2028. For more information review https://learn.microsoft.com/en-us/azure/aks/configure-kubenet'
        Category    = 'Kubernetes'
        Version     = '1.0.0'
        Mode        = 'Indexed'
        Metadata    = [ordered]@{ alzCloudEnvironments = @('AzureCloud'); source = 'https://github.com/Azure/Enterprise-Scale/' }
    }

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

    Resource 'Microsoft.ContainerService/managedClusters' {

        Require 'networkProfile.networkPlugin is not kubenet' {
            Field networkProfile.networkPlugin | Must -Not -Be 'kubenet' -IfPresent
        }
    }

    Effect (Param Effect)
}

Source: policy_definitions/Audit-AKS-kubenet.alz_policy_definition.json in Azure/Azure-Landing-Zones-Library, under the MIT licence.