Gallery › Kubernetes › Azure Community Policy
Append AKS API IP Restrictions
Doesn't convert yet Policy Append Audit Deny Disabled Mode Indexed Version 1.1.0
This policy will restrict access to the AKS API server as documented here: https://docs.microsoft.com/en-us/azure/aks/api-server-authorized-ip-ranges
ConvertTo-Bylaw can't convert this policy yet:
- BYL6003 The converted file doesn't compile, which is a ConvertTo-Bylaw bug: BYL3072: Effect parameter 'Effect' of an Append policy allows 'Deny'. Allowed values: Append, Disabled. BYL3072: Effect parameter 'Effect' of an Append policy allows 'Audit'. Allowed values: Append, Disabled.
Azure Policy JSONazurepolicy.json · 74 lines
{
"name": "0533f5f7-f3ac-4c10-9823-c5812a1476f9",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Append AKS API IP Restrictions",
"description": "This policy will restrict access to the AKS API server as documented here: https://docs.microsoft.com/en-us/azure/aks/api-server-authorized-ip-ranges",
"metadata": {
"category": "Kubernetes",
"version": "1.1.0"
},
"mode": "Indexed",
"parameters": {
"listOfAllowedIps": {
"type": "Array",
"metadata": {
"displayName": "Allowed IP's",
"description": "A list of IP's that are allowed to access the AKS API server."
}
},
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Append, Deny, Audit or Disable the execution of the Policy"
},
"allowedValues": ["Append", "Deny", "Audit", "Disabled"],
"defaultValue": "Append"
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.ContainerService/managedClusters"
},
{
"anyOf": [
{
"field": "Microsoft.ContainerService/managedClusters/apiServerAccessProfile.authorizedIPRanges",
"exists": "false"
},
{
"count": {
"field": "Microsoft.ContainerService/managedClusters/apiServerAccessProfile.authorizedIPRanges[*]",
"where": {
"field": "Microsoft.ContainerService/managedClusters/apiServerAccessProfile.authorizedIPRanges[*]",
"in": "[parameters('listOfAllowedIps')]"
}
},
"less": "[length(parameters('listOfAllowedIps'))]"
},
{
"count": {
"field": "Microsoft.ContainerService/managedClusters/apiServerAccessProfile.authorizedIPRanges[*]"
},
"notEquals": "[length(parameters('listOfAllowedIps'))]"
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": [
{
"field": "Microsoft.ContainerService/managedClusters/apiServerAccessProfile.authorizedIPRanges",
"value": "[parameters('listOfAllowedIps')]"
}
]
}
}
}
}Source: policyDefinitions/Kubernetes/append-aks-api-ip-restrictions/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw