Bylaw

Gallery › Kubernetes › Azure built-in policies

Configure Microsoft Entra ID integrated Azure Kubernetes Service Clusters with required Admin Group Access

Converted Policy DeployIfNotExists Disabled Mode Indexed Version 2.1.0

Ensure to improve cluster security by centrally govern Administrator access to Microsoft Entra ID integrated AKS clusters.

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

Azure Policy JSONAKS_AAD_AdminGroup_DINE.json · 228 lines
{
  "properties": {
    "policyType": "BuiltIn",
    "displayName": "Configure Microsoft Entra ID integrated Azure Kubernetes Service Clusters with required Admin Group Access",
    "description": "Ensure to improve cluster security by centrally govern Administrator access to Microsoft Entra ID integrated AKS clusters.",
    "metadata": {
      "version": "2.1.0",
      "category": "Kubernetes"
    },
    "version": "2.1.0",
    "mode": "Indexed",
    "parameters": {
      "effect": {
        "type": "String",
        "defaultValue": "DeployIfNotExists",
        "allowedValues": [
          "DeployIfNotExists",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy",
          "portalReview": true
        }
      },
      "adminGroupObjectIDs": {
        "type": "Array",
        "metadata": {
          "displayName": "AKS Administrator Group Object IDs",
          "description": "Array of the existing AKS Administrator Group Object ID to ensure administration access to the cluster. Empty array will remove all admin access.",
          "portalReview": true
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.ContainerService/managedClusters"
          },
          {
            "field": "Microsoft.ContainerService/managedClusters/aadProfile",
            "exists": true
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.ContainerService/managedClusters",
          "name": "[field('name')]",
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/ed7f3fbd-7b88-4dd4-9017-9adb7ce333f8",
            "/providers/Microsoft.Authorization/roleDefinitions/18ed5180-3e48-46fd-8541-4ea054d57064"
          ],
          "existenceCondition": {
            "allOf": [
              {
                "count": {
                  "field": "Microsoft.ContainerService/managedClusters/aadProfile.adminGroupObjectIDs[*]",
                  "where": {
                    "field": "Microsoft.ContainerService/managedClusters/aadProfile.adminGroupObjectIDs[*]",
                    "in": "[parameters('adminGroupObjectIDs')]"
                  }
                },
                "equals": "[length(parameters('adminGroupObjectIDs'))]"
              },
              {
                "count": {
                  "field": "Microsoft.ContainerService/managedClusters/aadProfile.adminGroupObjectIDs[*]"
                },
                "equals": "[length(parameters('adminGroupObjectIDs'))]"
              }
            ]
          },
          "deployment": {
            "properties": {
              "mode": "incremental",
              "template": {
                "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {
                  "clusterName": {
                    "type": "string"
                  },
                  "clusterResourceGroupName": {
                    "type": "string"
                  },
                  "adminGroupObjectIDs": {
                    "type": "array"
                  }
                },
                "variables": {
                  "clusterGetDeploymentName": "[take(concat('Policy-Get-', parameters('clusterName')), 64)]",
                  "clusterUpdateDeploymentName": "[take(concat('Policy-Update-', parameters('clusterName')), 64)]"
                },
                "resources": [
                  {
                    "apiVersion": "2020-06-01",
                    "type": "Microsoft.Resources/deployments",
                    "name": "[variables('clusterGetDeploymentName')]",
                    "properties": {
                      "mode": "Incremental",
                      "template": {
                        "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                        "contentVersion": "1.0.0.0",
                        "resources": [],
                        "outputs": {
                          "aksCluster": {
                            "type": "object",
                            "value": "[reference(resourceId(parameters('clusterResourceGroupName'), 'Microsoft.ContainerService/managedClusters', parameters('clusterName')), '2023-11-01', 'Full')]"
                          }
                        }
                      }
                    }
                  },
                  {
                    "apiVersion": "2020-06-01",
                    "type": "Microsoft.Resources/deployments",
                    "name": "[variables('clusterUpdateDeploymentName')]",
                    "properties": {
                      "mode": "Incremental",
                      "expressionEvaluationOptions": {
                        "scope": "inner"
                      },
                      "template": {
                        "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                        "contentVersion": "1.0.0.0",
                        "parameters": {
                          "aksClusterName": {
                            "type": "string"
                          },
                          "aksClusterContent": {
                            "type": "object"
                          },
                          "adminGroupObjectIDs": {
                            "type": "array"
                          }
                        },
                        "resources": [
                          {
                            "apiVersion": "2023-11-01",
                            "type": "Microsoft.ContainerService/managedClusters",
                            "name": "[parameters('aksClusterName')]",
                            "location": "[parameters('aksClusterContent').location]",
                            "sku": "[parameters('aksClusterContent').sku]",
                            "tags": "[if(contains(parameters('aksClusterContent'), 'tags'), parameters('aksClusterContent').tags, json('null'))]",
                            "properties": {
                              "kubernetesVersion": "[parameters('aksClusterContent').properties.kubernetesVersion]",
                              "linuxProfile": "[if(contains(parameters('aksClusterContent').properties, 'linuxProfile'), parameters('aksClusterContent').properties.linuxProfile, json('null'))]",
                              "windowsProfile": "[if(contains(parameters('aksClusterContent').properties, 'windowsProfile'), parameters('aksClusterContent').properties.windowsProfile, json('null'))]",
                              "servicePrincipalProfile": "[if(contains(parameters('aksClusterContent').properties, 'servicePrincipalProfile'), parameters('aksClusterContent').properties.servicePrincipalProfile, json('null'))]",
                              "nodeResourceGroup": "[parameters('aksClusterContent').properties.nodeResourceGroup]",
                              "enableRBAC": "[if(contains(parameters('aksClusterContent').properties, 'enableRBAC'), parameters('aksClusterContent').properties.enableRBAC, json('null'))]",
                              "enablePodSecurityPolicy": "[if(contains(parameters('aksClusterContent').properties, 'enablePodSecurityPolicy'), parameters('aksClusterContent').properties.enablePodSecurityPolicy, json('null'))]",
                              "networkProfile": "[if(contains(parameters('aksClusterContent').properties, 'networkProfile'), parameters('aksClusterContent').properties.networkProfile, json('null'))]",
                              "aadProfile": {
                                "adminGroupObjectIds": "[parameters('adminGroupObjectIDs')]",
                                "managed": "[if(and(contains(parameters('aksClusterContent').properties, 'aadProfile'), contains(parameters('aksClusterContent').properties.aadProfile, 'managed')), parameters('aksClusterContent').properties.aadProfile.managed, json('null'))]",
                                "enableAzureRBAC": "[if(and(contains(parameters('aksClusterContent').properties, 'aadProfile'), contains(parameters('aksClusterContent').properties.aadProfile, 'enableAzureRBAC')), parameters('aksClusterContent').properties.aadProfile.enableAzureRBAC, json('null'))]",
                                "tenantID": "[if(and(contains(parameters('aksClusterContent').properties, 'aadProfile'), contains(parameters('aksClusterContent').properties.aadProfile, 'tenantID')), parameters('aksClusterContent').properties.aadProfile.tenantID, json('null'))]",
                                "clientAppID": "[if(and(contains(parameters('aksClusterContent').properties, 'aadProfile'), contains(parameters('aksClusterContent').properties.aadProfile, 'clientAppID')), parameters('aksClusterContent').properties.aadProfile.clientAppID, json('null'))]",
                                "serverAppID": "[if(and(contains(parameters('aksClusterContent').properties, 'aadProfile'), contains(parameters('aksClusterContent').properties.aadProfile, 'serverAppID')), parameters('aksClusterContent').properties.aadProfile.serverAppID, json('null'))]",
                                "serverAppSecret": "[if(and(contains(parameters('aksClusterContent').properties, 'aadProfile'), contains(parameters('aksClusterContent').properties.aadProfile, 'serverAppSecret')), parameters('aksClusterContent').properties.aadProfile.serverAppSecret, json('null'))]"
                              },
                              "autoScalerProfile": "[if(contains(parameters('aksClusterContent').properties, 'autoScalerProfile'), parameters('aksClusterContent').properties.autoScalerProfile, json('null'))]",
                              "autoUpgradeProfile": "[if(contains(parameters('aksClusterContent').properties, 'autoUpgradeProfile'), parameters('aksClusterContent').properties.autoUpgradeProfile, json('null'))]",
                              "azureMonitorProfile": "[if(contains(parameters('aksClusterContent').properties, 'azureMonitorProfile'), parameters('aksClusterContent').properties.azureMonitorProfile, json('null'))]",
                              "apiServerAccessProfile": "[if(contains(parameters('aksClusterContent').properties, 'apiServerAccessProfile'), parameters('aksClusterContent').properties.apiServerAccessProfile, json('null'))]",
                              "diskEncryptionSetID": "[if(contains(parameters('aksClusterContent').properties, 'diskEncryptionSetID'), parameters('aksClusterContent').properties.diskEncryptionSetID, json('null'))]",
                              "disableLocalAccounts": "[if(contains(parameters('aksClusterContent').properties, 'disableLocalAccounts'), parameters('aksClusterContent').properties.disableLocalAccounts, json('null'))]",
                              "fqdnSubdomain": "[if(contains(parameters('aksClusterContent').properties, 'fqdnSubdomain'), parameters('aksClusterContent').properties.fqdnSubdomain, json('null'))]",
                              "httpProxyConfig": "[if(contains(parameters('aksClusterContent').properties, 'httpProxyConfig'), parameters('aksClusterContent').properties.httpProxyConfig, json('null'))]",
                              "oidcIssuerProfile": "[if(contains(parameters('aksClusterContent').properties, 'oidcIssuerProfile'), parameters('aksClusterContent').properties.oidcIssuerProfile, json('null'))]",
                              "podIdentityProfile": "[if(contains(parameters('aksClusterContent').properties, 'podIdentityProfile'), parameters('aksClusterContent').properties.podIdentityProfile, json('null'))]",
                              "privateLinkResources": "[if(contains(parameters('aksClusterContent').properties, 'privateLinkResources'), parameters('aksClusterContent').properties.privateLinkResources, json('null'))]",
                              "identityProfile": "[if(contains(parameters('aksClusterContent').properties, 'identityProfile'), parameters('aksClusterContent').properties.identityProfile, json('null'))]",
                              "publicNetworkAccess": "[if(contains(parameters('aksClusterContent').properties, 'publicNetworkAccess'), parameters('aksClusterContent').properties.publicNetworkAccess, json('null'))]",
                              "serviceMeshProfile": "[if(contains(parameters('aksClusterContent').properties, 'serviceMeshProfile'), parameters('aksClusterContent').properties.serviceMeshProfile, json('null'))]",
                              "storageProfile": "[if(contains(parameters('aksClusterContent').properties, 'storageProfile'), parameters('aksClusterContent').properties.storageProfile, json('null'))]",
                              "supportPlan": "[if(contains(parameters('aksClusterContent').properties, 'supportPlan'), parameters('aksClusterContent').properties.supportPlan, json('null'))]",
                              "upgradeSettings": "[if(contains(parameters('aksClusterContent').properties, 'upgradeSettings'), parameters('aksClusterContent').properties.upgradeSettings, json('null'))]",
                              "workloadAutoScalerProfile": "[if(contains(parameters('aksClusterContent').properties, 'workloadAutoScalerProfile'), parameters('aksClusterContent').properties.workloadAutoScalerProfile, json('null'))]"
                            }
                          }
                        ],
                        "outputs": {}
                      },
                      "parameters": {
                        "aksClusterName": {
                          "value": "[parameters('clusterName')]"
                        },
                        "aksClusterContent": {
                          "value": "[reference(variables('clusterGetDeploymentName')).outputs.aksCluster.value]"
                        },
                        "adminGroupObjectIDs": {
                          "value": "[parameters('adminGroupObjectIDs')]"
                        }
                      }
                    }
                  }
                ]
              },
              "parameters": {
                "clusterName": {
                  "value": "[field('name')]"
                },
                "clusterResourceGroupName": {
                  "value": "[resourceGroup().name]"
                },
                "adminGroupObjectIDs": {
                  "value": "[parameters('adminGroupObjectIDs')]"
                }
              }
            }
          }
        }
      }
    },
    "versions": [
      "2.1.0",
      "2.0.4"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/36a27de4-199b-40fb-b336-945a8475d6c5",
  "name": "36a27de4-199b-40fb-b336-945a8475d6c5"
}
Bylaw36a27de4-199b-40fb-b336-945a8475d6c5.bylaw.ps1 · 47 lines
# Converted from AKS_AAD_AdminGroup_DINE.json by ConvertTo-Bylaw.
Policy '36a27de4-199b-40fb-b336-945a8475d6c5' {

    Properties @{
        DisplayName   = 'Configure Microsoft Entra ID integrated Azure Kubernetes Service Clusters with required Admin Group Access'
        Description   = 'Ensure to improve cluster security by centrally govern Administrator access to Microsoft Entra ID integrated AKS clusters.'
        Version       = '2.1.0'
        Category      = 'Kubernetes'
        PolicyVersion = '2.1.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('DeployIfNotExists', 'Disabled')
        Default       = 'DeployIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
        Metadata      = [ordered]@{ portalReview = $true }
    }
    Parameter AdminGroupObjectIDs @{
        Type        = 'Array'
        DisplayName = 'AKS Administrator Group Object IDs'
        Description = 'Array of the existing AKS Administrator Group Object ID to ensure administration access to the cluster. Empty array will remove all admin access.'
        Metadata    = [ordered]@{ portalReview = $true }
    }

    Resource 'Microsoft.ContainerService/managedClusters' {

        Require 'aadProfile does not exist' {
            Field aadProfile | Must -Not -Exist
        }
    }

    DeployIfNotExists 'Microsoft.ContainerService/managedClusters' -Role 'Azure Kubernetes Service Contributor Role', 'Azure Kubernetes Service Policy Add-on Deployment' -Name (Arm '[field(''name'')]') -Effect (Param Effect) {
        Require 'aadProfile.adminGroupObjectIDs is as required' {
            Count 'aadProfile.adminGroupObjectIDs[*]' -Where {
                Element | Must -BeIn (Param AdminGroupObjectIDs)
            } | Must -Be (Param AdminGroupObjectIDs -Length)
            Count 'aadProfile.adminGroupObjectIDs[*]' | Must -Be (Param AdminGroupObjectIDs -Length)
        }
        Deployment -TemplateFile './templates/36a27de4-199b-40fb-b336-945a8475d6c5.json' -Parameters ([ordered]@{
                clusterName              = (Arm '[field(''name'')]')
                clusterResourceGroupName = (Arm '[resourceGroup().name]')
                adminGroupObjectIDs      = (Param AdminGroupObjectIDs)
            })
    }
}

Its deployment templates are written beside it:

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