Forum Discussion
Policy for "Send scan results to Log Analytics" Microsoft Defender for Storage setting
I am trying to create an Azure Policy to track the "Send scan results to Log Analytics" Microsoft Defender for Storage setting, and unfortunately, having a lot of trouble finding information on the correct policy rule evaluation paths.
This is what I have so far but it isn't working. It's only tracking 10% of the storage accounts in my subscription and it's not tracking them correctly.
"policyRule": {
"if": {
"field": "type",
"equals": "Microsoft.Storage/storageAccounts"
},
"then": {
"effect": "auditIfNotExists",
"details": {
"type": "Microsoft.Security/defenderForStorageSettings/Microsoft.Insights/diagnosticSettings",
"name": "current/service",
"existenceCondition": {
"allOf": [
{
"field": "Microsoft.Insights/diagnosticSettings/workspaceId",
"exists": true
},
{
"count": {
"field": "Microsoft.Insights/diagnosticSettings/logs[*]",
"where": {
"allOf": [
{
"field": "Microsoft.Insights/diagnosticSettings/logs[*].category",
"equals": "ScanResults"
},
{
"field": "Microsoft.Insights/diagnosticSettings/logs[*].enabled",
"equals": true
}
]
}
},
"greater": 0
}
]
}
}
}
}
Any help would be appreciated!
2 Replies
The documented endpoint identifies a diagnostic setting named service attached to DefenderForStorageSettings/current. That full resource ID is different from the resource type used in an Azure Policy lookup; combining both provider types as in your details.type does not describe the diagnostic-settings resource correctly.
Use Microsoft.Insights/diagnosticSettings for the related resource type and service for its name, with the lookup scoped to the Defender for Storage settings resource. Your ScanResults/enabled count is the relevant payload check; compare workspaceId with the intended workspace if a specific destination is required.
If you target DefenderForStorageSettings directly, use mode All. Also account separately for storage accounts without that settings resource, or they will never enter that policy’s evaluation.
Test accounts with logging enabled, disabled, and no Defender settings, and compare the actual resource payloads with compliance details. Check assignment scope and exclusions before attributing the 10% coverage solely to the existence condition.
You may audit the Microsoft.Security/DefenderForStorageSettings/current/providers/Microsoft.Insights/diagnosticSettings/service resource type, specifically checking for the logs array where category = ScanResults and enabled = true.