Gallery › App Service › Azure Community Policy
Function apps should have local authentication methods for deployment disabled
Converted Policy AuditIfNotExists DeployIfNotExists Disabled Mode Indexed Version 1.0.0
Disabling local authentication methods improves security by ensuring that the app exclusively requires Azure Active Directory identities for authentication. Learn more at: https://aka.ms/app-service-disable-basic-auth.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 94 lines
{
"name": "3634d9f0-8b92-40ca-9a15-07690ab72b7c",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Function apps should have local authentication methods for deployment disabled",
"description": "Disabling local authentication methods improves security by ensuring that the app exclusively requires Azure Active Directory identities for authentication. Learn more at: https://aka.ms/app-service-disable-basic-auth.",
"metadata": {
"version": "1.0.0",
"category": "App Service"
},
"mode": "Indexed",
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "DeployIfNotExists, AuditIfNotExists or Disabled the execution of the Policy"
},
"allowedValues": [
"DeployIfNotExists",
"AuditIfNotExists",
"Disabled"
],
"defaultValue": "DeployIfNotExists"
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Web/sites"
},
{
"field": "kind",
"contains": "functionapp"
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Web/sites/basicPublishingCredentialsPolicies",
"name": "scm",
"existenceCondition": {
"field": "Microsoft.Web/sites/basicPublishingCredentialsPolicies/allow",
"equals": false
},
"roleDefinitionIds": [
"/providers/Microsoft.Authorization/roleDefinitions/de139f84-1756-47ae-9be6-808fbbe84772"
],
"deployment": {
"properties": {
"mode": "incremental",
"parameters": {
"siteName": {
"value": "[field('name')]"
},
"location": {
"value": "[field('location')]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"siteName": {
"type": "string"
},
"location": {
"type": "string"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Web/sites/basicPublishingCredentialsPolicies",
"name": "[concat(parameters('siteName'), '/scm')]",
"apiVersion": "2020-12-01",
"location": "[parameters('location')]",
"tags": {},
"properties": {
"allow": false
}
}
]
}
}
}
}
}
}
}
}Bylaw3634d9f0-8b92-40ca-9a15-07690ab72b7c.bylaw.ps1 · 35 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '3634d9f0-8b92-40ca-9a15-07690ab72b7c' {
Properties @{
DisplayName = 'Function apps should have local authentication methods for deployment disabled'
Description = 'Disabling local authentication methods improves security by ensuring that the app exclusively requires Azure Active Directory identities for authentication. Learn more at: https://aka.ms/app-service-disable-basic-auth.'
Version = '1.0.0'
Category = 'App Service'
Mode = 'Indexed'
}
Parameter Effect @{
AllowedValues = @('DeployIfNotExists', 'AuditIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'Effect'
Description = 'DeployIfNotExists, AuditIfNotExists or Disabled the execution of the Policy'
}
Resource 'Microsoft.Web/sites' {
Require 'kind does not contain functionapp' {
Field kind | Must -Not -ContainText 'functionapp' -IfPresent
}
}
DeployIfNotExists 'Microsoft.Web/sites/basicPublishingCredentialsPolicies' -Role 'Website Contributor' -Name 'scm' -Effect (Param Effect) {
Require 'allow is false' {
Field allow | Must -Be $false
}
Deployment -TemplateFile './templates/3634d9f0-8b92-40ca-9a15-07690ab72b7c.json' -Parameters ([ordered]@{
siteName = (Arm '[field(''name'')]')
location = (Arm '[field(''location'')]')
})
}
}Its deployment templates are written beside it:
templates/3634d9f0-8b92-40ca-9a15-07690ab72b7c.json
Source: policyDefinitions/App Service/function-apps-should-have-local-authentication-methods-for-deployment-disabled/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw