Bylaw

Gallery › Authorization › Azure Community Policy

Allowed Role Definitions For Specific Principal IDs

Doesn't convert yet Policy Audit Deny Disabled Mode All Version 1.0.0

This policy defines an allow list of role definitions that can be assigned to specific Principal IDs in IAM. This is useful in the example where you don't want an SPN having it's rights elevated.

ConvertTo-Bylaw can't convert this policy yet:

Azure Policy JSONazurepolicy.json · 66 lines
{
  "name": "3f1bde46-4a10-441d-bb62-c6ffc5ad0d92",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Allowed Role Definitions For Specific Principal IDs",
    "description": "This policy defines an allow list of role definitions that can be assigned to specific Principal IDs in IAM. This is useful in the example where you don't want an SPN having it's rights elevated.",
    "metadata": {
      "version": "1.0.0",
      "category": "Authorization"
    },
    "mode": "All",
    "parameters": {
      "roleDefinitionIds": {
        "type": "array",
        "metadata": {
          "description": "The list of allowed role definition IDs. Example: If you were to put in '8e3af657-a8ff-443c-a75c-2fe8c4bcb635' as a value then only the 'Owner' role definition could be assigned.",
          "displayName": "Approved Role Definitions"
        }
      },
      "targetedPrincipalIDs": {
        "type": "array",
        "metadata": {
          "displayName": "Targeted Principal IDs",
          "description": "Any Principal IDs included in this list will have this Policy applied to them."
        },
        "defaultvalue": "None"
      },
      "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": {
              "value": "[split(field('Microsoft.Authorization/roleAssignments/roleDefinitionId'),'roleDefinitions/')[1]]",
              "in": "[parameters('roleDefinitionIds')]"
            }
          },
          {
            "field": "Microsoft.Authorization/roleAssignments/principalId",
            "in": "[parameters('targetedPrincipalIDs')]"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}

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