Bylaw

Gallery › Kubernetes › Azure Community Policy

Enforce AKS outbound type

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0

This policy enforces outbound type for AKS.

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

Azure Policy JSONazurepolicy.json · 60 lines
{
  "name": "a6c3dde3-4f8a-4f50-903f-5baeffef93ca",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Enforce AKS outbound type",
    "description": "This policy enforces outbound type for AKS.",
    "metadata": {
      "category": "Kubernetes",
      "createdBy": "",
      "updatedBy": null,
      "updatedOn": null,
      "version": "1.0.0"
    },
    "mode": "Indexed",
    "parameters": {
      "OutboundType": {
        "type": "String",
        "metadata": {
          "description": "The outbound (egress) routing method.",
          "displayName": "Outbound Type"
        },
        "allowedValues": [
          "loadBalancer",
          "userDefinedRouting"
        ],
        "defaultValue": "userDefinedRouting"
      },
      "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"
          },
          {
            "field": "Microsoft.ContainerService/managedClusters/networkProfile.outboundType",
            "notEquals": "[parameters('outboundType')]"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylawa6c3dde3-4f8a-4f50-903f-5baeffef93ca.bylaw.ps1 · 34 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'a6c3dde3-4f8a-4f50-903f-5baeffef93ca' {

    Properties @{
        DisplayName = 'Enforce AKS outbound type'
        Description = 'This policy enforces outbound type for AKS.'
        Category    = 'Kubernetes'
        Version     = '1.0.0'
        Mode        = 'Indexed'
    }

    Parameter OutboundType @{
        AllowedValues = @('loadBalancer', 'userDefinedRouting')
        Default       = 'userDefinedRouting'
        DisplayName   = 'Outbound Type'
        Description   = 'The outbound (egress) routing method.'
        JsonName      = 'OutboundType'
    }
    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 'networkProfile.outboundType is (Arm ''[parameters(''''outboundType'''')]'')' {
            Field networkProfile.outboundType | Must -Be (Arm '[parameters(''outboundType'')]')
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Kubernetes/enforce-aks-outbound-type/azurepolicy.json in Azure/Community-Policy, under the MIT licence.