Bylaw

Gallery › App Service › Azure built-in policies

Function app slots should have remote debugging turned off

Converted Policy AuditIfNotExists Disabled Mode Indexed Version 1.1.0

Remote debugging requires inbound ports to be opened on Function apps. Remote debugging should be turned off.

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

Azure Policy JSONDisableRemoteDebugging_FunctionApp_Slot_Audit.json · 65 lines
{
  "properties": {
    "displayName": "Function app slots should have remote debugging turned off",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Remote debugging requires inbound ports to be opened on Function apps. Remote debugging should be turned off.",
    "metadata": {
      "version": "1.1.0",
      "category": "App Service"
    },
    "version": "1.1.0",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "AuditIfNotExists",
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Web/sites/slots"
          },
          {
            "field": "kind",
            "contains": "functionapp"
          },
          {
            "field": "kind",
            "notContains": "workflowapp"
          },
          {
            "field": "kind",
            "notContains": "azurecontainerapps"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Web/sites/slots/config",
          "existenceCondition": {
            "field": "Microsoft.Web/sites/slots/config/web.remoteDebuggingEnabled",
            "equals": "false"
          }
        }
      }
    },
    "versions": [
      "1.1.0",
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/89691ef9-8c50-49a8-8950-9c7fba41699e",
  "name": "89691ef9-8c50-49a8-8950-9c7fba41699e"
}
Bylaw89691ef9-8c50-49a8-8950-9c7fba41699e.bylaw.ps1 · 38 lines
# Converted from DisableRemoteDebugging_FunctionApp_Slot_Audit.json by ConvertTo-Bylaw.
Policy '89691ef9-8c50-49a8-8950-9c7fba41699e' {

    Properties @{
        DisplayName   = 'Function app slots should have remote debugging turned off'
        Description   = 'Remote debugging requires inbound ports to be opened on Function apps. Remote debugging should be turned off.'
        Version       = '1.1.0'
        Category      = 'App Service'
        PolicyVersion = '1.1.0'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.Web/sites/slots' {

        When {
            Field kind | Must -ContainText 'functionapp'
            Field kind | Must -Not -ContainText 'workflowapp'
        }

        Require 'kind contains azurecontainerapps' {
            Field kind | Must -ContainText 'azurecontainerapps'
        }
    }

    AuditIfNotExists 'Microsoft.Web/sites/slots/config' -Effect (Param Effect) {
        Require 'web.remoteDebuggingEnabled is false' {
            Field web.remoteDebuggingEnabled | Must -Be 'false'
        }
    }
}

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