Gallery › Authorization › Azure Community Policy
Disallowed Role Definitions
Converted Policy Audit Deny Disabled Mode All Version 1.0.0
This policy defines a list of role definitions that can not be used in IAM
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 66 lines
{
"name": "c91285dc-6f65-477e-b5ca-b49f7bdca817",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Disallowed Role Definitions",
"description": "This policy defines a list of role definitions that can not be used in IAM",
"metadata": {
"version": "1.0.0",
"category": "Authorization"
},
"mode": "All",
"parameters": {
"roleDefinitionIds": {
"type": "array",
"metadata": {
"description": "The list of disallowed role definition IDs. Example: If you were to put in '8e3af657-a8ff-443c-a75c-2fe8c4bcb635' as a value then the 'Owner' role could not be assigned.",
"displayName": "Not Approved Role Definitions"
}
},
"exemptPrincipalIDs": {
"type": "array",
"metadata": {
"displayName": "Exempt Principal IDs",
"description": "Any Principal IDs included in this list will not have this Policy applied to them."
},
"defaultvalue": []
},
"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"
},
{
"value": "[last(split(field('Microsoft.Authorization/roleAssignments/roleDefinitionId'),'/'))]",
"in": "[parameters('roleDefinitionIds')]"
},
{
"not": {
"field": "Microsoft.Authorization/roleAssignments/principalId",
"in": "[parameters('exemptPrincipalIDs')]"
}
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
}
}
}Bylawc91285dc-6f65-477e-b5ca-b49f7bdca817.bylaw.ps1 · 42 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'c91285dc-6f65-477e-b5ca-b49f7bdca817' {
Properties @{
DisplayName = 'Disallowed Role Definitions'
Description = 'This policy defines a list of role definitions that can not be used in IAM'
Version = '1.0.0'
Category = 'Authorization'
Mode = 'All'
}
Parameter RoleDefinitionIds @{
Type = 'array'
DisplayName = 'Not Approved Role Definitions'
Description = 'The list of disallowed role definition IDs. Example: If you were to put in ''8e3af657-a8ff-443c-a75c-2fe8c4bcb635'' as a value then the ''Owner'' role could not be assigned.'
}
Parameter ExemptPrincipalIDs @{
Type = 'array'
Default = @()
DisplayName = 'Exempt Principal IDs'
Description = 'Any Principal IDs included in this list will not have this Policy applied to them.'
}
Parameter Effect @{
AllowedValues = @('Deny', 'Audit', 'Disabled')
Default = 'Audit'
DisplayName = 'Effect'
Description = 'Deny, Audit or Disabled the execution of the Policy'
}
Resource 'Microsoft.Authorization/roleAssignments' {
When {
Arm '[last(split(field(''Microsoft.Authorization/roleAssignments/roleDefinitionId''),''/''))]' | Must -BeIn (Param RoleDefinitionIds)
}
Require 'principalId is one of the ExemptPrincipalIDs parameter' {
Field principalId | Must -BeIn (Param ExemptPrincipalIDs)
}
}
Effect (Param Effect)
}Source: policyDefinitions/Authorization/disallowed-role-definitions/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw