An administrator needs to identify unauthorized access attempts to an Azure Key Vault named KV-Prod. You are tasked with writing a Kusto Query Language (KQL) query in Log Analytics to retrieve all secret retrieval operations (SecretGet) that failed due to unauthorized access (HTTP status codes 401 or 403) within the last 24 hours. The query must only output the columns for TimeGenerated, Resource, CallerIPAddress, and ResultSignature. Which KQL query should you use?
- AzureDiagnostics
| where TimeGenerated > ago(24h)
| where ResourceProvider == "MICROSOFT.KEYVAULT"
| where OperationName == "SecretGet"
| where ResultSignature in ("401", "403")
| project TimeGenerated, Resource, CallerIPAddress, ResultSignatureAnswer - BAzureDiagnostics
| project TimeGenerated, Resource, CallerIPAddress, ResultSignature
| where TimeGenerated > ago(24h) and ResourceProvider == "MICROSOFT.KEYVAULT"
| where OperationName == "SecretGet" and (ResultSignature == "401" or ResultSignature == "403") - CSELECT TimeGenerated, Resource, CallerIPAddress, ResultSignature
FROM AzureDiagnostics
WHERE TimeGenerated > ago(24h)
AND ResourceProvider = 'MICROSOFT.KEYVAULT'
AND OperationName = 'SecretGet'
AND ResultSignature IN ('401', '403') - DAzureDiagnostics
| where TimeGenerated > ago(24h)
| where ResourceProvider = "MICROSOFT.KEYVAULT"
| where OperationName = "SecretGet"
| where ResultSignature == "401" or "403"
| project TimeGenerated, Resource, CallerIPAddress, ResultSignature
Answer
The query that starts with the AzureDiagnostics table, filters for records from the last 24 hours, restricts the resource provider to Microsoft Key Vault, filters for SecretGet operations and status codes 401 or 403, and then projects the required columns.
The correct query correctly follows the tabular operator syntax of KQL. It first filters the AzureDiagnostics table by TimeGenerated, ResourceProvider, OperationName, and ResultSignature, and then uses the project operator to output only the requested columns.
Step-by-Step Solution
Key Concept
Writing KQL queries using valid syntax and operator sequencing to analyze Azure diagnostics data.
Estimated Time:2m 0s