Bylaw

Gallery › App Service › Azure built-in policies

[Deprecated]: Ensure that 'Java version' is the latest, if used as a part of the API app

Converted Policy AuditIfNotExists Disabled Mode Indexed Version 2.0.0-deprecated Deprecated

Periodically, newer versions are released for Java either due to security flaws or to include additional functionality. Using the latest Python version for API apps is recommended in order to take advantage of security fixes, if any, and/or new functionalities of the latest version. We recommend all customers who are still using API apps to implement the built-in policy called 'App Service apps that use Java should use the latest 'Java version'', which is scoped to include API apps in addition to Web apps.

ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.

Azure Policy JSONApiApp_Audit_java_Latest.json · 78 lines
{
  "properties": {
    "displayName": "[Deprecated]: Ensure that 'Java version' is the latest, if used as a part of the API app",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Periodically, newer versions are released for Java either due to security flaws or to include additional functionality. Using the latest Python version for API apps is recommended in order to take advantage of security fixes, if any, and/or new functionalities of the latest version. We recommend all customers who are still using API apps to implement the built-in policy called 'App Service apps that use Java should use the latest 'Java version'', which is scoped to include API apps in addition to Web apps.",
    "metadata": {
      "version": "2.0.0-deprecated",
      "category": "App Service",
      "deprecated": true
    },
    "version": "2.0.0",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "AuditIfNotExists",
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      },
      "JavaLatestVersion": {
        "type": "String",
        "defaultValue": "11",
        "metadata": {
          "displayName": "Latest Java version",
          "description": "Latest supported Java version for App Services"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Web/sites"
          },
          {
            "field": "kind",
            "like": "*api"
          },
          {
            "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": "JAVA"
              },
              {
                "field": "Microsoft.Web/sites/config/web.linuxFxVersion",
                "like": "[concat('*', parameters('JavaLatestVersion'))]"
              }
            ]
          }
        }
      }
    },
    "versions": [
      "2.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/88999f4c-376a-45c8-bcb3-4058f713cf39",
  "name": "88999f4c-376a-45c8-bcb3-4058f713cf39"
}
Bylaw88999f4c-376a-45c8-bcb3-4058f713cf39.bylaw.ps1 · 47 lines
# Converted from ApiApp_Audit_java_Latest.json by ConvertTo-Bylaw.
Policy '88999f4c-376a-45c8-bcb3-4058f713cf39' {

    Properties @{
        DisplayName   = '[Deprecated]: Ensure that ''Java version'' is the latest, if used as a part of the API app'
        Description   = 'Periodically, newer versions are released for Java either due to security flaws or to include additional functionality. Using the latest Python version for API apps is recommended in order to take advantage of security fixes, if any, and/or new functionalities of the latest version. We recommend all customers who are still using API apps to implement the built-in policy called ''App Service apps that use Java should use the latest ''Java version'''', which is scoped to include API apps in addition to Web apps.'
        Version       = '2.0.0-deprecated'
        Category      = 'App Service'
        Deprecated    = $true
        PolicyVersion = '2.0.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        Type          = 'string'
        AllowedValues = @('AuditIfNotExists', 'Disabled')
        Default       = 'AuditIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }
    Parameter JavaLatestVersion @{
        Default     = '11'
        DisplayName = 'Latest Java version'
        Description = 'Latest supported Java version for App Services'
        JsonName    = 'JavaLatestVersion'
    }

    Resource 'Microsoft.Web/sites' {

        When {
            Field kind | Must -BeLike '*api'
        }

        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 'JAVA' -IfPresent
                Field web.linuxFxVersion | Must -BeLike (Arm '[concat(''*'', parameters(''JavaLatestVersion''))]')
            }
        }
    }
}

Source: built-in-policies/policyDefinitions/App Service/ApiApp_Audit_java_Latest.json in Azure/azure-policy, under the MIT licence.