{
  "$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/a91e677a-46b5-428e-8a7d-29a2bb33bb6f')]",
      "kind": "Scheduled",
      "name": "[concat(parameters('workspace'),'/Microsoft.SecurityInsights/a91e677a-46b5-428e-8a7d-29a2bb33bb6f')]",
      "properties": {
        "alertRuleTemplateName": "a91e677a-46b5-428e-8a7d-29a2bb33bb6f",
        "customDetails": null,
        "description": "Detects applications with open hardcoded-secret findings (CWE-798, CWE-259,\nCWE-321, CWE-522) that have associated service principal sign-in anomalies.\nCorrelates StratoSecure secret findings with AAD SPN sign-in failures.\n",
        "displayName": "Secret Exposure with Anomalous SPN Sign-In",
        "enabled": true,
        "entityMappings": [
          {
            "entityType": "CloudApplication",
            "fieldMappings": [
              {
                "columnName": "ApplicationId",
                "identifier": "AppId"
              }
            ]
          }
        ],
        "OriginalUri": "https://github.com/Azure/Azure-Sentinel/blob/master/Solutions/StratoSecure/Analytic%20Rules/S2_Secret_AnomalousCredential.yaml",
        "query": "let lookback = 1d;\nlet SecretFindings = StratoSecure_Findings_CL\n    | where TimeGenerated >= ago(lookback)\n    | where FixStatus =~ \"open\"\n    | where CweId in (\"CWE-798\", \"CWE-259\", \"CWE-321\", \"CWE-522\")\n    | where Severity in (\"Critical\", \"High\")\n    | summarize FindingCount = count(), RuleIds = make_set(RuleId), Repos = make_set(Repository)\n        by ApplicationId, StraTenantId;\nlet AnomalousSignins = AADServicePrincipalSignInLogs\n    | where TimeGenerated >= ago(lookback)\n    | where ResultType != \"0\" or ConditionalAccessStatus =~ \"failure\"\n    | summarize FailedAttempts = count(), DistinctIPs = dcount(IPAddress),\n        FirstAttempt = min(TimeGenerated), LastAttempt = max(TimeGenerated)\n        by ServicePrincipalId, ServicePrincipalName\n    | where FailedAttempts > 5 or DistinctIPs > 3;\nSecretFindings\n    | join kind=inner AnomalousSignins on $left.ApplicationId == $right.ServicePrincipalId\n    | project TimeGenerated = LastAttempt, ApplicationId, ServicePrincipalName, StraTenantId,\n        FindingCount, RuleIds, Repos, FailedAttempts, DistinctIPs\n",
        "queryFrequency": "PT1H",
        "queryPeriod": "PT1455M",
        "severity": "High",
        "status": "Available",
        "subTechniques": [
          "T1078.004"
        ],
        "suppressionDuration": "PT1H",
        "suppressionEnabled": false,
        "tactics": [
          "CredentialAccess",
          "DefenseEvasion"
        ],
        "techniques": [
          "T1078",
          "T1552"
        ],
        "templateVersion": "1.0.0",
        "triggerOperator": "GreaterThan",
        "triggerThreshold": 0
      },
      "type": "Microsoft.OperationalInsights/workspaces/providers/alertRules"
    }
  ]
}
