Bylaw

Gallery › Kubernetes › Azure Community Policy

AKS prevent node public ip

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0

This policy prevent node public ip for aks.

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

Azure Policy JSONazurepolicy.json · 62 lines
{
  "name": "82417f79-38c7-4446-ae2c-3c4fd7f06d89",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "AKS prevent node public ip",
    "description": "This policy prevent node public ip for aks.",
    "metadata": {
      "category": "Kubernetes",
      "createdBy": "",
      "updatedBy": null,
      "updatedOn": null,
      "version": "1.0.0"
    },
    "mode": "Indexed",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Deny, Audit or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Deny",
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "equals": "Microsoft.ContainerService/managedClusters",
            "field": "type"
          },
          {
            "count": {
              "field": "Microsoft.ContainerService/managedClusters/agentPoolProfiles[*]",
              "where": {
                "anyOf": [
                  {
                    "exists": "False",
                    "field": "Microsoft.ContainerService/managedClusters/agentPoolProfiles[*].enableNodePublicIP"
                  },
                  {
                    "equals": "true",
                    "field": "Microsoft.ContainerService/managedClusters/agentPoolProfiles[*].enableNodePublicIP"
                  }
                ]
              }
            },
            "greater": 0
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw82417f79-38c7-4446-ae2c-3c4fd7f06d89.bylaw.ps1 · 29 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '82417f79-38c7-4446-ae2c-3c4fd7f06d89' {

    Properties @{
        DisplayName = 'AKS prevent node public ip'
        Description = 'This policy prevent node public ip for aks.'
        Category    = 'Kubernetes'
        Version     = '1.0.0'
        Mode        = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('Deny', 'Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Deny, Audit or Disabled the execution of the Policy'
    }

    Resource 'Microsoft.ContainerService/managedClusters' {

        Require 'agentPoolProfiles and enableNodePublicIP are as required' {
            Each 'agentPoolProfiles[*]' {
                Field enableNodePublicIP | Must -Not -Be 'true' -Strict
            }
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Kubernetes/aks-prevent-node-public-ip/azurepolicy.json in Azure/Community-Policy, under the MIT licence.