Bylaw

Gallery › Security Center › Azure built-in policies

Azure running container images should have vulnerabilities resolved (powered by Microsoft Defender Vulnerability Management)

Converted Policy AuditIfNotExists Disabled Mode Indexed Version 1.0.1

Container image vulnerability assessment scans your registry for commonly known vulnerabilities (CVEs) and provides a detailed vulnerability report for each image. This recommendation provides visibility to vulnerable images currently running in your Kubernetes clusters. Remediating vulnerabilities in container images that are currently running is key to improving your security posture, significantly reducing the attack surface for your containerized workloads.

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

Azure Policy JSONMDC_K8sRuningImagesVulnerabilityAssessmentBasedOnMDVM_Audit.json · 55 lines
{
  "properties": {
    "displayName": "Azure running container images should have vulnerabilities resolved (powered by Microsoft Defender Vulnerability Management)",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Container image vulnerability assessment scans your registry for commonly known vulnerabilities (CVEs) and provides a detailed vulnerability report for each image. This recommendation provides visibility to vulnerable images currently running in your Kubernetes clusters. Remediating vulnerabilities in container images that are currently running is key to improving your security posture, significantly reducing the attack surface for your containerized workloads.",
    "metadata": {
      "version": "1.0.1",
      "category": "Security Center"
    },
    "version": "1.0.1",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "defaultValue": "AuditIfNotExists"
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "in": [
          "Microsoft.ContainerService/managedClusters"
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Security/assessments",
          "name": "c609cf0f-71ab-41e9-a3c6-9a1f7fe1b8d5",
          "existenceCondition": {
            "field": "Microsoft.Security/assessments/status.code",
            "in": [
              "NotApplicable",
              "Healthy"
            ]
          }
        }
      }
    },
    "versions": [
      "1.0.1",
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/17f4b1cc-c55c-4d94-b1f9-2978f6ac2957",
  "name": "17f4b1cc-c55c-4d94-b1f9-2978f6ac2957"
}
Bylaw17f4b1cc-c55c-4d94-b1f9-2978f6ac2957.bylaw.ps1 · 32 lines
# Converted from MDC_K8sRuningImagesVulnerabilityAssessmentBasedOnMDVM_Audit.json by ConvertTo-Bylaw.
Policy '17f4b1cc-c55c-4d94-b1f9-2978f6ac2957' {

    Properties @{
        DisplayName   = 'Azure running container images should have vulnerabilities resolved (powered by Microsoft Defender Vulnerability Management)'
        Description   = 'Container image vulnerability assessment scans your registry for commonly known vulnerabilities (CVEs) and provides a detailed vulnerability report for each image. This recommendation provides visibility to vulnerable images currently running in your Kubernetes clusters. Remediating vulnerabilities in container images that are currently running is key to improving your security posture, significantly reducing the attack surface for your containerized workloads.'
        Version       = '1.0.1'
        Category      = 'Security Center'
        PolicyVersion = '1.0.1'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('AuditIfNotExists', 'Disabled')
        Default       = 'AuditIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource * {

        Require 'type is not one of 1 value' {
            Field type | Must -Not -BeIn @('Microsoft.ContainerService/managedClusters') -IfPresent
        }
    }

    AuditIfNotExists 'Microsoft.Security/assessments' -Name 'c609cf0f-71ab-41e9-a3c6-9a1f7fe1b8d5' -Effect (Param Effect) {
        Require 'status.code is one of 2 values' {
            Field status.code | Must -BeIn @('NotApplicable', 'Healthy')
        }
    }
}

Source: built-in-policies/policyDefinitions/Security Center/MDC_K8sRuningImagesVulnerabilityAssessmentBasedOnMDVM_Audit.json in Azure/azure-policy, under the MIT licence.