Bylaw

Gallery › Kubernetes › Azure built-in policies

Azure Kubernetes Service Clusters should enable workload identity

Converted Policy Audit Disabled Mode Indexed Version 1.0.0

Workload identity allows to assign a unique identity to each Kubernetes Pod and associate it with Azure AD protected resources such as Azure Key Vault, enabling secure access to these resources from within the Pod. Learn more at: https://aka.ms/aks/wi.

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

Azure Policy JSONAKS_WorkloadIdentity_Audit.json · 57 lines
{
  "properties": {
    "policyType": "BuiltIn",
    "displayName": "Azure Kubernetes Service Clusters should enable workload identity",
    "description": "Workload identity allows to assign a unique identity to each Kubernetes Pod and associate it with Azure AD protected resources such as Azure Key Vault, enabling secure access to these resources from within the Pod. Learn more at: https://aka.ms/aks/wi.",
    "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."
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.ContainerService/managedClusters"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.ContainerService/managedClusters/securityProfile.workloadIdentity.enabled",
                "exists": "false"
              },
              {
                "field": "Microsoft.ContainerService/managedClusters/securityProfile.workloadIdentity.enabled",
                "equals": "false"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/2cc2e023-0dac-4046-875b-178f683929d5",
  "name": "2cc2e023-0dac-4046-875b-178f683929d5"
}
Bylaw2cc2e023-0dac-4046-875b-178f683929d5.bylaw.ps1 · 32 lines
# Converted from AKS_WorkloadIdentity_Audit.json by ConvertTo-Bylaw.
Policy '2cc2e023-0dac-4046-875b-178f683929d5' {

    Properties @{
        DisplayName   = 'Azure Kubernetes Service Clusters should enable workload identity'
        Description   = 'Workload identity allows to assign a unique identity to each Kubernetes Pod and associate it with Azure AD protected resources such as Azure Key Vault, enabling secure access to these resources from within the Pod. Learn more at: https://aka.ms/aks/wi.'
        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.'
    }

    Resource 'Microsoft.ContainerService/managedClusters' {

        Require 'securityProfile.workloadIdentity.enabled exists' {
            Field securityProfile.workloadIdentity.enabled | Must -Exist
        }

        Require 'securityProfile.workloadIdentity.enabled is not false' {
            Field securityProfile.workloadIdentity.enabled | Must -Not -Be 'false' -IfPresent
        }
    }

    Effect (Param Effect)
}

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