Bylaw

Gallery › App Service › Azure Community Policy

Remote Debugging disabled deploy for App Service

Converted Policy AuditIfNotExists DeployIfNotExists Disabled Mode Indexed Version 1.1.0

Remote Debugging disabled deploy for App Service

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

Azure Policy JSONazurepolicy.json · 93 lines
{
  "name": "d55c0177-f092-4797-82ef-cb2ec89cf527",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Remote Debugging disabled deploy for App Service",
    "description": "Remote Debugging disabled deploy for App Service",
    "metadata": {
      "version": "1.1.0",
      "category": "App Service"
    },
    "mode": "Indexed",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "DeployIfNotExists, AuditIfNotExists or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "DeployIfNotExists",
          "AuditIfNotExists",
          "Disabled"
        ],
        "defaultValue": "DeployIfNotExists"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Web/sites"
          },
          {
            "field": "kind",
            "like": "app*"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Web/sites/config",
          "roleDefinitionIds": [
            "/providers/microsoft.authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
          ],
          "existenceCondition": {
            "field": "Microsoft.Web/sites/config/web.remoteDebuggingEnabled",
            "equals": "true"
          },
          "deployment": {
            "properties": {
              "mode": "incremental",
              "template": {
                "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {
                  "appName": {
                    "type": "string"
                  },
                  "location": {
                    "type": "string"
                  }
                },
                "resources": [
                  {
                    "name": "[parameters('appName')]",
                    "type": "Microsoft.Web/sites",
                    "apiVersion": "2016-08-01",
                    "location": "[parameters('location')]",
                    "properties": {
                      "siteConfig": {
                        "remoteDebuggingEnabled": "false"
                      }
                    }
                  }
                ]
              },
              "parameters": {
                "appName": {
                  "value": "[field('name')]"
                },
                "location": {
                  "value": "[field('location')]"
                }
              }
            }
          }
        }
      }
    }
  }
}
Bylawd55c0177-f092-4797-82ef-cb2ec89cf527.bylaw.ps1 · 35 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'd55c0177-f092-4797-82ef-cb2ec89cf527' {

    Properties @{
        DisplayName = 'Remote Debugging disabled deploy for App Service'
        Description = 'Remote Debugging disabled deploy for App Service'
        Version     = '1.1.0'
        Category    = 'App Service'
        Mode        = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('DeployIfNotExists', 'AuditIfNotExists', 'Disabled')
        Default       = 'DeployIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'DeployIfNotExists, AuditIfNotExists or Disabled the execution of the Policy'
    }

    Resource 'Microsoft.Web/sites' {

        Require 'kind is not like app*' {
            Field kind | Must -Not -BeLike 'app*' -IfPresent
        }
    }

    DeployIfNotExists 'Microsoft.Web/sites/config' -Role 'Contributor' -Effect (Param Effect) {
        Require 'web.remoteDebuggingEnabled is true' {
            Field web.remoteDebuggingEnabled | Must -Be 'true'
        }
        Deployment -TemplateFile './templates/d55c0177-f092-4797-82ef-cb2ec89cf527.json' -Parameters ([ordered]@{
                appName  = (Arm '[field(''name'')]')
                location = (Arm '[field(''location'')]')
            })
    }
}

Its deployment templates are written beside it:

Source: policyDefinitions/App Service/remote-debugging-disabled-deploy-for-app-service/azurepolicy.json in Azure/Community-Policy, under the MIT licence.