Bylaw

Gallery › Kubernetes › Azure built-in policies

Azure Kubernetes Service Clusters should enable cluster auto-upgrade

Converted Policy Audit Disabled Mode Indexed Version 1.0.0

AKS cluster auto-upgrade can ensure your clusters are up to date and don't miss the latest features or patches from AKS and upstream Kubernetes. Learn more at: https://learn.microsoft.com/en-us/azure/aks/auto-upgrade-cluster.

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

Azure Policy JSONAKS_Autoupgrade_Cluster_Audit.json · 77 lines
{
  "properties": {
    "policyType": "BuiltIn",
    "displayName": "Azure Kubernetes Service Clusters should enable cluster auto-upgrade",
    "description": "AKS cluster auto-upgrade can ensure your clusters are up to date and don't miss the latest features or patches from AKS and upstream Kubernetes. Learn more at: https://learn.microsoft.com/en-us/azure/aks/auto-upgrade-cluster.",
    "metadata": {
      "version": "1.0.0",
      "category": "Kubernetes"
    },
    "version": "1.0.0",
    "mode": "Indexed",
    "parameters": {
      "effect": {
        "type": "String",
        "defaultValue": "Audit",
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy."
        }
      },
      "allowedClusterAutoUpgradeChannels": {
        "type": "Array",
        "metadata": {
          "displayName": "Allowed Cluster Auto-upgrade Channels",
          "description": "Cluster auto-upgrade channels viewed as complaint. Lean more at https://learn.microsoft.com/en-us/azure/aks/auto-upgrade-cluster#use-cluster-auto-upgrade",
          "portalReview": true
        },
        "allowedValues": [
          "rapid",
          "stable",
          "patch",
          "node-image",
          "none"
        ],
        "defaultValue": [
          "rapid",
          "stable",
          "patch"
        ]
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.ContainerService/managedClusters"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.ContainerService/managedClusters/autoUpgradeProfile.upgradeChannel",
                "exists": false
              },
              {
                "field": "Microsoft.ContainerService/managedClusters/autoUpgradeProfile.upgradeChannel",
                "notin": "[parameters('allowedClusterAutoUpgradeChannels')]"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/5c345cdf-2049-47e0-b8fe-b0e96bc2df35",
  "name": "5c345cdf-2049-47e0-b8fe-b0e96bc2df35"
}
Bylaw5c345cdf-2049-47e0-b8fe-b0e96bc2df35.bylaw.ps1 · 40 lines
# Converted from AKS_Autoupgrade_Cluster_Audit.json by ConvertTo-Bylaw.
Policy '5c345cdf-2049-47e0-b8fe-b0e96bc2df35' {

    Properties @{
        DisplayName   = 'Azure Kubernetes Service Clusters should enable cluster auto-upgrade'
        Description   = 'AKS cluster auto-upgrade can ensure your clusters are up to date and don''t miss the latest features or patches from AKS and upstream Kubernetes. Learn more at: https://learn.microsoft.com/en-us/azure/aks/auto-upgrade-cluster.'
        Version       = '1.0.0'
        Category      = 'Kubernetes'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy.'
    }
    Parameter AllowedClusterAutoUpgradeChannels @{
        Type          = 'Array'
        AllowedValues = @('rapid', 'stable', 'patch', 'node-image', 'none')
        Default       = @('rapid', 'stable', 'patch')
        DisplayName   = 'Allowed Cluster Auto-upgrade Channels'
        Description   = 'Cluster auto-upgrade channels viewed as complaint. Lean more at https://learn.microsoft.com/en-us/azure/aks/auto-upgrade-cluster#use-cluster-auto-upgrade'
        Metadata      = [ordered]@{ portalReview = $true }
    }

    Resource 'Microsoft.ContainerService/managedClusters' {

        Require 'autoUpgradeProfile.upgradeChannel exists' {
            Field autoUpgradeProfile.upgradeChannel | Must -Exist
        }

        Require 'autoUpgradeProfile.upgradeChannel is one of the AllowedClusterAutoUpgradeChannels parameter' {
            Field autoUpgradeProfile.upgradeChannel | Must -BeIn (Param AllowedClusterAutoUpgradeChannels)
        }
    }

    Effect (Param Effect)
}

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