Bylaw

Gallery › Mission › Azure built-in policies

App Service apps should restrict site access rules to specified sources in Mission Platform products and services

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0

This policy applies exclusively to Mission Platform products and services; usage outside of these scopes is not supported. Restrict Site Access Rules to Specified Sources.

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

Azure Policy JSONAppRestrictSiteAccessRules_Audit.json · 130 lines
{
  "properties": {
    "displayName": "App Service apps should restrict site access rules to specified sources in Mission Platform products and services",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "This policy applies exclusively to Mission Platform products and services; usage outside of these scopes is not supported. Restrict Site Access Rules to Specified Sources.",
    "metadata": {
      "version": "1.0.0",
      "category": "Mission"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "defaultValue": "Audit"
      },
      "allowedServiceTags": {
        "type": "Array",
        "metadata": {
          "displayName": "Allowed Service Tags",
          "description": " List of allowed Service Tags."
        },
        "defaultValue": []
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Web/sites"
          },
          {
            "anyOf": [
              {
                "count": {
                  "field": "Microsoft.Web/sites/siteConfig.ipSecurityRestrictions[*]",
                  "where": {
                    "not": {
                      "anyOf": [
                        {
                          "allOf": [
                            {
                              "value": "[current('Microsoft.Web/sites/siteConfig.ipSecurityRestrictions[*].tag')]",
                              "equals": "ServiceTag"
                            },
                            {
                              "value": "[current('Microsoft.Web/sites/siteConfig.ipSecurityRestrictions[*].ipAddress')]",
                              "in": "[parameters('allowedServiceTags')]"
                            }
                          ]
                        },
                        {
                          "allOf": [
                            {
                              "value": "[current('Microsoft.Web/sites/siteConfig.ipSecurityRestrictions[*].Action')]",
                              "equals": "Deny"
                            },
                            {
                              "value": "[current('Microsoft.Web/sites/siteConfig.ipSecurityRestrictions[*].ipAddress')]",
                              "equals": "Any"
                            }
                          ]
                        }
                      ]
                    }
                  }
                },
                "greater": 0
              },
              {
                "count": {
                  "field": "Microsoft.Web/sites/siteConfig.scmIpSecurityRestrictions[*]",
                  "where": {
                    "not": {
                      "anyOf": [
                        {
                          "allOf": [
                            {
                              "value": "[current('Microsoft.Web/sites/siteConfig.scmIpSecurityRestrictions[*].tag')]",
                              "equals": "ServiceTag"
                            },
                            {
                              "value": "[current('Microsoft.Web/sites/siteConfig.scmIpSecurityRestrictions[*].ipAddress')]",
                              "in": "[parameters('allowedServiceTags')]"
                            }
                          ]
                        },
                        {
                          "allOf": [
                            {
                              "value": "[current('Microsoft.Web/sites/siteConfig.scmIpSecurityRestrictions[*].Action')]",
                              "equals": "Deny"
                            },
                            {
                              "value": "[current('Microsoft.Web/sites/siteConfig.scmIpSecurityRestrictions[*].ipAddress')]",
                              "equals": "Any"
                            }
                          ]
                        }
                      ]
                    }
                  }
                },
                "greater": 0
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/f36fcc62-6b1b-46e3-9a94-97af3eb4a55e",
  "name": "f36fcc62-6b1b-46e3-9a94-97af3eb4a55e"
}
Bylawf36fcc62-6b1b-46e3-9a94-97af3eb4a55e.bylaw.ps1 · 56 lines
# Converted from AppRestrictSiteAccessRules_Audit.json by ConvertTo-Bylaw.
Policy 'f36fcc62-6b1b-46e3-9a94-97af3eb4a55e' {

    Properties @{
        DisplayName   = 'App Service apps should restrict site access rules to specified sources in Mission Platform products and services'
        Description   = 'This policy applies exclusively to Mission Platform products and services; usage outside of these scopes is not supported. Restrict Site Access Rules to Specified Sources.'
        Version       = '1.0.0'
        Category      = 'Mission'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Deny', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }
    Parameter AllowedServiceTags @{
        Type        = 'Array'
        Default     = @()
        DisplayName = 'Allowed Service Tags'
        Description = ' List of allowed Service Tags.'
    }

    Resource 'Microsoft.Web/sites' {

        Require 'siteConfig.ipSecurityRestrictions is as required' {
            Count 'siteConfig.ipSecurityRestrictions[*]' -Where {
                AnyOf {
                    Arm '[current(''Microsoft.Web/sites/siteConfig.ipSecurityRestrictions[*].tag'')]' | Must -Not -Be 'ServiceTag'
                    Arm '[current(''Microsoft.Web/sites/siteConfig.ipSecurityRestrictions[*].ipAddress'')]' | Must -Not -BeIn (Param AllowedServiceTags)
                }
                AnyOf {
                    Arm '[current(''Microsoft.Web/sites/siteConfig.ipSecurityRestrictions[*].Action'')]' | Must -Not -Be 'Deny'
                    Arm '[current(''Microsoft.Web/sites/siteConfig.ipSecurityRestrictions[*].ipAddress'')]' | Must -Not -Be 'Any'
                }
            } | Must -Be 0
        }

        Require 'siteConfig.scmIpSecurityRestrictions is as required' {
            Count 'siteConfig.scmIpSecurityRestrictions[*]' -Where {
                AnyOf {
                    Arm '[current(''Microsoft.Web/sites/siteConfig.scmIpSecurityRestrictions[*].tag'')]' | Must -Not -Be 'ServiceTag'
                    Arm '[current(''Microsoft.Web/sites/siteConfig.scmIpSecurityRestrictions[*].ipAddress'')]' | Must -Not -BeIn (Param AllowedServiceTags)
                }
                AnyOf {
                    Arm '[current(''Microsoft.Web/sites/siteConfig.scmIpSecurityRestrictions[*].Action'')]' | Must -Not -Be 'Deny'
                    Arm '[current(''Microsoft.Web/sites/siteConfig.scmIpSecurityRestrictions[*].ipAddress'')]' | Must -Not -Be 'Any'
                }
            } | Must -Be 0
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/Mission/AppRestrictSiteAccessRules_Audit.json in Azure/azure-policy, under the MIT licence.