Bylaw

Gallery › Security Center › Azure built-in policies

API endpoints that are unused should be disabled and removed from the Azure API Management service

Converted Policy AuditIfNotExists Disabled Mode All Version 1.0.1

As a security best practice, API endpoints that haven't received traffic for 30 days are considered unused and should be removed from the Azure API Management service. Keeping unused API endpoints may pose a security risk to your organization. These may be APIs that should have been deprecated from the Azure API Management service but may have been accidentally left active. Such APIs typically do not receive the most up to date security coverage.

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

Azure Policy JSONASC_APIMUnusedApiEndpointsShouldbeRemoved_AINE.json · 53 lines
{
  "properties": {
    "displayName": "API endpoints that are unused should be disabled and removed from the Azure API Management service",
    "policyType": "BuiltIn",
    "mode": "All",
    "description": "As a security best practice, API endpoints that haven't received traffic for 30 days are considered unused and should be removed from the Azure API Management service. Keeping unused API endpoints may pose a security risk to your organization. These may be APIs that should have been deprecated from the Azure API Management service but may have been accidentally left active. Such APIs typically do not receive the most up to date security coverage.",
    "metadata": {
      "category": "Security Center",
      "version": "1.0.1"
    },
    "version": "1.0.1",
    "parameters": {
      "effect": {
        "type": "String",
        "defaultValue": "AuditIfNotExists",
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "equals": "Microsoft.ApiManagement/service/apis/operations"
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Security/assessments",
          "name": "4e8c00a2-e8bc-42a8-9e12-99584a51ad10",
          "existencecondition": {
            "field": "microsoft.security/assessments/status.code",
            "in": [
              "NotApplicable",
              "Healthy"
            ]
          }
        }
      }
    },
    "versions": [
      "1.0.1",
      "1.0.0-PREVIEW"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/c8acafaf-3d23-44d1-9624-978ef0f8652c",
  "name": "c8acafaf-3d23-44d1-9624-978ef0f8652c"
}
Bylawc8acafaf-3d23-44d1-9624-978ef0f8652c.bylaw.ps1 · 27 lines
# Converted from ASC_APIMUnusedApiEndpointsShouldbeRemoved_AINE.json by ConvertTo-Bylaw.
Policy 'c8acafaf-3d23-44d1-9624-978ef0f8652c' {

    Properties @{
        DisplayName   = 'API endpoints that are unused should be disabled and removed from the Azure API Management service'
        Description   = 'As a security best practice, API endpoints that haven''t received traffic for 30 days are considered unused and should be removed from the Azure API Management service. Keeping unused API endpoints may pose a security risk to your organization. These may be APIs that should have been deprecated from the Azure API Management service but may have been accidentally left active. Such APIs typically do not receive the most up to date security coverage.'
        Category      = 'Security Center'
        Version       = '1.0.1'
        PolicyVersion = '1.0.1'
        Mode          = 'All'
    }

    Parameter Effect @{
        AllowedValues = @('AuditIfNotExists', 'Disabled')
        Default       = 'AuditIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource 'Microsoft.ApiManagement/service/apis/operations'

    AuditIfNotExists 'Microsoft.Security/assessments' -Name '4e8c00a2-e8bc-42a8-9e12-99584a51ad10' -Effect (Param Effect) {
        Require 'status.code is one of 2 values' {
            Field status.code | Must -BeIn @('NotApplicable', 'Healthy')
        }
    }
}

Source: built-in-policies/policyDefinitions/Security Center/ASC_APIMUnusedApiEndpointsShouldbeRemoved_AINE.json in Azure/azure-policy, under the MIT licence.