Azure Policy Add-on

October 6, 2022 ยท View on GitHub

Azure Policy integrates with the AKS Engine to apply at-scale enforcements and safeguards on your clusters in a centralized, consistent manner. By extending use of Open Policy Agent (OPA) Gatekeeper v3, an admission controller webhook for Kubernetes, Azure Policy makes it possible to manage and report on the compliance state of your Azure resources and AKS Engine clusters from one place.

Note

Azure Policy for AKS Engine is in Public Preview. The service only supports built-in policy definitions and a single AKS Engine cluster for each resource group configured with a Service Principal. Gatekeeper v3 is in Beta and is supported by the open source community.

For detailed instructions to enable and use Azure policy add-on for AKS Engine, please refer Install Azure Policy Add-on on AKS Engine.

The following is a sample API definition with azure-policy addon.

{
  "apiVersion": "vlabs",
  "properties": {
    "orchestratorProfile": {
      "kubernetesConfig": {
        "addons": [
          {
            "name": "azure-policy",
            "enabled": true,
            "config": {
              "auditInterval": "60",
              "constraintViolationsLimit": "100"
            }
          }
        ]
      }
    },
    "masterProfile": {
      "count": 1,
      "dnsPrefix": "",
      "vmSize": "Standard_DS2_v2"
    },
    "agentPoolProfiles": [
      {
        "name": "agentpool",
        "count": 3,
        "vmSize": "Standard_DS2_v2",
        "availabilityProfile": "AvailabilitySet"
      }
    ],
    "linuxProfile": {
      "adminUsername": "azureuser",
      "ssh": {
        "publicKeys": [
          {
            "keyData": ""
          }
        ]
      }
    },
    "servicePrincipalProfile": {
      "clientId": "",
      "secret": ""
    }
  }
}

๐Ÿšจ Please note that this add-on is in alpha stage and is not production ready.

You can validate that the add-on is running as expected with the following command. You should see gatekeeper and azure-policy pods running.

kubectl get pods -n kube-system

Configuration

NameRequiredDescriptionDefault Value
auditIntervalnoaudit interval (in seconds)60
constraintViolationsLimitnoconstraint violations limit100

Azure Policy

NameRequiredDescriptionDefault Value
namenocontainer name"azure-policy"
imagenoimage"mcr.microsoft.com/azure-policy/policy-kubernetes-addon-prod:prod_20201023.1"
cpuRequestsnocpu requests for the container"30m"
memoryRequestsnomemory requests for the container"50Mi"
cpuLimitsnocpu limits for the container"100m"
memoryLimitsnomemory limits for the container"200Mi"

Gatekeeper

NameRequiredDescriptionDefault Value
namenocontainer name"gatekeeper"
imagenoimage"mcr.microsoft.com/oss/open-policy-agent/gatekeeper:v3.2.3"
cpuRequestsnocpu requests for the container"100m"
memoryRequestsnomemory requests for the container"256Mi"
cpuLimitsnocpu limits for the container"1000m"
memoryLimitsnomemory limits for the container"512Mi"

Disable Azure Policy Add-on

Option 1

  • Update apimodel.json and set azure-policy addon enabled to false.
  • Run aks-engine-azurestack upgrade with the updated apimodel.json
  • Run kubectl delete deployments.apps -n kube-system gatekeeper-controller-manager azure-policy to remove running deployments and pods

Option 2

  • SSH into AKS-Engine Kubernetes master node
  • Run kubectl delete -f /etc/kubernetes/addons/azure-policy-deployment.yaml && sudo rm /etc/kubernetes/addons/azure-policy-deployment.yaml to remove all resources created by addon

Supported Orchestrators

Kubernetes

Contact