Bylaw

Gallery › App Service › Azure Community Policy

Latest TLS version should be used in your Function App

Converted Policy AuditIfNotExists DeployIfNotExists Disabled Mode Indexed Version 1.0.0

Upgrade to the latest TLS version

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

Azure Policy JSONazurepolicy.json · 85 lines
{
  "name": "82a02e3d-4d2b-4ac6-87fe-ed00c292b78c",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Latest TLS version should be used in your Function App",
    "description": "Upgrade to the latest TLS version",
    "metadata": {
      "version": "1.0.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",
            "contains": "functionapp"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Web/sites/config",
          "name": "web",
          "existenceCondition": {
            "field": "Microsoft.Web/sites/config/minTlsVersion",
            "equals": "1.2"
          },
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/de139f84-1756-47ae-9be6-808fbbe84772"
          ],
          "deployment": {
            "properties": {
              "mode": "incremental",
              "parameters": {
                "name": {
                  "value": "[field('name')]"
                }
              },
              "template": {
                "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {
                  "name": {
                    "type": "string"
                  }
                },
                "resources": [
                  {
                    "name": "[concat(parameters('name'), '/web')]",
                    "type": "Microsoft.Web/sites/config",
                    "apiVersion": "2018-11-01",
                    "properties": {
                      "minTlsVersion": "1.2"
                    }
                  }
                ]
              }
            }
          }
        }
      }
    }
  }
}
Bylaw82a02e3d-4d2b-4ac6-87fe-ed00c292b78c.bylaw.ps1 · 34 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '82a02e3d-4d2b-4ac6-87fe-ed00c292b78c' {

    Properties @{
        DisplayName = 'Latest TLS version should be used in your Function App'
        Description = 'Upgrade to the latest TLS version'
        Version     = '1.0.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 does not contain functionapp' {
            Field kind | Must -Not -ContainText 'functionapp' -IfPresent
        }
    }

    DeployIfNotExists 'Microsoft.Web/sites/config' -Role 'Website Contributor' -Name 'web' -Effect (Param Effect) {
        Require 'minTlsVersion is 1.2' {
            Field minTlsVersion | Must -Be '1.2'
        }
        Deployment -TemplateFile './templates/82a02e3d-4d2b-4ac6-87fe-ed00c292b78c.json' -Parameters ([ordered]@{
                name = (Arm '[field(''name'')]')
            })
    }
}

Its deployment templates are written beside it:

Source: policyDefinitions/App Service/latest-tls-version-should-be-used-in-your-function-app/azurepolicy.json in Azure/Community-Policy, under the MIT licence.