last sync: 2021-Jan-25 16:07:05 UTC

Azure Policy definition

Enforce labels on pods in Kubernetes cluster

Name Enforce labels on pods in Kubernetes cluster
Azure Portal
Id 46592696-4c7b-4bf3-9e45-6c2763bdc0a6
Version 5.0.1
details on versioning
Category Kubernetes
Microsoft docs
Description This policy enforces the specified labels are provided for pods in a Kubernetes cluster. This policy is generally available for Kubernetes Service (AKS), and preview for AKS Engine and Azure Arc enabled Kubernetes. For instructions on using this policy, visit https://aka.ms/kubepolicydoc.
Mode Microsoft.Kubernetes.Data
Type BuiltIn
Preview FALSE
Deprecated FALSE
Effect Default: deny
Allowed: (audit, deny, disabled)
Used RBAC Role none
History
Date/Time (UTC ymd) (i) Change type Change detail
2020-12-11 15:42:52 change Major (4.0.1 > 5.0.1)
2020-09-15 14:06:41 change Previous DisplayName: [Preview]: Enforce labels on pods in Kubernetes cluster
2020-04-23 15:06:19 change Previous DisplayName: [Preview]: [AKS Engine] Enforce labels on pods in Kubernetes cluster
2019-10-29 23:04:36 add 46592696-4c7b-4bf3-9e45-6c2763bdc0a6
Used in Initiatives none
JSON Changes

Json
{
  "properties": {
    "displayName": "Enforce labels on pods in Kubernetes cluster",
    "policyType": "BuiltIn",
    "mode": "Microsoft.Kubernetes.Data",
    "description": "This policy enforces the specified labels are provided for pods in a Kubernetes cluster. This policy is generally available for Kubernetes Service (AKS), and preview for AKS Engine and Azure Arc enabled Kubernetes. For instructions on using this policy, visit https://aka.ms/kubepolicydoc.",
    "metadata": {
      "version": "5.0.1",
      "category": "Kubernetes"
    },
    "parameters": {
      "labelsList": {
        "type": "Array",
        "metadata": {
          "displayName": "List of labels",
          "description": "The list of labels to be specified on Pods in a Kubernetes cluster."
        }
      },
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "'Audit' allows a non-compliant resource to be created, but flags it as non-compliant. 'Deny' blocks the resource creation. 'Disable' turns off the policy."
        },
        "allowedValues": [
          "audit",
          "deny",
          "disabled"
        ],
        "defaultValue": "deny"
      },
      "excludedNamespaces": {
        "type": "Array",
        "metadata": {
          "displayName": "Namespace exclusions",
          "description": "List of Kubernetes namespaces to exclude from policy evaluation."
        },
        "defaultValue": [
          "kube-system",
          "gatekeeper-system",
          "azure-arc"
        ]
      },
      "namespaces": {
        "type": "Array",
        "metadata": {
          "displayName": "Namespace inclusions",
          "description": "List of Kubernetes namespaces to only include in policy evaluation. An empty list means the policy is applied to all resources in all namespaces."
        },
        "defaultValue": [
          
        ]
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "in": [
          "AKS Engine",
          "Microsoft.Kubernetes/connectedClusters",
          "Microsoft.ContainerService/managedClusters"
        ]
      },
      "then": {
      "effect": "[parameters('effect')]",
        "details": {
          "constraintTemplate": "https://raw.githubusercontent.com/Azure/azure-policy/master/built-in-references/Kubernetes/pod-enforce-labels/template.yaml",
          "constraint": "https://raw.githubusercontent.com/Azure/azure-policy/master/built-in-references/Kubernetes/pod-enforce-labels/constraint.yaml",
        "excludedNamespaces": "[parameters('excludedNamespaces')]",
        "namespaces": "[parameters('namespaces')]",
          "values": {
          "labels": "[parameters('labelsList')]",
          "excludedNamespaces": "[parameters('excludedNamespaces')]"
          }
        }
      }
    }
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/46592696-4c7b-4bf3-9e45-6c2763bdc0a6",
  "type": "Microsoft.Authorization/policyDefinitions",
  "name": "46592696-4c7b-4bf3-9e45-6c2763bdc0a6"
}