Control: 7.1.2.4 Ensure that Activity Log Alert exists for Delete Network Security Group
Description
Create an activity log alert for the Delete Network Security Group event.
Monitoring for "Delete Network Security Group" events gives insight into network access changes and may reduce the time it takes to detect suspicious activity.
Remediation
From Azure Portal
- Navigate to the 
Monitorblade. - Select 
Alerts. - Select 
Create. - Select 
Alert rule. - Choose a subscription.
 - Select 
Apply. - Select the 
Conditiontab. - Click 
See all signals. - Select 
Delete Network Security Group (Network Security Group). - Click 
Apply. - Select the 
Actionstab. - Click 
Select action groupsto select an existing action group, orCreate action groupto create a new action group. - Follow the prompts to choose or create an action group.
 - Select the 
Detailstab. - Select a 
Resource group, provide anAlert rule nameand an optionalAlert rule description. - Click 
Review + create. - Click 
Create. 
From Azure CLI
az monitor activity-log alert create --resource-group "<resource group name>" --condition category=Administrative and operationName=Microsoft.Network/networkSecurityGroups/delete and level=<verbose | information | warning | error | critical> --scope "/subscriptions/<subscription ID>" --name "<activity log rule name>" --subscription <subscription id> --action-group <action group ID>
From PowerShell
Create the Conditions object.
$conditions = @()$conditions += New-AzActivityLogAlertAlertRuleAnyOfOrLeafConditionObject -Equal Administrative -Field category$conditions += New-AzActivityLogAlertAlertRuleAnyOfOrLeafConditionObject -Equal Microsoft.Network/networkSecurityGroups/delete -Field operationName$conditions += New-AzActivityLogAlertAlertRuleAnyOfOrLeafConditionObject -Equal Verbose -Field level
Retrieve the Action Group information and store in a variable, then create the Actions object.
$actionGroup = Get-AzActionGroup -ResourceGroupName <resource group name> -Name <action group name>$actionObject = New-AzActivityLogAlertActionGroupObject -Id $actionGroup.Id
Create the Scope object
$scope = "/subscriptions/<subscription id>"
Create the Activity Log Alert Rule for Microsoft.Network/networkSecurityGroups/delete
New-AzActivityLogAlert -Name "<activity log alert rule name>" -ResourceGroupName "<resource group name>" -Condition $conditions -Scope $scope -Location global -Action $actionObject -Subscription <subscription ID> -Enabled $true
Default Value
By default, no monitoring alerts are created.
Usage
Run the control in your terminal:
powerpipe control run azure_compliance.control.cis_v400_7_1_2_4Snapshot and share results via Turbot Pipes:
powerpipe loginpowerpipe control run azure_compliance.control.cis_v400_7_1_2_4 --shareSQL
This control uses a named query:
with alert_rule as (  select    alert.id as alert_id,    alert.name as alert_name,    alert.enabled,    alert.location,    alert.subscription_id,    jsonb_array_length(alert.condition -> 'allOf')  from    azure_log_alert as alert,    jsonb_array_elements_text(scopes) as sc  where    alert.location = 'global'    and alert.enabled    and sc = '/subscriptions/' || alert.subscription_id    and (      (        alert.condition -> 'allOf' @> '[{"equals":"Administrative","field":"category"}]'        and alert.condition -> 'allOf' @> '[{"field": "operationName", "equals": "Microsoft.Network/networkSecurityGroups/delete"}]'      )      or      (        alert.condition -> 'allOf' @> '[{"equals":"Administrative","field":"category"}]'        and alert.condition -> 'allOf' @> '[{"field": "resourceType", "equals": "microsoft.network/networksecuritygroups"}]'        and jsonb_array_length(alert.condition -> 'allOf') = 2      )    )  limit 1)  select    sub.subscription_id as resource,    case      when count(a.subscription_id) > 0 then 'ok'      else 'alarm'    end as status,    case      when count(a.subscription_id) > 0 then 'Activity log alert exists for delete Network Security Group event.'      else 'Activity log alert does not exists for delete Network Security Group event.'    end as reason        , sub.display_name as subscription  from    azure_subscription sub    left join alert_rule a on sub.subscription_id = a.subscription_id  group by    sub._ctx,    sub.subscription_id,    sub.display_name;