Bylaw

Gallery › Maps › Azure built-in policies

CORS should not allow every resource to access your map account.

Uses Condition Policy Audit Deny Disabled Mode Indexed Version 1.0.0

Cross-Origin Resource Sharing (CORS) should not allow all domains to access your map account. Allow only required domains to interact with your map account.

ConvertTo-Bylaw converted this policy, and proved it compiles back to the same definition. Conditions the language can't express yet are written as raw JSON with Condition.

Azure Policy JSONRestrictCORSAccess_Audit.json · 67 lines
{
  "properties": {
    "displayName": "CORS should not allow every resource to access your map account.",
    "policyType": "BuiltIn",
    "description": "Cross-Origin Resource Sharing (CORS) should not allow all domains to access your map account. Allow only required domains to interact with your map account.",
    "metadata": {
      "version": "1.0.0",
      "category": "Maps"
    },
    "version": "1.0.0",
    "mode": "Indexed",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "Audit",
        "allowedValues": [
          "Disabled",
          "Audit",
          "Deny"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "The effect determines what happens when the policy rule is evaluated to match"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Maps/accounts"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.Maps/accounts/cors.corsRules[*].allowedOrigins",
                "exists": false
              },
              {
                "count": {
                  "field": "Microsoft.Maps/accounts/cors.corsRules[*].allowedOrigins[*]",
                  "where": {
                    "field": "Microsoft.Maps/accounts/cors.corsRules[*].allowedOrigins[*]",
                    "in": [
                      "*",
                      ""
                    ]
                  }
                },
                "greater": 0
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/50553764-7777-43cf-bf12-8647e0b9ba01",
  "name": "50553764-7777-43cf-bf12-8647e0b9ba01"
}
Bylaw50553764-7777-43cf-bf12-8647e0b9ba01.bylaw.ps1 · 35 lines
# Converted from RestrictCORSAccess_Audit.json by ConvertTo-Bylaw.
Policy '50553764-7777-43cf-bf12-8647e0b9ba01' {

    Properties @{
        DisplayName   = 'CORS should not allow every resource to access your map account.'
        Description   = 'Cross-Origin Resource Sharing (CORS) should not allow all domains to access your map account. Allow only required domains to interact with your map account.'
        Version       = '1.0.0'
        Category      = 'Maps'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        Type          = 'string'
        AllowedValues = @('Disabled', 'Audit', 'Deny')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'The effect determines what happens when the policy rule is evaluated to match'
    }

    Resource 'Microsoft.Maps/accounts' {

        Require 'cors.corsRules and allowedOrigins are as required' {
            Count 'cors.corsRules[*]' -Where {
                Field allowedOrigins | Must -Exist
            } | Must -Not -Be 0
        }

        Require 'cors.corsRules.allowedOrigins is as required' {
            Condition -Violation '{ "count": { "field": "Microsoft.Maps/accounts/cors.corsRules[*].allowedOrigins[*]", "where": { "field": "Microsoft.Maps/accounts/cors.corsRules[*].allowedOrigins[*]", "in": [ "*", "" ] } }, "greater": 0 }'
        }
    }

    Effect (Param Effect)
}

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