Gallery › Authorization › Azure Community Policy
Deny custom roles with exclusionlist
Converted Policy Audit Deny Disabled Mode All Version 1.0.0
This policy will audit or deny the creation of RBAC custom roles, excluding specified role definition names.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 57 lines
{
"name": "4eaae358-7df4-4338-ae26-c4547ebe9403",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Deny custom roles with exclusionlist",
"description": "This policy will audit or deny the creation of RBAC custom roles, excluding specified role definition names.",
"metadata": {
"version": "1.0.0",
"category": "Authorization"
},
"mode": "All",
"parameters": {
"excludedRoleNames": {
"type": "array",
"metadata": {
"displayName": "Excluded Role Names",
"description": "Names of Roles to be excluded from the policy."
},
"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/roleDefinitions"
},
{
"field": "Microsoft.Authorization/roleDefinitions/type",
"notEquals": "BuiltInRole"
},
{
"field": "Microsoft.Authorization/roleDefinitions/roleName",
"notIn": "[parameters('excludedRoleNames')]"
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
}
}
}Bylaw4eaae358-7df4-4338-ae26-c4547ebe9403.bylaw.ps1 · 38 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '4eaae358-7df4-4338-ae26-c4547ebe9403' {
Properties @{
DisplayName = 'Deny custom roles with exclusionlist'
Description = 'This policy will audit or deny the creation of RBAC custom roles, excluding specified role definition names.'
Version = '1.0.0'
Category = 'Authorization'
Mode = 'All'
}
Parameter ExcludedRoleNames @{
Type = 'array'
Default = @()
DisplayName = 'Excluded Role Names'
Description = 'Names of Roles to be excluded from the policy.'
}
Parameter Effect @{
Type = 'string'
AllowedValues = @('Deny', 'Audit', 'Disabled')
Default = 'Audit'
DisplayName = 'Effect'
Description = 'Deny, Audit or Disabled the execution of the Policy'
}
Resource 'Microsoft.Authorization/roleDefinitions' {
When {
Field 'Microsoft.Authorization/roleDefinitions/type' | Must -Not -Be 'BuiltInRole'
}
Require 'roleName is one of the ExcludedRoleNames parameter' {
Field roleName | Must -BeIn (Param ExcludedRoleNames)
}
}
Effect (Param Effect)
}Source: policyDefinitions/Authorization/deny-custom-roles-with-exclusionlist/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw