Bylaw

Gallery › App Service › Azure built-in policies

[Deprecated]: Managed identity should be used in your API App

Converted Policy AuditIfNotExists Disabled Mode Indexed Version 2.0.0-deprecated Deprecated

Use a managed identity for enhanced authentication security. We recommend all customers who are still using API Apps to implement the built-in policy called 'App Service apps should use managed identity', 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 JSONUseManagedIdentity_ApiApp_Audit.json · 66 lines
{
  "properties": {
    "displayName": "[Deprecated]: Managed identity should be used in your API App",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Use a managed identity for enhanced authentication security. We recommend all customers who are still using API Apps to implement the built-in policy called 'App Service apps should use managed identity', 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"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Web/sites"
          },
          {
            "field": "kind",
            "like": "*api"
          }
        ]
      },
      "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": [
      "2.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/c4d441f8-f9d9-4a9e-9cef-e82117cb3eef",
  "name": "c4d441f8-f9d9-4a9e-9cef-e82117cb3eef"
}
Bylawc4d441f8-f9d9-4a9e-9cef-e82117cb3eef.bylaw.ps1 · 37 lines
# Converted from UseManagedIdentity_ApiApp_Audit.json by ConvertTo-Bylaw.
Policy 'c4d441f8-f9d9-4a9e-9cef-e82117cb3eef' {

    Properties @{
        DisplayName   = '[Deprecated]: Managed identity should be used in your API App'
        Description   = 'Use a managed identity for enhanced authentication security. We recommend all customers who are still using API Apps to implement the built-in policy called ''App Service apps should use managed identity'', 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'
    }

    Resource 'Microsoft.Web/sites' {

        Require 'kind is not like *api' {
            Field kind | Must -Not -BeLike '*api' -IfPresent
        }
    }

    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_ApiApp_Audit.json in Azure/azure-policy, under the MIT licence.