{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "workspace": {
      "type": "String"
    }
  },
  "resources": [
    {
      "apiVersion": "2024-01-01-preview",
      "id": "[concat(resourceId('Microsoft.OperationalInsights/workspaces/providers', parameters('workspace'), 'Microsoft.SecurityInsights'),'/alertRules/74b243a6-3046-48aa-8b03-e43b3c529cc1')]",
      "kind": "Scheduled",
      "name": "[concat(parameters('workspace'),'/Microsoft.SecurityInsights/74b243a6-3046-48aa-8b03-e43b3c529cc1')]",
      "properties": {
        "alertDetailsOverride": {
          "alertDescriptionFormat": "{{UserName}} attempted, and failed, to log into multiple Business Application Studio dev spaces. Tenants accessed: {{Tenants}}",
          "alertDisplayNameFormat": "SAP BTP - Unauthorized access attempt to multiple tenants"
        },
        "alertRuleTemplateName": "74b243a6-3046-48aa-8b03-e43b3c529cc1",
        "customDetails": null,
        "description": "Identifies failed Business Application Studio access attempts over a predefined number of subaccounts.",
        "displayName": "SAP BTP - Failed access attempts across multiple BAS subaccounts",
        "enabled": true,
        "entityMappings": [
          {
            "entityType": "Account",
            "fieldMappings": [
              {
                "columnName": "AccountName",
                "identifier": "Name"
              },
              {
                "columnName": "UPNSuffix",
                "identifier": "UPNSuffix"
              }
            ]
          },
          {
            "entityType": "CloudApplication",
            "fieldMappings": [
              {
                "columnName": "CloudApp",
                "identifier": "Name"
              }
            ]
          }
        ],
        "eventGroupingSettings": {
          "aggregationKind": "SingleAlert"
        },
        "OriginalUri": "https://github.com/Azure/Azure-Sentinel/blob/master/Solutions/SAP%20BTP/Analytic%20Rules/BTP%20-%20Failed%20access%20attempts%20across%20multiple%20BAS%20subaccounts.yaml",
        "query": "let subaccount_detection_threshold = 3;\nSAPBTPAuditLog_CL\n| where Category == \"audit.security-events\" and Message has \"Unauthorized access attempt\"\n| summarize Start=min(UpdatedOn), End=max(UpdatedOn), Tenants = make_set(Tenant, 100) by UserName\n| where array_length(Tenants) > subaccount_detection_threshold\n| project Start, End, UserName, Tenants, CloudApp = \"SAP BTP\"\n| extend AccountName = split(UserName, \"@\")[0], UPNSuffix = split(UserName, \"@\")[1]\n",
        "queryFrequency": "PT1H",
        "queryPeriod": "PT1H",
        "severity": "Medium",
        "status": "Available",
        "subTechniques": [],
        "suppressionDuration": "PT1H",
        "suppressionEnabled": false,
        "tactics": [
          "Discovery",
          "Reconnaissance"
        ],
        "techniques": [
          "T1526",
          "T1595"
        ],
        "templateVersion": "3.0.6",
        "triggerOperator": "GreaterThan",
        "triggerThreshold": 0
      },
      "type": "Microsoft.OperationalInsights/workspaces/providers/alertRules"
    }
  ]
}
