Gallery › App Service › Azure built-in policies
Function apps should use managed identity
Converted Policy AuditIfNotExists Disabled Mode Indexed Version 3.1.0
Use a managed identity for enhanced authentication security
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONUseManagedIdentity_FunctionApp_Audit.json · 74 lines
{
"properties": {
"displayName": "Function apps should use managed identity",
"policyType": "BuiltIn",
"mode": "Indexed",
"description": "Use a managed identity for enhanced authentication security",
"metadata": {
"version": "3.1.0",
"category": "App Service"
},
"version": "3.1.0",
"parameters": {
"effect": {
"type": "string",
"defaultValue": "AuditIfNotExists",
"allowedValues": [
"AuditIfNotExists",
"Disabled"
],
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
}
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Web/sites"
},
{
"field": "kind",
"contains": "functionapp"
},
{
"field": "kind",
"notContains": "workflowapp"
},
{
"field": "kind",
"notContains": "azurecontainerapps"
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Web/sites/config",
"name": "web",
"existenceCondition": {
"anyOf": [
{
"field": "Microsoft.Web/sites/config/managedServiceIdentityId",
"exists": "true"
},
{
"field": "Microsoft.Web/sites/config/xmanagedServiceIdentityId",
"exists": "true"
}
]
}
}
}
},
"versions": [
"3.1.0",
"3.0.0"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/0da106f2-4ca3-48e8-bc85-c638fe6aea8f",
"name": "0da106f2-4ca3-48e8-bc85-c638fe6aea8f"
}Bylaw0da106f2-4ca3-48e8-bc85-c638fe6aea8f.bylaw.ps1 · 41 lines
# Converted from UseManagedIdentity_FunctionApp_Audit.json by ConvertTo-Bylaw.
Policy '0da106f2-4ca3-48e8-bc85-c638fe6aea8f' {
Properties @{
DisplayName = 'Function apps should use managed identity'
Description = 'Use a managed identity for enhanced authentication security'
Version = '3.1.0'
Category = 'App Service'
PolicyVersion = '3.1.0'
Mode = 'Indexed'
}
Parameter Effect @{
Type = 'string'
AllowedValues = @('AuditIfNotExists', 'Disabled')
Default = 'AuditIfNotExists'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Resource 'Microsoft.Web/sites' {
When {
Field kind | Must -ContainText 'functionapp'
Field kind | Must -Not -ContainText 'workflowapp'
}
Require 'kind contains azurecontainerapps' {
Field kind | Must -ContainText 'azurecontainerapps'
}
}
AuditIfNotExists 'Microsoft.Web/sites/config' -Name 'web' -Effect (Param Effect) {
Require 'managedServiceIdentityId and xManagedServiceIdentityId are as required' {
AnyOf {
Field managedServiceIdentityId | Must -Exist
Field xManagedServiceIdentityId | Must -Exist
}
}
}
}Source: built-in-policies/policyDefinitions/App Service/UseManagedIdentity_FunctionApp_Audit.json in Azure/azure-policy, under the MIT licence.
Bylaw