Bylaw

Gallery › App Service › Azure Community Policy

Require https only for all App Services

Converted Policy Audit Deny Disabled Mode All Version 1.0.1

Requires the property Microsoft.Web/sites/httpsOnly to be set to true for all App Services.

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

Azure Policy JSONazurepolicy.json · 45 lines
{
  "name": "e0ae173d-4fab-49c6-a313-1958bcd08592",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Require https only for all App Services",
    "description": "Requires the property Microsoft.Web/sites/httpsOnly to be set to true for all App Services.",
    "metadata": {
      "version": "1.0.1",
      "category": "App Service"
    },
    "mode": "All",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Deny, Audit or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Deny",
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Web/sites"
          },
          {
            "field": "Microsoft.Web/sites/httpsOnly",
            "equals": "false"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylawe0ae173d-4fab-49c6-a313-1958bcd08592.bylaw.ps1 · 27 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'e0ae173d-4fab-49c6-a313-1958bcd08592' {

    Properties @{
        DisplayName = 'Require https only for all App Services'
        Description = 'Requires the property Microsoft.Web/sites/httpsOnly to be set to true for all App Services.'
        Version     = '1.0.1'
        Category    = 'App Service'
        Mode        = 'All'
    }

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

    Resource 'Microsoft.Web/sites' {

        Require 'httpsOnly is not false' {
            Field httpsOnly | Must -Not -Be 'false' -IfPresent
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/App Service/require-https-only-for-all-app-services/azurepolicy.json in Azure/Community-Policy, under the MIT licence.