Bylaw

Gallery › App Service › Azure built-in policies

Configure App Service apps to only be accessible over HTTPS

Converted Policy Disabled Modify Mode Indexed Version 2.0.0

Use of HTTPS ensures server/service authentication and protects data in transit from network layer eavesdropping attacks.

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

Azure Policy JSONWebapp_AuditHTTP_Modify.json · 75 lines
{
  "properties": {
    "displayName": "Configure App Service apps to only be accessible over HTTPS",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Use of HTTPS ensures server/service authentication and protects data in transit from network layer eavesdropping attacks.",
    "metadata": {
      "version": "2.0.0",
      "category": "App Service"
    },
    "version": "2.0.0",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "Modify",
        "allowedValues": [
          "Modify",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "kind",
            "notContains": "functionapp"
          },
          {
            "field": "type",
            "equals": "Microsoft.Web/sites"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.Web/sites/httpsOnly",
                "exists": "false"
              },
              {
                "field": "Microsoft.Web/sites/httpsOnly",
                "equals": "false"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "roleDefinitionIds": [
            "/providers/microsoft.authorization/roleDefinitions/de139f84-1756-47ae-9be6-808fbbe84772"
          ],
          "conflictEffect": "audit",
          "operations": [
            {
              "condition": "[greaterOrEquals(requestContext().apiVersion, '2019-08-01')]",
              "operation": "addOrReplace",
              "field": "Microsoft.Web/sites/httpsOnly",
              "value": true
            }
          ]
        }
      }
    },
    "versions": [
      "2.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/0f98368e-36bc-4716-8ac2-8f8067203b63",
  "name": "0f98368e-36bc-4716-8ac2-8f8067203b63"
}
Bylaw0f98368e-36bc-4716-8ac2-8f8067203b63.bylaw.ps1 · 39 lines
# Converted from Webapp_AuditHTTP_Modify.json by ConvertTo-Bylaw.
Policy '0f98368e-36bc-4716-8ac2-8f8067203b63' {

    Properties @{
        DisplayName   = 'Configure App Service apps to only be accessible over HTTPS'
        Description   = 'Use of HTTPS ensures server/service authentication and protects data in transit from network layer eavesdropping attacks.'
        Version       = '2.0.0'
        Category      = 'App Service'
        PolicyVersion = '2.0.0'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.Web/sites' {

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

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

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

    Modify -Role 'Website Contributor' -ConflictEffect Audit -Effect (Param Effect) {
        Field httpsOnly | AddOrReplace $true -Condition (Arm '[greaterOrEquals(requestContext().apiVersion, ''2019-08-01'')]')
    }
}

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