Bylaw

Gallery › Kubernetes › Azure built-in policies

[Preview]: [Preview]: Use Image Integrity to ensure only trusted images are deployed

Converted Initiative Version 1.1.0-preview Preview

Use Image Integrity to ensure AKS clusters deploy only trusted images by enabling the Image Integrity and Azure Policy Add-Ons on AKS clusters. Image Integrity Add-On and Azure Policy Add-On are both pre-requisites to using Image Integrity to verify if image is signed upon deployment. For more info, visit https://aka.ms/aks/image-integrity.

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

Azure Policy JSONAKS_ImageIntegrity.json · 153 lines
{
  "properties": {
    "displayName": "[Preview]: [Preview]: Use Image Integrity to ensure only trusted images are deployed",
    "policyType": "BuiltIn",
    "description": "Use Image Integrity to ensure AKS clusters deploy only trusted images by enabling the Image Integrity and Azure Policy Add-Ons on AKS clusters. Image Integrity Add-On and Azure Policy Add-On are both pre-requisites to using Image Integrity to verify if image is signed upon deployment. For more info, visit https://aka.ms/aks/image-integrity.",
    "metadata": {
      "version": "1.1.0-preview",
      "category": "Kubernetes",
      "preview": true
    },
    "version": "1.1.0-preview",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "verification effect",
          "description": "Enable the image integrity and verification polices"
        },
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      },
      "excludedNamespaces": {
        "type": "Array",
        "metadata": {
          "displayName": "Namespace exclusions",
          "description": "List of Kubernetes namespaces to exclude from policy evaluation."
        },
        "defaultValue": [
          "kube-system",
          "gatekeeper-system",
          "azure-arc",
          "azure-extensions-usage-system"
        ]
      },
      "excludedImages": {
        "type": "Array",
        "metadata": {
          "displayName": "Image exclusions",
          "description": "The list of InitContainers and Containers to exclude from policy evaluation. The identifier is the image of container. Prefix-matching can be signified with `*`. For example: `myregistry.azurecr.io/istio:*`. It is recommended that users use the fully-qualified Docker image name (e.g. start with a domain name) in order to avoid unexpectedly exempting images from an untrusted repository."
        },
        "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
        }
      }
    },
    "policyDefinitions": [
      {
        "policyDefinitionReferenceId": "deployAKSImageIntegrity",
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/5dc99dae-cfb2-42cc-8762-9aae02b74e27",
        "definitionVersion": "1.*.*-preview",
        "parameters": {
          "effect": {
            "value": "[if(equals(parameters('effect'), 'Disabled'), 'Disabled', 'DeployIfNotExists')]"
          }
        }
      },
      {
        "policyDefinitionReferenceId": "deployAKSPolicyAddOn",
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/a8eff44f-8c92-45c3-a3fb-9880802d67a7",
        "definitionVersion": "4.*.*",
        "parameters": {
          "effect": {
            "value": "[if(equals(parameters('effect'), 'Disabled'), 'Disabled', 'DeployIfNotExists')]"
          }
        }
      },
      {
        "policyDefinitionReferenceId": "imageIntegrityNotationVerification",
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/cf426bb8-b320-4321-8545-1b784a5df3a4",
        "definitionVersion": "1.*.*-preview",
        "parameters": {
          "effect": {
            "value": "[parameters('effect')]"
          },
          "excludedNamespaces": {
            "value": "[parameters('excludedNamespaces')]"
          },
          "excludedImages": {
            "value": "[parameters('excludedImages')]"
          },
          "labelSelector": {
            "value": "[parameters('labelSelector')]"
          }
        }
      }
    ],
    "versions": [
      "1.1.0-PREVIEW"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policySetDefinitions/af28bf8b-c669-4dd3-9137-1e68fdc61bd6",
  "name": "af28bf8b-c669-4dd3-9137-1e68fdc61bd6"
}
Bylawaf28bf8b-c669-4dd3-9137-1e68fdc61bd6.bylaw.ps1 · 106 lines
# Converted from AKS_ImageIntegrity.json by ConvertTo-Bylaw.
Initiative 'af28bf8b-c669-4dd3-9137-1e68fdc61bd6' {

    Properties @{
        DisplayName   = '[Preview]: [Preview]: Use Image Integrity to ensure only trusted images are deployed'
        Description   = 'Use Image Integrity to ensure AKS clusters deploy only trusted images by enabling the Image Integrity and Azure Policy Add-Ons on AKS clusters. Image Integrity Add-On and Azure Policy Add-On are both pre-requisites to using Image Integrity to verify if image is signed upon deployment. For more info, visit https://aka.ms/aks/image-integrity.'
        Version       = '1.1.0-preview'
        Category      = 'Kubernetes'
        Preview       = $true
        PolicyVersion = '1.1.0-preview'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'verification effect'
        Description   = 'Enable the image integrity and verification polices'
    }
    Parameter ExcludedNamespaces @{
        Type        = 'Array'
        Default     = @('kube-system', 'gatekeeper-system', 'azure-arc', 'azure-extensions-usage-system')
        DisplayName = 'Namespace exclusions'
        Description = 'List of Kubernetes namespaces to exclude from policy evaluation.'
    }
    Parameter ExcludedImages @{
        Type        = 'Array'
        Default     = @()
        DisplayName = 'Image exclusions'
        Description = 'The list of InitContainers and Containers to exclude from policy evaluation. The identifier is the image of container. Prefix-matching can be signified with `*`. For example: `myregistry.azurecr.io/istio:*`. It is recommended that users use the fully-qualified Docker image name (e.g. start with a domain name) in order to avoid unexpectedly exempting images from an untrusted repository.'
    }
    Parameter LabelSelector @{
        Type        = 'object'
        Default     = [ordered]@{  }
        DisplayName = 'Kubernetes label selector'
        Description = 'Label query to select Kubernetes resources for policy evaluation. An empty label selector matches all Kubernetes resources.'
        Schema      = [ordered]@{
            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 = [ordered]@{
                matchLabels = [ordered]@{
                    description = 'matchLabels is a map of {key,value} pairs.'
                    type = 'object'
                    additionalProperties = [ordered]@{ type = 'string' }
                    minProperties = 1
                }
                matchExpressions = [ordered]@{
                    description = 'matchExpressions is a list of values, a key, and an operator.'
                    type = 'array'
                    items = [ordered]@{
                        type = 'object'
                        properties = [ordered]@{
                            key = [ordered]@{
                                description = 'key is the label key that the selector applies to.'
                                type = 'string'
                            }
                            operator = [ordered]@{
                                description = 'operator represents a key''s relationship to a set of values.'
                                type = 'string'
                                enum = @('In', 'NotIn', 'Exists', 'DoesNotExist')
                            }
                            values = [ordered]@{
                                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 = [ordered]@{ type = 'string' }
                            }
                        }
                        required = @('key', 'operator')
                        additionalProperties = $false
                    }
                    minItems = 1
                }
            }
            additionalProperties = $false
        }
    }

    PolicyDefinition @{
        Id          = '5dc99dae-cfb2-42cc-8762-9aae02b74e27'
        ReferenceId = 'deployAKSImageIntegrity'
        Version     = '1.*.*-preview'
        Parameters  = @{
            effect = (Arm '[if(equals(parameters(''effect''), ''Disabled''), ''Disabled'', ''DeployIfNotExists'')]')
        }
    }

    PolicyDefinition @{
        Id          = 'a8eff44f-8c92-45c3-a3fb-9880802d67a7'
        ReferenceId = 'deployAKSPolicyAddOn'
        Version     = '4.*.*'
        Parameters  = @{
            effect = (Arm '[if(equals(parameters(''effect''), ''Disabled''), ''Disabled'', ''DeployIfNotExists'')]')
        }
    }

    PolicyDefinition @{
        Id          = 'cf426bb8-b320-4321-8545-1b784a5df3a4'
        ReferenceId = 'imageIntegrityNotationVerification'
        Version     = '1.*.*-preview'
        Parameters  = [ordered]@{
            effect             = (Param Effect)
            excludedNamespaces = (Param ExcludedNamespaces)
            excludedImages     = (Param ExcludedImages)
            labelSelector      = (Param LabelSelector)
        }
    }
}

Members (3)

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