Skip to content
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2682,6 +2682,38 @@ schemas and the `paramify` CLI — not the internal code.

### Fixed

- **Four Azure monitoring fetchers give null counts, not 0 or false, when a
list could not be read.** The run still exits 1 as `partial_failure`.
- `azure_activity_log_alerts` 0.4.0: when the alert rule list is not read,
every alert count, both coverage maps and every coverage verdict
(`all_monitored_operations_covered`, `service_health_alert_configured`,
`all_change_operations_covered`) are null. Before they read 0 and false.
The two operation totals stay 12 and 4. When the processing rule list is
not read, `suppressed` and `reaches_human` are null per alert, and
`alerts_suppressed`, `alerts_possibly_suppressed`, `alerts_reaching_human`,
the change coverage fields and `monitored_operation_coverage_reaching_human`
are null. Before they read as if no rule suppressed anything. An enabled
alert with no deliverable action group of its own is unknown too, since a
processing rule may add one: `routes_to_enabled_receiver` and
`routes_to_person` read null, not false, so `reaches_human` is null and the
alert counts in `alerts_routing_unknown` and `alerts_reaching_human_unknown`.
`processing_rule_matches` and `suppressed_by_processing_rules` are null, not
`[]`.
- `azure_diagnostic_settings` 0.2.0: when the settings are not read,
`activity_log_exported`, the counts, the coverage map and the required
category verdicts are null. Before, `activity_log_exported` read false.
- `azure_resource_diagnostic_settings` 0.5.0: when Resource Graph is not
read, the resource, coverage and ingestion counts and verdicts, the
destination counts, `in_scope_resources` and `excluded_resources` are null.
Before they read 0.
- `azure_log_analytics_workspaces` 0.4.0: when the workspace list is not
read, every count, `in_scope_workspaces` and `excluded_workspaces` are
null. A workspace whose tables or data exports are not read makes
`total_tables`, `min_table_total_retention_in_days` and the data export
counts null. `sentinel_onboarded_workspaces` is null while any workspace's
solutions are unread, and `sentinel_onboarded` is null while any are unread
and none is known to have Sentinel; before, it read false.

- **Disk, Key Vault, storage and SQL Managed Instance fetchers: an unread list
gives null counts, not 0.** When a list the run needs is refused (403),
throttled or times out, every total, count and percentage built from it is
Expand Down
20 changes: 14 additions & 6 deletions fetchers/azure/_shared/alert_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,11 @@ def _tri(groups: list[dict], has: Callable[[dict], bool]) -> Optional[bool]:
return False


def route(enabled: bool, group_ids: list[str], alert_scopes: list[str], groups: dict, rules: list[dict]) -> dict:
"""Resolve an alert rule's notification path; `groups` is keyed by lower-cased action group id."""
matches = matching_processing_rules(alert_scopes, rules)
def route(enabled: bool, group_ids: list[str], alert_scopes: list[str], groups: dict, rules: list[dict] | None) -> dict:
"""Resolve an alert rule's notification path; `groups` is keyed by lower-cased action group id.

rules=None means the processing rule list was not read, so whether anything suppresses the alert is unknown."""
matches = matching_processing_rules(alert_scopes, rules or [])
own = {}
for gid in group_ids:
if gid:
Expand All @@ -224,8 +226,14 @@ def route(enabled: bool, group_ids: list[str], alert_scopes: list[str], groups:
})
routes = _tri(resolved, lambda g: g["deliverable"]) if enabled else False
to_person = _tri(resolved, lambda g: g["notifies_people"]) if enabled else False
if rules is None and enabled:
# A processing rule may add a group, so a "no" from the own groups is unknown.
routes = None if routes is False else routes
to_person = None if to_person is False else to_person
suppressors = [m for m in matches if m["rule"]["suppresses_notifications"]]
if any(m["applies_to_every_fire"] for m in suppressors):
if rules is None and enabled:
suppressed = None
elif any(m["applies_to_every_fire"] for m in suppressors):
suppressed = True
elif suppressors:
suppressed = None
Expand All @@ -242,11 +250,11 @@ def route(enabled: bool, group_ids: list[str], alert_scopes: list[str], groups:
"unresolved_action_group_ids": [g["id"] for g in resolved if not g["found"]],
"routes_to_enabled_receiver": routes,
"routes_to_person": to_person,
"processing_rule_matches": [
"processing_rule_matches": None if rules is None else [
{"id": m["rule"]["id"], "scope_match": m["scope_match"], "applies_to_every_fire": m["applies_to_every_fire"]}
for m in matches
],
"suppressed_by_processing_rules": [m["rule"]["id"] for m in suppressors],
"suppressed_by_processing_rules": None if rules is None else [m["rule"]["id"] for m in suppressors],
"suppressed": suppressed,
"reaches_human": reaches,
}
Expand Down
46 changes: 40 additions & 6 deletions fetchers/azure/activity_log_alerts/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,45 @@ def operation_coverage(alerts: list[dict], operations_map=MONITORED_OPERATIONS)
}


