Bylaw

Gallery › BuiltInPolicyTest › Azure built-in policies

[Deprecated]: No AKS Specific Labels. Versioning Test BuiltIn.

Doesn't convert yet Policy Audit Deny Disabled Mode Microsoft.Kubernetes.Data Version 2.2.0-deprecated Deprecated

This is a test policy only for internal use by Policy team. Prevents customers from applying AKS specific labels

ConvertTo-Bylaw can't convert this policy yet:

Azure Policy JSONNoAKSSpecificLabels_Versioning_Test.json · 192 lines
{
  "properties": {
    "displayName": "[Deprecated]: No AKS Specific Labels. Versioning Test BuiltIn.",
    "policyType": "BuiltIn",
    "mode": "Microsoft.Kubernetes.Data",
    "description": "This is a test policy only for internal use by Policy team. Prevents customers from applying AKS specific labels",
    "metadata": {
      "version": "2.2.0-deprecated",
      "category": "BuiltInPolicyTest",
      "deprecated": true
    },
    "version": "2.2.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "'audit' allows a non-compliant resource to be created or updated, but flags it as non-compliant. 'deny' blocks the non-compliant resource creation or update. 'disabled' turns off the policy."
        },
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "defaultValue": "Disabled"
      },
      "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": []
      },
      "labelSelector": {
        "type": "Object",
        "metadata": {
          "displayName": "Kubernetes label selector",
          "description": "Label query to select Kubernetes resources for policy evaluation. An empty label selector matches all Kubernetes resources."
        },
        "defaultValue": {},
        "schema": {
          "description": "A label selector is a label query over a set of resources. The result of matchLabels and matchExpressions are ANDed. An empty label selector matches all resources.",
          "type": "object",
          "properties": {
            "matchLabels": {
              "description": "matchLabels is a map of {key,value} pairs.",
              "type": "object",
              "additionalProperties": {
                "type": "string"
              },
              "minProperties": 1
            },
            "matchExpressions": {
              "description": "matchExpressions is a list of values, a key, and an operator.",
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "key": {
                    "description": "key is the label key that the selector applies to.",
                    "type": "string"
                  },
                  "operator": {
                    "description": "operator represents a key's relationship to a set of values.",
                    "type": "string",
                    "enum": [
                      "In",
                      "NotIn",
                      "Exists",
                      "DoesNotExist"
                    ]
                  },
                  "values": {
                    "description": "values is an array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty.",
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                },
                "required": [
                  "key",
                  "operator"
                ],
                "additionalProperties": false
              },
              "minItems": 1
            }
          },
          "additionalProperties": false
        }
      },
      "labelsV2": {
        "type": "Array",
        "metadata": {
          "displayName": "AKS Specific Labels",
          "description": "Labels specific to AKS."
        }
      },
      "allowedUsers": {
        "type": "Array",
        "metadata": {
          "displayName": "Allowed Users",
          "description": "Users that are allowed to use AKS specific labels."
        }
      },
      "allowedGroups": {
        "type": "Array",
        "metadata": {
          "displayName": "Allowed Groups",
          "description": "Groups that are allowed to use AKS specific labels."
        }
      },
      "testString": {
        "metadata": {
          "displayName": "Test string",
          "description": "A string to be compared against 'test' in the policy rule to generate the desired compliance result."
        },
        "type": "string",
        "defaultValue": "test"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "value": "[parameters('testString')]",
            "equals": "test"
          },
          {
            "field": "type",
            "in": [
              "Microsoft.Kubernetes/connectedClusters",
              "Microsoft.ContainerService/managedClusters"
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "templateInfo": {
            "sourceType": "PublicURL",
            "url": "https://store.policy.core.windows.net/kubernetes/restricted-labels/v1/template.yaml"
          },
          "apiGroups": [
            "",
            "apps"
          ],
          "kinds": [
            "Pod",
            "Node",
            "Service",
            "Deployment",
            "StatefulSet",
            "ReplicaSet"
          ],
          "namespaces": "[parameters('namespaces')]",
          "excludedNamespaces": "[parameters('excludedNamespaces')]",
          "labelSelector": "[parameters('labelSelector')]",
          "values": {
            "labels": "[parameters('labelsV2')]",
            "allowedUsers": "[parameters('allowedUsers')]",
            "allowedGroups": "[parameters('allowedGroups')]"
          }
        }
      }
    },
    "versions": [
      "2.2.0",
      "2.1.0",
      "2.0.0",
      "1.1.0",
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/83a0809a-a4e3-4ef2-8a24-2afc156607af",
  "name": "83a0809a-a4e3-4ef2-8a24-2afc156607af"
}

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