{
  "$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/cee6bbae-e1ee-4b65-9782-6afce5c330e6')]",
      "kind": "Scheduled",
      "name": "[concat(parameters('workspace'),'/Microsoft.SecurityInsights/cee6bbae-e1ee-4b65-9782-6afce5c330e6')]",
      "properties": {
        "alertRuleTemplateName": "cee6bbae-e1ee-4b65-9782-6afce5c330e6",
        "customDetails": null,
        "description": "Correlates the archival, deletion or detachment of a Uniqkey employee account with data exports performed by that same employee during the preceding 14 days. An employee who exports credentials shortly before losing access is a classic insider-risk scenario, and organization credentials touched by the export should be considered for rotation. The action filter matches the offboarding action identifiers from the Uniqkey audit-log catalog, with a name-based fallback for future action variants.",
        "displayName": "Uniqkey - Departing employee credential export",
        "enabled": true,
        "entityMappings": [
          {
            "entityType": "Account",
            "fieldMappings": [
              {
                "columnName": "ActorEmail",
                "identifier": "FullName"
              }
            ]
          },
          {
            "entityType": "IP",
            "fieldMappings": [
              {
                "columnName": "SrcIpAddr",
                "identifier": "Address"
              }
            ]
          }
        ],
        "eventGroupingSettings": {
          "aggregationKind": "AlertPerResult"
        },
        "incidentConfiguration": {
          "createIncident": true,
          "groupingConfiguration": {
            "enabled": true,
            "lookbackDuration": "PT5H",
            "matchingMethod": "AllEntities",
            "reopenClosedIncident": false
          }
        },
        "OriginalUri": "https://github.com/Azure/Azure-Sentinel/blob/master/Solutions/Uniqkey/Analytic%20Rules/Uniqkey%20-%20Departing%20employee%20credential%20export.yaml",
        "query": "let lookback = 14d;\nlet frequency = 1h;\nlet exports =\n    UniqkeyEvents_CL\n    | where TimeGenerated > ago(lookback)\n    | where Category == \"data_export\"\n    | project ExportTime = TimeGenerated, ActorId, ActorEmail, ExportAction = Action, ExportedTargetType = TargetType, ExportedTargetName = TargetName, SrcIpAddr;\nlet removalActionIds = dynamic([\n    \"a2e18fcb-4d28-4f53-b2e3-24f03d0e188e\", // Archive employee account\n    \"319c8a05-abd5-4b13-b51f-d6198578e61c\", // Archive bulk employee\n    \"f1ed588f-975b-4bbe-83e9-e7a5c23e647f\", // Hard delete employee\n    \"f8b81b6c-0082-4ed8-916e-83350f932e89\", // Permanent delete employee account\n    \"4361dd86-0f70-47e0-91de-071a81d49834\"  // Detach bulk employee account\n]);\nUniqkeyEvents_CL\n| where TimeGenerated > ago(frequency)\n| where Category == \"account_management\"\n| where tolower(ActionId) in (removalActionIds) or Action has_any (\"archive\", \"delete\", \"detach\")\n| where TargetType == \"employee\"\n| project RemovalTime = TimeGenerated, RemovalAction = Action, RemovedEmployeeId = TargetId, RemovedEmployeeName = TargetName, RemovalActor = ActorEmail\n| join kind=inner exports on $left.RemovedEmployeeId == $right.ActorId\n| project RemovalTime, RemovalAction, RemovedEmployeeName, RemovalActor, ExportTime, ExportAction, ExportedTargetType, ExportedTargetName, ActorEmail, SrcIpAddr",
        "queryFrequency": "PT1H",
        "queryPeriod": "P14D",
        "severity": "High",
        "subTechniques": [],
        "suppressionDuration": "PT5H",
        "suppressionEnabled": false,
        "tactics": [
          "CredentialAccess",
          "Exfiltration"
        ],
        "techniques": [
          "T1555"
        ],
        "templateVersion": "1.0.0",
        "triggerOperator": "GreaterThan",
        "triggerThreshold": 0
      },
      "type": "Microsoft.OperationalInsights/workspaces/providers/alertRules"
    }
  ]
}