def with_routing(alert: dict, groups: dict, processing_rules: list[dict]) -> dict:
def with_routing(alert: dict, groups: dict, processing_rules: list[dict] | None) -> dict:
return {**alert, **route(alert["enabled"], alert["action_groups"], alert["scopes"], groups, processing_rules)}


def summarize(alerts: list[dict]) -> dict:
"""Coverage of the monitored operations is the headline, not the alert count."""
ALERT_FIELDS = (
"total_activity_log_alerts", "enabled_alerts", "disabled_alerts", "alerts_with_action_groups",
"alerts_without_action_groups", "monitored_operation_coverage", "monitored_operations_covered",
"monitored_operation_percentage", "all_monitored_operations_covered",
"uncovered_monitored_operations", "service_health_alert_configured",
"alerts_routing_to_enabled_receiver", "alerts_routing_unknown", "alerts_suppressed",
"alerts_possibly_suppressed", "alerts_reaching_human", "alerts_reaching_human_unknown",
"monitored_operation_coverage_reaching_human", "change_operation_coverage",
"change_operations_covered", "change_operations_possibly_covered",
"all_change_operations_covered", "uncovered_change_operations",
)


SUPPRESSION_FIELDS = (
"alerts_suppressed", "alerts_possibly_suppressed", "alerts_reaching_human",
"monitored_operation_coverage_reaching_human", "change_operation_coverage", "change_operations_covered",
"change_operations_possibly_covered", "all_change_operations_covered", "uncovered_change_operations",
)


def summarize(alerts: list[dict] | None, processing_rules_read: bool = True) -> dict:
"""Coverage of the monitored operations is the headline, not the alert count.

None (the alert list was not read) gives null for every count, coverage map and verdict built from it.
processing_rules_read=False (that list was not read) gives null for what depends on suppression."""
if alerts is None:
return {**dict.fromkeys(ALERT_FIELDS), "monitored_operations_total": len(MONITORED_OPERATIONS),
"change_operations_total": len(CHANGE_OPERATIONS)}
summary = alert_summary(alerts)
if not processing_rules_read:
summary.update(dict.fromkeys(SUPPRESSION_FIELDS))
return summary


def alert_summary(alerts: list[dict]) -> dict:
coverage = operation_coverage(alerts)
covered = sum(1 for is_covered in coverage.values() if is_covered)
total_monitored = len(MONITORED_OPERATIONS)
Expand Down Expand Up @@ -350,6 +383,7 @@ def main() -> int:
cred = collector.guard("azure.identity.DefaultAzureCredential", credential)

alerts: list[dict] = []
alerts_read = False
group_records: list[dict] = []
processing_rules: list[dict] = []
exclusions = ResourceExclusions.from_env()
Expand All @@ -370,7 +404,7 @@ def main() -> int:
subscription_id,
)
listed = collect_activity_log_alerts(subscription_id, cred, collector)
read["activity_log_alerts"] = listed is not None
read["activity_log_alerts"] = alerts_read = listed is not None
alerts, excluded = exclusions.split(listed or [], "activity_log_alert")
alerts_mgmt = provider_registration_status(collector, subscription_id, cred, "Microsoft.AlertsManagement")
rest = collector.guard("arm_rest.ARMPipelineClient (init)", lambda: arm_rest_client(cred))
Expand Down Expand Up @@ -403,7 +437,7 @@ def main() -> int:
outside_scope = sorted({g for g in referenced if not g.lower().startswith(prefix)})
referenced = [g for g in referenced if g.lower().startswith(prefix)]
add_referenced_groups(rest, referenced, by_id, collector)
alerts = [with_routing(a, by_id, processing_rules) for a in alerts]
alerts = [with_routing(a, by_id, processing_rules if read["processing_rules"] else None) for a in alerts]
processing_rules = in_scope_processing
elif not subscription_id:
collector.record(
Expand Down Expand Up @@ -448,7 +482,7 @@ def main() -> int:
"excluded": excluded,
},
summary={
**summarize(alerts),
**summarize(alerts if alerts_read else None, read["processing_rules"]),
"provider_registration_status": registration,
**counts,
},
Expand Down
28 changes: 14 additions & 14 deletions fetchers/azure/activity_log_alerts/fetcher.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: azure_activity_log_alerts
version: 0.3.1
version: 0.4.0
description: >-
Shows which security-relevant control-plane operations and App Service changes an enabled activity log alert covers, and whether those alerts reach a person.
category: azure
Expand Down Expand Up @@ -89,12 +89,12 @@ evidence_set:
- excluded_activity_log_alerts — Number of activity log alert rules left out of scope because a pattern matched their resource group, region (they carry the region global) or id; each is listed under excluded with the pattern, and no other count includes it; null when the rule list could not be read
- excluded_action_groups — Number of action groups left out of scope because a pattern matched their resource group or id (they carry no region, so location: patterns never match them); routing is still worked out against them; null when the action group list could not be read
- excluded_processing_rules — Number of alert processing rules left out of scope because a pattern matched their resource group or id (they carry no region); routing is still worked out against them; null when the processing rule list could not be read
- in_scope_activity_log_alerts — Number of activity log alert rules read and in scope; 0 means none was read or the patterns took out every rule, which a check can catch by requiring more than 0; null when the rule list could not be read
- in_scope_activity_log_alerts — Number of activity log alert rules read and in scope; 0 means the patterns took out every rule or none exists, which a check can catch by requiring more than 0; null when the rule list could not be read
- in_scope_action_groups — Number of action groups read and in scope; null when the action group list could not be read
- in_scope_processing_rules — Number of alert processing rules read and in scope; null when the processing rule list could not be read

What activity log alerts exist?
- total_activity_log_alerts — Number of in-scope activity log alert rules
- total_activity_log_alerts — Number of in-scope activity log alert rules; null when the alert rule list could not be read, as is every field in the next three sections (provider_registration_status still reads, and the two totals of operations stay 12 and 4)
- enabled_alerts — Number of enabled alert rules
- disabled_alerts — Number of disabled alert rules, which never fire; a rule Azure reports with no enabled value counts here
- alerts_with_action_groups — Number of alert rules with at least one action group of their own
Expand Down Expand Up @@ -124,12 +124,12 @@ evidence_set:

Do the alerts reach a person?
- alerts_routing_to_enabled_receiver — Number of enabled alerts that always notify an action group that is enabled and has at least one enabled receiver (email and SMS receivers count only when their status is Enabled, so Disabled and NotSpecified send nothing)
- alerts_routing_unknown — Number of enabled alerts where it's unknown whether they notify anyone, because an action group couldn't be read or a deliverable one is added only some of the time
- alerts_suppressed — Number of enabled alerts whose notifications an active suppression rule always switches off: one covering the alert's whole scope, with no conditions, and either no schedule or a one-off schedule window that is in force now
- alerts_possibly_suppressed — Number of enabled alerts that a suppression rule might switch off: it covers only part of the alert's scope, has conditions, or has a schedule that can't be evaluated
- alerts_reaching_human — Number of enabled alerts that notify a person (by email, SMS, voice call, app push, Azure role or ITSM ticket) and aren't suppressed
- alerts_reaching_human_unknown — Number of enabled alerts where it's unknown whether they reach a person: they notify only code (webhooks, Logic Apps, Functions, runbooks or Event Hubs), an action group couldn't be read, or a suppression rule might apply
- monitored_operation_coverage_reaching_human — For each operation in monitored_operation_coverage, true if an alert that reaches a person fires on it; null if only an alert that might reach a person does; false otherwise:
- alerts_routing_unknown — Number of enabled alerts where it's unknown whether they notify anyone, because an action group couldn't be read, a deliverable one is added only some of the time, or the processing rule list could not be read and the alert has no deliverable action group of its own
- alerts_suppressed — Number of enabled alerts whose notifications an active suppression rule always switches off: one covering the alert's whole scope, with no conditions, and either no schedule or a one-off schedule window that is in force now; null when the alert processing rule list could not be read
- alerts_possibly_suppressed — Number of enabled alerts that a suppression rule might switch off: it covers only part of the alert's scope, has conditions, or has a schedule that can't be evaluated; null when the alert processing rule list could not be read
- alerts_reaching_human — Number of enabled alerts that notify a person (by email, SMS, voice call, app push, Azure role or ITSM ticket) and aren't suppressed; null when the alert processing rule list could not be read
- alerts_reaching_human_unknown — Number of enabled alerts where it's unknown whether they reach a person: they notify only code (webhooks, Logic Apps, Functions, runbooks or Event Hubs), an action group couldn't be read, a suppression rule might apply, or the processing rule list could not be read and the alert has no deliverable action group of its own
- monitored_operation_coverage_reaching_human — For each operation in monitored_operation_coverage, true if an alert that reaches a person fires on it; null if only an alert that might reach a person does; false otherwise; null when the alert processing rule list could not be read:
- create_update_network_security_group (same operations as monitored_operation_coverage)
- delete_network_security_group (same)
- create_update_network_security_group_rule (same)
Expand All @@ -144,13 +144,13 @@ evidence_set:
- delete_security_solution (same)

Does a person get alerted to App Service changes?
- change_operation_coverage — For each App Service change, on apps and on deployment slots, true if an alert that reaches a person fires on it; null if only an alert that might reach a person does; false otherwise:
- change_operation_coverage — For each App Service change, on apps and on deployment slots, true if an alert that reaches a person fires on it; null if only an alert that might reach a person does; false otherwise; null when the alert processing rule list could not be read:
- create_update_web_app (Microsoft.Web/sites/write, and the slot equivalent)
- update_web_app_configuration (sites/config/write, and the slot equivalent)
- deploy_web_app (sites/deployments/write, and the slot equivalent)
- swap_web_app_slots (sites/slotsswap/action, and the slot equivalent)
- change_operations_covered — Number of App Service changes marked true in change_operation_coverage
- change_operations_possibly_covered — Number of App Service changes marked null in change_operation_coverage
- change_operations_covered — Number of App Service changes marked true in change_operation_coverage; null when the alert processing rule list could not be read
- change_operations_possibly_covered — Number of App Service changes marked null in change_operation_coverage; null when the alert processing rule list could not be read
- change_operations_total — Number of App Service changes in change_operation_coverage; always 4
- all_change_operations_covered — True if every App Service change is marked true; false if any is marked false; null if none is false but some are only possibly covered
- uncovered_change_operations — List of the App Service changes marked false in change_operation_coverage
- all_change_operations_covered — True if every App Service change is marked true; false if any is marked false; null if none is false but some are only possibly covered; null when the alert processing rule list could not be read
- uncovered_change_operations — List of the App Service changes marked false in change_operation_coverage; null when the alert processing rule list could not be read
Loading
Loading