Gallery › Policy › Azure Community Policy
Deny policy exemption with an expiration date greater than given days
Converted Policy Audit Deny Disabled Mode All Version 1.0.0
Deny policy exemption with an expiration date greater than given days
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 52 lines
{
"name": "2e9a8bea-8de0-4bd1-b70b-64cff8b28d17",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Deny policy exemption with an expiration date greater than given days",
"description": "Deny policy exemption with an expiration date greater than given days",
"metadata": {
"version": "1.0.0",
"category": "Policy"
},
"mode": "All",
"parameters": {
"maxExpirationDays": {
"type": "integer",
"defaultValue": 182,
"metadata": {
"description": "Days from current datetime that a policy exemption date can maximum be. Time is UTC. 182 is approx. 6 months."
}
},
"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/policyExemptions"
},
{
"field": "Microsoft.Authorization/policyExemptions/expiresOn",
"greaterOrEquals": "[addDays(utcNow(), parameters('maxExpirationDays'))]"
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
}
}
}Bylaw2e9a8bea-8de0-4bd1-b70b-64cff8b28d17.bylaw.ps1 · 32 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '2e9a8bea-8de0-4bd1-b70b-64cff8b28d17' {
Properties @{
DisplayName = 'Deny policy exemption with an expiration date greater than given days'
Description = 'Deny policy exemption with an expiration date greater than given days'
Version = '1.0.0'
Category = 'Policy'
Mode = 'All'
}
Parameter MaxExpirationDays @{
Type = 'integer'
Default = 182
Description = 'Days from current datetime that a policy exemption date can maximum be. Time is UTC. 182 is approx. 6 months.'
}
Parameter Effect @{
AllowedValues = @('Deny', 'Audit', 'Disabled')
Default = 'Audit'
DisplayName = 'Effect'
Description = 'Deny, Audit or Disabled the execution of the Policy'
}
Resource 'Microsoft.Authorization/policyExemptions' {
Require 'expiresOn is less than (Arm ''[addDays(utcNow(), parameters(''''maxExpirationDays''''))]'')' {
Field expiresOn | Must -BeLessThan (Arm '[addDays(utcNow(), parameters(''maxExpirationDays''))]')
}
}
Effect (Param Effect)
}Source: policyDefinitions/Policy/deny-policy-exemption-with-an-expiration-date-greater-than-given-days/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw