Gallery › App Service › Azure built-in policies
App Service apps that use Python should use a specified 'Python version'
Converted Policy AuditIfNotExists Disabled Mode Indexed Version 4.1.0
Periodically, newer versions are released for Python software either due to security flaws or to include additional functionality. Using the latest Python version for App Service apps is recommended in order to take advantage of security fixes, if any, and/or new functionalities of the latest version. This policy only applies to Linux apps. This policy requires you to specify a Python version that meets your requirements.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
{
"properties": {
"displayName": "App Service apps that use Python should use a specified 'Python version'",
"policyType": "BuiltIn",
"mode": "Indexed",
"description": "Periodically, newer versions are released for Python software either due to security flaws or to include additional functionality. Using the latest Python version for App Service apps is recommended in order to take advantage of security fixes, if any, and/or new functionalities of the latest version. This policy only applies to Linux apps. This policy requires you to specify a Python version that meets your requirements.",
"metadata": {
"version": "4.1.0",
"category": "App Service"
},
"version": "4.1.0",
"parameters": {
"effect": {
"type": "string",
"defaultValue": "AuditIfNotExists",
"allowedValues": [
"AuditIfNotExists",
"Disabled"
],
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
}
},
"WindowsPythonLatestVersion": {
"type": "String",
"metadata": {
"displayName": "Latest Windows Python version",
"description": "Latest supported Python version for App Services",
"deprecated": true
},
"defaultValue": "3.6"
},
"LinuxPythonLatestVersion": {
"type": "String",
"defaultValue": "3.9",
"metadata": {
"displayName": "Linux Latest Python version",
"description": "Latest supported Python version for App Services",
"deprecated": true
}
},
"LinuxPythonVersion": {
"type": "String",
"defaultValue": "",
"metadata": {
"displayName": "Linux Python version",
"description": "Specify a supported Python version for App Service"
}
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Web/sites"
},
{
"field": "kind",
"notContains": "functionapp"
},
{
"field": "kind",
"contains": "linux"
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Web/sites/config",
"name": "web",
"existenceCondition": {
"anyOf": [
{
"field": "Microsoft.Web/sites/config/web.linuxFxVersion",
"notContains": "PYTHON"
},
{
"field": "Microsoft.Web/sites/config/web.linuxFxVersion",
"equals": "[concat('PYTHON|', parameters('LinuxPythonVersion'))]"
}
]
}
}
}
},
"versions": [
"4.1.0"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/7008174a-fd10-4ef0-817e-fc820a951d73",
"name": "7008174a-fd10-4ef0-817e-fc820a951d73"
}# Converted from WebApp_Audit_python_Latest.json by ConvertTo-Bylaw.
Policy '7008174a-fd10-4ef0-817e-fc820a951d73' {
Properties @{
DisplayName = 'App Service apps that use Python should use a specified ''Python version'''
Description = 'Periodically, newer versions are released for Python software either due to security flaws or to include additional functionality. Using the latest Python version for App Service apps is recommended in order to take advantage of security fixes, if any, and/or new functionalities of the latest version. This policy only applies to Linux apps. This policy requires you to specify a Python version that meets your requirements.'
Version = '4.1.0'
Category = 'App Service'
PolicyVersion = '4.1.0'
Mode = 'Indexed'
}
Parameter Effect @{
Type = 'string'
AllowedValues = @('AuditIfNotExists', 'Disabled')
Default = 'AuditIfNotExists'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Parameter WindowsPythonLatestVersion @{
Default = '3.6'
DisplayName = 'Latest Windows Python version'
Description = 'Latest supported Python version for App Services'
JsonName = 'WindowsPythonLatestVersion'
Metadata = [ordered]@{ deprecated = $true }
}
Parameter LinuxPythonLatestVersion @{
Default = '3.9'
DisplayName = 'Linux Latest Python version'
Description = 'Latest supported Python version for App Services'
JsonName = 'LinuxPythonLatestVersion'
Metadata = [ordered]@{ deprecated = $true }
}
Parameter LinuxPythonVersion @{
Default = ''
DisplayName = 'Linux Python version'
Description = 'Specify a supported Python version for App Service'
JsonName = 'LinuxPythonVersion'
}
Resource 'Microsoft.Web/sites' {
When {
Field kind | Must -Not -ContainText 'functionapp'
}
Require 'kind does not contain linux' {
Field kind | Must -Not -ContainText 'linux' -IfPresent
}
}
AuditIfNotExists 'Microsoft.Web/sites/config' -Name 'web' -Effect (Param Effect) {
Require 'web.linuxFxVersion is as required' {
AnyOf {
Field web.linuxFxVersion | Must -Not -ContainText 'PYTHON' -IfPresent
Field web.linuxFxVersion | Must -Be (Arm '[concat(''PYTHON|'', parameters(''LinuxPythonVersion''))]')
}
}
}
}Source: built-in-policies/policyDefinitions/App Service/WebApp_Audit_python_Latest.json in Azure/azure-policy, under the MIT licence.
Bylaw