Bylaw

Gallery › Security Center › Azure built-in policies

Authorized IP ranges should be defined on Kubernetes Services

Converted Policy Audit Disabled Mode All Version 2.0.1

Restrict access to the Kubernetes Service Management API by granting API access only to IP addresses in specific ranges. It is recommended to limit access to authorized IP ranges to ensure that only applications from allowed networks can access the cluster.

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

Azure Policy JSONASC_EnableIpRanges_KubernetesService_Audit.json · 61 lines
{
  "properties": {
    "displayName": "Authorized IP ranges should be defined on Kubernetes Services",
    "policyType": "BuiltIn",
    "mode": "All",
    "description": "Restrict access to the Kubernetes Service Management API by granting API access only to IP addresses in specific ranges. It is recommended to limit access to authorized IP ranges to ensure that only applications from allowed networks can access the cluster.",
    "metadata": {
      "version": "2.0.1",
      "category": "Security Center"
    },
    "version": "2.0.1",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "Audit",
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.ContainerService/managedClusters"
          },
          {
            "field": "Microsoft.ContainerService/managedClusters/apiServerAccessProfile.authorizedIPRanges",
            "exists": "false"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.ContainerService/managedClusters/apiServerAccessProfile.enablePrivateCluster",
                "exists": "false"
              },
              {
                "field": "Microsoft.ContainerService/managedClusters/apiServerAccessProfile.enablePrivateCluster",
                "equals": "false"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "2.0.1"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/0e246bcf-5f6f-4f87-bc6f-775d4712c7ea",
  "name": "0e246bcf-5f6f-4f87-bc6f-775d4712c7ea"
}
Bylaw0e246bcf-5f6f-4f87-bc6f-775d4712c7ea.bylaw.ps1 · 37 lines
# Converted from ASC_EnableIpRanges_KubernetesService_Audit.json by ConvertTo-Bylaw.
Policy '0e246bcf-5f6f-4f87-bc6f-775d4712c7ea' {

    Properties @{
        DisplayName   = 'Authorized IP ranges should be defined on Kubernetes Services'
        Description   = 'Restrict access to the Kubernetes Service Management API by granting API access only to IP addresses in specific ranges. It is recommended to limit access to authorized IP ranges to ensure that only applications from allowed networks can access the cluster.'
        Version       = '2.0.1'
        Category      = 'Security Center'
        PolicyVersion = '2.0.1'
        Mode          = 'All'
    }

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

    Resource 'Microsoft.ContainerService/managedClusters' {

        When {
            Field apiServerAccessProfile.authorizedIPRanges | Must -Not -Exist
        }

        Require 'apiServerAccessProfile.enablePrivateCluster exists' {
            Field apiServerAccessProfile.enablePrivateCluster | Must -Exist
        }

        Require 'apiServerAccessProfile.enablePrivateCluster is not false' {
            Field apiServerAccessProfile.enablePrivateCluster | Must -Not -Be 'false' -IfPresent
        }
    }

    Effect (Param Effect)
}

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