Bylaw

Gallery › Authorization › Azure Community Policy

Allowed Principal Ids

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

This policy defines an allow list of Principal IDs that can be used in IAM

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

Azure Policy JSONazurepolicy.json · 54 lines
{
  "name": "294c1b68-0e15-4b02-bad3-801d0339bb9b",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Allowed Principal Ids",
    "description": "This policy defines an allow list of Principal IDs that can be used in IAM",
    "metadata": {
      "version": "1.0.0",
      "category": "Authorization"
    },
    "mode": "All",
    "parameters": {
      "principalIds": {
        "type": "array",
        "metadata": {
          "description": "The list of allowed Principal IDs. Enter in semi-colon ';' separated list.",
          "displayName": "Allowed Principal IDs"
        }
      },
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Deny, Audit or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Deny",
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Authorization/roleAssignments"
          },
          {
            "not": {
              "field": "Microsoft.Authorization/roleAssignments/principalId",
              "in": "[parameters('principalIds')]"
            }
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw294c1b68-0e15-4b02-bad3-801d0339bb9b.bylaw.ps1 · 32 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '294c1b68-0e15-4b02-bad3-801d0339bb9b' {

    Properties @{
        DisplayName = 'Allowed Principal Ids'
        Description = 'This policy defines an allow list of Principal IDs that can be used in IAM'
        Version     = '1.0.0'
        Category    = 'Authorization'
        Mode        = 'All'
    }

    Parameter PrincipalIds @{
        Type        = 'array'
        DisplayName = 'Allowed Principal IDs'
        Description = 'The list of allowed Principal IDs. Enter in semi-colon '';'' separated list.'
    }
    Parameter Effect @{
        AllowedValues = @('Deny', 'Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Deny, Audit or Disabled the execution of the Policy'
    }

    Resource 'Microsoft.Authorization/roleAssignments' {

        Require 'principalId is one of the PrincipalIds parameter' {
            Field principalId | Must -BeIn (Param PrincipalIds)
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Authorization/allowed-principal-ids/azurepolicy.json in Azure/Community-Policy, under the MIT licence.