Bylaw

Gallery › General › Azure built-in policies

Users must authenticate with multi-factor authentication to create or update resources

Uses Condition Policy Audit Deny Disabled Mode All Version 1.1.0

This policy definition blocks resource create and update operations when the caller is not authenticated via MFA. For more information, visit https://aka.ms/mfaforazure.

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 JSONMFA_Deny.json · 60 lines
{
  "properties": {
    "displayName": "Users must authenticate with multi-factor authentication to create or update resources",
    "policyType": "BuiltIn",
    "mode": "All",
    "description": "This policy definition blocks resource create and update operations when the caller is not authenticated via MFA. For more information, visit https://aka.ms/mfaforazure.",
    "metadata": {
      "version": "1.1.0",
      "category": "General"
    },
    "version": "1.1.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "The desired effect of the policy"
        },
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "value": "[contains(requestContext().identity, 'idtyp')]",
            "equals": true
          },
          {
            "value": "[requestContext().identity.idtyp]",
            "equals": "user"
          },
          {
            "value": "mfa",
            "notIn": "[split(tryGet(requestContext().identity, 'http://schemas.microsoft.com/claims/authnmethodsreferences'), ',')]"
          },
          {
            "value": "p1",
            "notIn": "[split(requestContext().identity.acrs, ',')]"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.1.0",
      "1.0.1",
      "1.0.0-PREVIEW"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/4e6c27d5-a6ee-49cf-b2b4-d8fe90fa2b8b",
  "name": "4e6c27d5-a6ee-49cf-b2b4-d8fe90fa2b8b"
}
Bylaw4e6c27d5-a6ee-49cf-b2b4-d8fe90fa2b8b.bylaw.ps1 · 34 lines
# Converted from MFA_Deny.json by ConvertTo-Bylaw.
Policy '4e6c27d5-a6ee-49cf-b2b4-d8fe90fa2b8b' {

    Properties @{
        DisplayName   = 'Users must authenticate with multi-factor authentication to create or update resources'
        Description   = 'This policy definition blocks resource create and update operations when the caller is not authenticated via MFA. For more information, visit https://aka.ms/mfaforazure.'
        Version       = '1.1.0'
        Category      = 'General'
        PolicyVersion = '1.1.0'
        Mode          = 'All'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Deny', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'The desired effect of the policy'
    }

    Resource * {

        When {
            Arm '[contains(requestContext().identity, ''idtyp'')]' | Must -Be $true
            Arm '[requestContext().identity.idtyp]' | Must -Be 'user'
            Condition '{ "value": "mfa", "notIn": "[split(tryGet(requestContext().identity, ''http://schemas.microsoft.com/claims/authnmethodsreferences''), '','')]" }'
        }

        Require 'Requirement 1' {
            Condition -Violation '{ "value": "p1", "notIn": "[split(requestContext().identity.acrs, '','')]" }'
        }
    }

    Effect (Param Effect)
}

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