Bylaw

Gallery › Kubernetes › Azure built-in policies

Azure Kubernetes Clusters should disable SSH

Converted Policy Audit Disabled Mode Indexed Version 1.1.0

Disable SSH gives you the ability to secure your cluster and reduce the attack surface. To learn more, visit: aka.ms/aks/disablessh

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

Azure Policy JSONAKS_DisableSSH_Audit.json · 77 lines
{
  "properties": {
    "displayName": "Azure Kubernetes Clusters should disable SSH",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Disable SSH gives you the ability to secure your cluster and reduce the attack surface. To learn more, visit: aka.ms/aks/disablessh",
    "metadata": {
      "version": "1.1.0",
      "category": "Kubernetes"
    },
    "version": "1.1.0",
    "parameters": {
      "effect": {
        "type": "String",
        "defaultValue": "Audit",
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy",
          "portalReview": true
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.ContainerService/managedClusters"
          },
          {
            "count": {
              "field": "Microsoft.ContainerService/managedClusters/agentPoolProfiles[*]",
              "where": {
                "allOf": [
                  {
                    "value": "[coalesce(tryGet(current('Microsoft.ContainerService/managedClusters/agentPoolProfiles[*]'), 'mode'), '')]",
                    "notEquals": "Machines"
                  },
                  {
                    "value": "[coalesce(tryGet(current('Microsoft.ContainerService/managedClusters/agentPoolProfiles[*]'), 'type'), '')]",
                    "notEquals": "FlexNodes"
                  },
                  {
                    "anyOf": [
                      {
                        "field": "Microsoft.ContainerService/managedClusters/agentPoolProfiles[*].securityProfile.sshAccess",
                        "exists": "False"
                      },
                      {
                        "field": "Microsoft.ContainerService/managedClusters/agentPoolProfiles[*].securityProfile.sshAccess",
                        "equals": "localuser"
                      }
                    ]
                  }
                ]
              }
            },
            "greater": 0
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.1.0",
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/28257686-e9db-403e-b9e2-a5eecbe03da9",
  "name": "28257686-e9db-403e-b9e2-a5eecbe03da9"
}
Bylaw28257686-e9db-403e-b9e2-a5eecbe03da9.bylaw.ps1 · 36 lines
# Converted from AKS_DisableSSH_Audit.json by ConvertTo-Bylaw.
Policy '28257686-e9db-403e-b9e2-a5eecbe03da9' {

    Properties @{
        DisplayName   = 'Azure Kubernetes Clusters should disable SSH'
        Description   = 'Disable SSH gives you the ability to secure your cluster and reduce the attack surface. To learn more, visit: aka.ms/aks/disablessh'
        Version       = '1.1.0'
        Category      = 'Kubernetes'
        PolicyVersion = '1.1.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
        Metadata      = [ordered]@{ portalReview = $true }
    }

    Resource 'Microsoft.ContainerService/managedClusters' {

        Require 'agentPoolProfiles and securityProfile.sshAccess are as required' {
            Count 'agentPoolProfiles[*]' -Where {
                Arm '[coalesce(tryGet(current(''Microsoft.ContainerService/managedClusters/agentPoolProfiles[*]''), ''mode''), '''')]' | Must -Not -Be 'Machines'
                Arm '[coalesce(tryGet(current(''Microsoft.ContainerService/managedClusters/agentPoolProfiles[*]''), ''type''), '''')]' | Must -Not -Be 'FlexNodes'
                AnyOf {
                    Field securityProfile.sshAccess | Must -Not -Exist
                    Field securityProfile.sshAccess | Must -Be 'localuser'
                }
            } | Must -Be 0
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/Kubernetes/AKS_DisableSSH_Audit.json in Azure/azure-policy, under the MIT licence.