Bylaw

Gallery › Kubernetes › Azure Community Policy

Enforce AKS network plugin

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0

This policy enforces network plugin for AKS.

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

Azure Policy JSONazurepolicy.json · 56 lines
{
  "name": "3af005dd-7bc6-4fb0-b8f3-8b2a519a9853",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Enforce AKS network plugin",
    "description": "This policy enforces network plugin for AKS.",
    "metadata": {
      "category": "Kubernetes",
      "createdBy": "",
      "updatedBy": null,
      "updatedOn": null,
      "version": "1.0.0"
    },
    "mode": "Indexed",
    "parameters": {
      "networkPlugin": {
        "type": "String",
        "metadata": {
          "description": "The network plugin used for building Kubernetes network.",
          "displayName": "Network Plugin"
        },
        "defaultValue": "azure"
      },
      "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.networkPlugin",
            "notEquals": "[parameters('networkPlugin')]"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw3af005dd-7bc6-4fb0-b8f3-8b2a519a9853.bylaw.ps1 · 32 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '3af005dd-7bc6-4fb0-b8f3-8b2a519a9853' {

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

    Parameter NetworkPlugin @{
        Default     = 'azure'
        DisplayName = 'Network Plugin'
        Description = 'The network plugin used for building Kubernetes network.'
    }
    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.networkPlugin is the NetworkPlugin parameter' {
            Field networkProfile.networkPlugin | Must -Be (Param NetworkPlugin)
        }
    }

    Effect (Param Effect)
}

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