Bylaw

Gallery › App Service › Azure built-in policies

App Service app slots should disable SSH

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0

Azure App Service allows you to open an SSH session to a container running in the service. This feature should be disabled to ensure that SSH is not inadvertently left open on App Service apps, reducing the risk of unauthorized access. Learn more at: https://aka.ms/app-service-ssh

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

Azure Policy JSONWebApp_Slot_SshEnabled_Audit.json · 58 lines
{
  "properties": {
    "displayName": "App Service app slots should disable SSH",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Azure App Service allows you to open an SSH session to a container running in the service. This feature should be disabled to ensure that SSH is not inadvertently left open on App Service apps, reducing the risk of unauthorized access. Learn more at: https://aka.ms/app-service-ssh",
    "metadata": {
      "version": "1.0.0",
      "category": "App Service"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Web/sites/slots"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.Web/sites/slots/sshEnabled",
                "exists": "false"
              },
              {
                "field": "Microsoft.Web/sites/slots/sshEnabled",
                "notEquals": "false"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/a88d589f-2b09-4b50-8998-9a4e71d7b746",
  "name": "a88d589f-2b09-4b50-8998-9a4e71d7b746"
}
Bylawa88d589f-2b09-4b50-8998-9a4e71d7b746.bylaw.ps1 · 32 lines
# Converted from WebApp_Slot_SshEnabled_Audit.json by ConvertTo-Bylaw.
Policy 'a88d589f-2b09-4b50-8998-9a4e71d7b746' {

    Properties @{
        DisplayName   = 'App Service app slots should disable SSH'
        Description   = 'Azure App Service allows you to open an SSH session to a container running in the service. This feature should be disabled to ensure that SSH is not inadvertently left open on App Service apps, reducing the risk of unauthorized access. Learn more at: https://aka.ms/app-service-ssh'
        Version       = '1.0.0'
        Category      = 'App Service'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.Web/sites/slots' {

        Require 'sshEnabled exists' {
            Field sshEnabled | Must -Exist
        }

        Require 'sshEnabled is false' {
            Field sshEnabled | Must -Be 'false'
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/App Service/WebApp_Slot_SshEnabled_Audit.json in Azure/azure-policy, under the MIT licence.