From a729848771d9138a46cc8e694afba66942dcd894 Mon Sep 17 00:00:00 2001 From: Connor Dalton Date: Fri, 13 Nov 2026 14:51:35 -0700 Subject: [PATCH 1/2] Give null counts, not 0, when AKS, Redis and custom role lists can't be read A cluster, cache or role definition list that could not be read left every summary count at 0 or empty. Each count built from it is now null, as is each count built from a per-cache or per-cluster read that failed. The run still fails as before. Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 18 +++ .../aks_cluster_configuration/fetcher.py | 11 +- .../aks_cluster_configuration/fetcher.yaml | 12 +- .../managed_redis_configuration/fetcher.py | 35 +++--- .../managed_redis_configuration/fetcher.yaml | 18 +-- fetchers/azure/rbac_custom_roles/fetcher.py | 9 +- fetchers/azure/rbac_custom_roles/fetcher.yaml | 10 +- .../redis_cache_configuration/fetcher.py | 29 +++-- .../redis_cache_configuration/fetcher.yaml | 20 +-- tests/test_azure_unread_lists_null_counts.py | 119 ++++++++++++++++++ 10 files changed, 224 insertions(+), 57 deletions(-) create mode 100644 tests/test_azure_unread_lists_null_counts.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 51d2f497..c430eccb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2388,6 +2388,24 @@ schemas and the `paramify` CLI — not the internal code. ### Fixed +- **`azure_aks_cluster_configuration` 0.4.0, `azure_redis_cache_configuration` + 0.3.0, `azure_managed_redis_configuration` 0.3.0 and + `azure_rbac_custom_roles` 0.3.0: a list that could not be read gives null + counts, not 0.** + - When the cluster, cache or role definition list is not read, every count, + percentage and list built from it in the summary is null (including + `total_clusters`, `total_caches`, `total_role_definitions` and + `custom_role_definitions`). Before they read 0 or empty. The run still + exits 1 as `partial_failure`. + - `azure_redis_cache_configuration`: the counts built from a per-cache read + (`access_policy_assignments`, `firewall_allows_all_ips_caches`, + `audit_logging_enabled_caches`, `maintenance_window_caches`, + `geo_replicated_caches`) are null while any cache's read failed. Before they + left that cache out. + - `azure_managed_redis_configuration`: the database counts and + `tls_only_clusters` (and its percentage) are null while any cluster's + database list could not be read. Before they left that cluster out. + - **`azure_entra_authentication_policy` no longer shows Microsoft's password defaults when the tenant's settings could not be read.** Before, a failed `/groupSettings` read fell back to the template, so `password_settings_source` diff --git a/fetchers/azure/aks_cluster_configuration/fetcher.py b/fetchers/azure/aks_cluster_configuration/fetcher.py index 5051f307..47d2f66c 100644 --- a/fetchers/azure/aks_cluster_configuration/fetcher.py +++ b/fetchers/azure/aks_cluster_configuration/fetcher.py @@ -256,8 +256,13 @@ def cluster_record(cluster: dict) -> dict: } -def summarize(clusters: list[dict]) -> dict: - """Coverage counts across the cluster estate, one per Prowler AKS check.""" +def summarize(clusters: list[dict] | None) -> dict: + """Coverage counts across the cluster estate, one per Prowler AKS check. + + `clusters` None means the list could not be read: every count is null, never 0. + """ + if clusters is None: + return dict.fromkeys(summarize([])) total = len(clusters) private = sum(1 for c in clusters if c["private_cluster"]) restricted = sum(1 for c in clusters if c["api_server_access_restricted"]) @@ -412,7 +417,7 @@ def main() -> int: "excluded": excluded, }, summary={ - **summarize(clusters), + **summarize(clusters if listed else None), "provider_registration_status": registration, **exclusions.summary(excluded, KINDS, {"clusters": len(clusters) if listed else None}), }, diff --git a/fetchers/azure/aks_cluster_configuration/fetcher.yaml b/fetchers/azure/aks_cluster_configuration/fetcher.yaml index 6a9d4ad5..f84f83d1 100644 --- a/fetchers/azure/aks_cluster_configuration/fetcher.yaml +++ b/fetchers/azure/aks_cluster_configuration/fetcher.yaml @@ -1,5 +1,5 @@ name: azure_aks_cluster_configuration -version: 0.3.1 +version: 0.4.0 description: >- Shows whether each AKS cluster's API server is private or IP-restricted, who can sign in, and whether it has network policy, auto-upgrade, Defender and Azure Monitor. category: azure @@ -88,9 +88,9 @@ evidence_set: - in_scope_clusters — Number of clusters read and in scope; 0 means there are none or the patterns took out every cluster; null when the cluster list could not be read Which clusters and node pools were checked? - - total_clusters — Number of in-scope AKS clusters, including clusters still provisioning or in a failed state; every count below about clusters is out of this total; reads 0, not null, when the cluster list could not be read, so read it together with in_scope_clusters - - total_agent_pools — Number of node pools (agent pools) across the in-scope clusters; 0 when the cluster list could not be read - - kubernetes_versions — List of the distinct Kubernetes versions the clusters are set to run (the requested version, which an upgrade in progress may not have reached yet), sorted + - total_clusters — Number of in-scope AKS clusters, including clusters still provisioning or in a failed state; every count below about clusters is out of this total; null when the cluster list could not be read, as is every count below + - total_agent_pools — Number of node pools (agent pools) across the in-scope clusters; null when the cluster list could not be read + - kubernetes_versions — List of the distinct Kubernetes versions the clusters are set to run (the requested version, which an upgrade in progress may not have reached yet), sorted; null when the cluster list could not be read - provider_registration_status — Whether the AKS provider (Microsoft.ContainerService) is registered on the subscription: registered, not_registered or unknown Is the API server kept off the internet? @@ -121,11 +121,11 @@ evidence_set: - fips_enabled_agent_pools — Number of node pools running the FIPS-enabled node image - fips_disabled_agent_pools — Number of node pools Azure reports as not running the FIPS-enabled node image - fips_unknown_agent_pools — Number of node pools whose FIPS setting Azure did not return; counted apart, never as FIPS-disabled - - all_agent_pools_fips — True if every node pool runs the FIPS image; false if any pool is FIPS-disabled and none is unknown; null if any pool's FIPS setting is unknown, or there are no node pools + - all_agent_pools_fips — True if every node pool runs the FIPS image; false if any pool is FIPS-disabled and none is unknown; null if any pool's FIPS setting is unknown, there are no node pools, or the cluster list could not be read - secure_boot_enabled_agent_pools — Number of node pools with Trusted Launch secure boot turned on - vtpm_enabled_agent_pools — Number of node pools with a virtual TPM (vTPM) turned on - trusted_launch_unknown_agent_pools — Number of node pools for which Azure returned neither the secure boot nor the vTPM setting - ssh_disabled_agent_pools — Number of node pools with SSH access to the nodes disabled - ssh_local_user_agent_pools — Number of node pools whose nodes allow SSH as a local user - ssh_access_unknown_agent_pools — Number of node pools whose SSH access setting Azure did not return - - node_image_versions — List of the distinct node image builds across all node pools, sorted; several builds mean some pools run older images + - node_image_versions — List of the distinct node image builds across all node pools, sorted; several builds mean some pools run older images; null when the cluster list could not be read diff --git a/fetchers/azure/managed_redis_configuration/fetcher.py b/fetchers/azure/managed_redis_configuration/fetcher.py index 6b82cd66..221bdbb2 100644 --- a/fetchers/azure/managed_redis_configuration/fetcher.py +++ b/fetchers/azure/managed_redis_configuration/fetcher.py @@ -141,16 +141,23 @@ def cluster_record(cluster: dict, databases) -> dict: } -def summarize(clusters: list[dict]) -> dict: - """Counts per posture property; databases are counted across every cluster.""" +def summarize(clusters: list[dict] | None) -> dict: + """Counts per posture property; databases are counted across every cluster. + + `clusters` None means the list could not be read: every count is null, never 0. A count built + from the databases is null while any cluster's database list could not be read. + """ + if clusters is None: + return dict.fromkeys(summarize([])) + all_read = all(c["databases_read"] for c in clusters) total = len(clusters) dbs = [d for c in clusters for d in c["databases"]] tls_only = sum(1 for c in clusters if c["tls_only"] is True) return { "total_clusters": total, - "total_databases": len(dbs), - "tls_only_clusters": tls_only, - "tls_only_percentage": coverage_percentage(tls_only, total), + "total_databases": len(dbs) if all_read else None, + "tls_only_clusters": tls_only if all_read else None, + "tls_only_percentage": coverage_percentage(tls_only, total) if all_read else None, "recommended_minimum_tls_clusters": sum( 1 for c in clusters if c["minimum_tls_version_recommended"] ), @@ -163,14 +170,14 @@ def summarize(clusters: list[dict]) -> dict: "public_network_access_unset_clusters": sum( 1 for c in clusters if c.get("public_network_access") is None ), - "encrypted_protocol_databases": sum(1 for d in dbs if d["client_protocol_encrypted"]), - "plaintext_protocol_databases": sum(1 for d in dbs if not d["client_protocol_encrypted"]), - "access_keys_disabled_databases": sum( - 1 for d in dbs if d["access_keys_authentication_disabled"] - ), - "access_keys_enabled_databases": sum( - 1 for d in dbs if not d["access_keys_authentication_disabled"] - ), + "encrypted_protocol_databases": ( + sum(1 for d in dbs if d["client_protocol_encrypted"]) if all_read else None), + "plaintext_protocol_databases": ( + sum(1 for d in dbs if not d["client_protocol_encrypted"]) if all_read else None), + "access_keys_disabled_databases": ( + sum(1 for d in dbs if d["access_keys_authentication_disabled"]) if all_read else None), + "access_keys_enabled_databases": ( + sum(1 for d in dbs if not d["access_keys_authentication_disabled"]) if all_read else None), } @@ -267,7 +274,7 @@ def main() -> int: collector=collector, results={"redis_clusters": clusters, "provider_registration_status": registration, "excluded": excluded}, summary={ - **summarize(clusters), + **summarize(clusters if listed else None), "provider_registration_status": registration, **exclusions.summary(excluded, ("redis_cluster",), {"redis_clusters": len(clusters) if listed else None}), }, diff --git a/fetchers/azure/managed_redis_configuration/fetcher.yaml b/fetchers/azure/managed_redis_configuration/fetcher.yaml index d29f6ea8..267ec0bc 100644 --- a/fetchers/azure/managed_redis_configuration/fetcher.yaml +++ b/fetchers/azure/managed_redis_configuration/fetcher.yaml @@ -1,5 +1,5 @@ name: azure_managed_redis_configuration -version: 0.2.1 +version: 0.3.0 description: >- Shows each Azure Managed Redis cluster's transport and access posture: minimum TLS version, public network access, private endpoints, customer-managed-key encryption, and per database the client protocol and key authentication. category: azure @@ -88,17 +88,17 @@ evidence_set: - in_scope_redis_clusters — Number of clusters read and in scope; null when the cluster list could not be read; 0 means there are none or the patterns took out every cluster, which a check can catch by requiring more than 0 Which clusters and databases exist? - - total_clusters — Number of in-scope clusters; every cluster count below is out of this total; reads 0, not null, when the cluster list could not be read, so read it together with in_scope_redis_clusters - - total_databases — Number of databases read across the in-scope clusters; clusters whose database list could not be read add none + - total_clusters — Number of in-scope clusters; every cluster count below is out of this total; null when the cluster list could not be read, as is every count below + - total_databases — Number of databases read across the in-scope clusters; null when the cluster list, or any cluster's database list, could not be read - provider_registration_status — Whether the Redis provider (Microsoft.Cache) is registered on the subscription: registered, not_registered or unknown - databases_unread_clusters — Number of clusters whose database list could not be read, so both per-cluster verdicts are null: tls_only (minimum TLS 1.2 or higher, at least one database, and every database Encrypted) and entra_only (at least one database, and every database with access-key authentication Disabled) Is traffic encrypted? - - tls_only_clusters — Number of clusters with a minimum TLS version of 1.2 or higher, at least one database, and every database accepting only encrypted client connections; clusters whose database list could not be read are not counted - - tls_only_percentage — Percentage of clusters that are TLS-only = tls_only_clusters / total_clusters × 100 (a whole number, rounded down; reads 0 when total_clusters is 0); clusters whose database list could not be read count in the total but never as TLS-only + - tls_only_clusters — Number of clusters with a minimum TLS version of 1.2 or higher, at least one database, and every database accepting only encrypted client connections; null when the cluster list, or any cluster's database list, could not be read + - tls_only_percentage — Percentage of clusters that are TLS-only = tls_only_clusters / total_clusters × 100 (a whole number, rounded down; reads 0 when total_clusters is 0); null when the cluster list, or any cluster's database list, could not be read - recommended_minimum_tls_clusters — Number of clusters whose minimum TLS version is 1.2 or 1.3; a cluster with no minimum version is not counted - - encrypted_protocol_databases — Number of databases whose client protocol is Encrypted (TLS only) - - plaintext_protocol_databases — Number of databases that do not require an encrypted client protocol (Plaintext, which accepts non-TLS connections, or no protocol reported) + - encrypted_protocol_databases — Number of databases whose client protocol is Encrypted (TLS only); null when the cluster list, or any cluster's database list, could not be read + - plaintext_protocol_databases — Number of databases that do not require an encrypted client protocol (Plaintext, which accepts non-TLS connections, or no protocol reported); null when the cluster list, or any cluster's database list, could not be read - customer_managed_key_clusters — Number of clusters encrypted with a customer-managed key Who can reach the clusters? @@ -107,5 +107,5 @@ evidence_set: - private_only_clusters — Number of clusters with public network access Disabled and at least one Approved private endpoint connection How do clients authenticate? - - access_keys_disabled_databases — Number of databases with access-key authentication Disabled, so only Microsoft Entra ID can be used - - access_keys_enabled_databases — Number of databases not reporting access-key authentication Disabled, including those reporting nothing, which are treated as Enabled (the service default before 2024) + - access_keys_disabled_databases — Number of databases with access-key authentication Disabled, so only Microsoft Entra ID can be used; null when the cluster list, or any cluster's database list, could not be read + - access_keys_enabled_databases — Number of databases not reporting access-key authentication Disabled, including those reporting nothing, which are treated as Enabled (the service default before 2024); null when the cluster list, or any cluster's database list, could not be read diff --git a/fetchers/azure/rbac_custom_roles/fetcher.py b/fetchers/azure/rbac_custom_roles/fetcher.py index 5c246f77..4a796eef 100644 --- a/fetchers/azure/rbac_custom_roles/fetcher.py +++ b/fetchers/azure/rbac_custom_roles/fetcher.py @@ -259,13 +259,16 @@ def split_custom_roles(roles: list[dict], exclusions: ResourceExclusions) -> tup return kept, excluded -def summarize(custom_roles: list[dict], total_definitions: int, excluded_custom_roles: int = 0) -> dict: +def summarize(custom_roles: list[dict] | None, total_definitions: int, excluded_custom_roles: int = 0) -> dict: """Escalation-capable custom roles are the headline. `total_role_definitions` and `builtin_role_definitions` are reported alongside so `custom_role_definitions: 0` is legible: a non-zero built-in count proves the list - call worked rather than returning nothing. + call worked rather than returning nothing. `custom_roles` None means the list could not be + read: every count is null, never 0. """ + if custom_roles is None: + return dict.fromkeys(summarize([], 0)) escalating = [r for r in custom_roles if r["can_escalate_privileges"]] return { "total_role_definitions": total_definitions, @@ -427,7 +430,7 @@ def main() -> int: "excluded": excluded, }, summary={ - **summarize(custom_roles, total_definitions, len(excluded)), + **summarize(custom_roles if listed else None, total_definitions, len(excluded)), "provider_registration_status": registration, **counts, }, diff --git a/fetchers/azure/rbac_custom_roles/fetcher.yaml b/fetchers/azure/rbac_custom_roles/fetcher.yaml index 781c9e64..1ac10d70 100644 --- a/fetchers/azure/rbac_custom_roles/fetcher.yaml +++ b/fetchers/azure/rbac_custom_roles/fetcher.yaml @@ -1,5 +1,5 @@ name: azure_rbac_custom_roles -version: 0.2.2 +version: 0.3.0 description: >- Lists every custom Azure role in the subscription with its permissions, flagging wildcards and permissions that let a holder grant itself more access. category: azure @@ -82,9 +82,9 @@ evidence_set: Summary fields: What was checked? - - total_role_definitions — Number of role definitions listed for the subscription, built-in, custom and excluded; 0 when the list could not be read - - builtin_role_definitions — Number of built-in role definitions; above 0 shows the list was read even when there are no custom roles; 0 when the list could not be read - - custom_role_definitions — Number of custom role definitions in scope; every count and percentage below covers only these, so when the role list could not be read this and every custom_roles_*, owner_equivalent_*, contributor_equivalent_* and least_privilege_* field below reads 0, and custom_roles_with_escalation_names is empty + - total_role_definitions — Number of role definitions listed for the subscription, built-in, custom and excluded; null when the list could not be read + - builtin_role_definitions — Number of built-in role definitions; above 0 shows the list was read even when there are no custom roles; null when the list could not be read + - custom_role_definitions — Number of custom role definitions in scope; every count and percentage below covers only these, so when the role list could not be read this and every custom_roles_*, owner_equivalent_*, contributor_equivalent_* and least_privilege_* field below is null - provider_registration_status — Whether Microsoft.Authorization is registered on the subscription: registered, not_registered or unknown Which custom roles are left out of scope? @@ -97,7 +97,7 @@ evidence_set: - custom_roles_with_privilege_escalation — Number of custom roles that grant at least one escalation permission: writing role assignments, role definitions or deny assignments. A role grants a permission when one of its actions matches it, with * matching any text including / (so */write and Microsoft.Authorization/* both match), and no notAction in the same permission block removes it; data actions are not checked - custom_roles_that_can_assign_roles — Number of custom roles that grant Microsoft.Authorization/roleAssignments/write, so a holder can assign any role, Owner included, to anyone - custom_roles_that_can_write_role_definitions — Number of custom roles that grant Microsoft.Authorization/roleDefinitions/write, so a holder can rewrite a role it already holds - - custom_roles_with_escalation_names — List of the names of custom roles that grant an escalation permission + - custom_roles_with_escalation_names — List of the names of custom roles that grant an escalation permission; null when the role list could not be read How broad are custom roles? - custom_roles_with_wildcard_actions — Number of custom roles with * anywhere in an action or data action, such as *, */read or Microsoft.Compute/* diff --git a/fetchers/azure/redis_cache_configuration/fetcher.py b/fetchers/azure/redis_cache_configuration/fetcher.py index 936a8361..b9f46ed8 100644 --- a/fetchers/azure/redis_cache_configuration/fetcher.py +++ b/fetchers/azure/redis_cache_configuration/fetcher.py @@ -253,7 +253,17 @@ def cache_record(cache: dict, extras: dict) -> dict: } -def summarize(caches: list[dict]) -> dict: +def summarize(caches: list[dict] | None) -> dict: + """`caches` None means the list could not be read: every count is null, never 0. + + A count built from a per-cache read is null while any cache's read failed. + """ + if caches is None: + return dict.fromkeys(summarize([])) + + def unless_unread(field, value): + return None if any(c[field] is None for c in caches) else value + total = len(caches) tls_only = sum(1 for c in caches if c["tls_only"]) by_sku: dict[str, int] = {} @@ -269,17 +279,22 @@ def summarize(caches: list[dict]) -> dict: "auth_not_required_caches": sum(1 for c in caches if not c["auth_required"]), "access_keys_disabled_caches": sum(1 for c in caches if c["entra_only"]), "entra_auth_enabled_caches": sum(1 for c in caches if c["entra_auth_enabled"]), - "access_policy_assignments": sum(len(c["access_policy_assignments"] or []) for c in caches), + "access_policy_assignments": unless_unread( + "access_policy_assignments", sum(len(c["access_policy_assignments"] or []) for c in caches)), "public_network_access_disabled_caches": sum(1 for c in caches if c["public_network_access_disabled"]), "public_network_access_unset_caches": sum(1 for c in caches if c.get("public_network_access") is None), "private_only_caches": sum(1 for c in caches if c["private_only"]), "vnet_injected_caches": sum(1 for c in caches if c["vnet_injected"]), - "firewall_allows_all_ips_caches": sum(1 for c in caches if c["firewall_allows_all_ips"] is True), - "audit_logging_enabled_caches": sum(1 for c in caches if c["audit_logging_enabled"] is True), - "maintenance_window_caches": sum(1 for c in caches if c["maintenance_window_configured"] is True), + "firewall_allows_all_ips_caches": unless_unread( + "firewall_allows_all_ips", sum(1 for c in caches if c["firewall_allows_all_ips"] is True)), + "audit_logging_enabled_caches": unless_unread( + "audit_logging_enabled", sum(1 for c in caches if c["audit_logging_enabled"] is True)), + "maintenance_window_caches": unless_unread( + "maintenance_window_configured", sum(1 for c in caches if c["maintenance_window_configured"] is True)), "replicated_caches": sum(1 for c in caches if c["replicated"]), "zone_redundant_caches": sum(1 for c in caches if c["zone_redundant"]), - "geo_replicated_caches": sum(1 for c in caches if c["geo_replicated"] is True), + "geo_replicated_caches": unless_unread( + "geo_replicated", sum(1 for c in caches if c["geo_replicated"] is True)), "persistence_enabled_caches": sum(1 for c in caches if c["persistence_enabled"]), "caches_by_sku": dict(sorted(by_sku.items())), "caches_by_redis_version": dict(sorted( @@ -401,7 +416,7 @@ def main() -> int: collector=collector, results={"redis_caches": caches, "provider_registration_status": registration, "excluded": excluded}, summary={ - **summarize(caches), + **summarize(caches if listed else None), "provider_registration_status": registration, **exclusions.summary(excluded, ("redis_cache",), {"redis_caches": len(caches) if listed else None}), }, diff --git a/fetchers/azure/redis_cache_configuration/fetcher.yaml b/fetchers/azure/redis_cache_configuration/fetcher.yaml index 6001eb5e..82ab4e33 100644 --- a/fetchers/azure/redis_cache_configuration/fetcher.yaml +++ b/fetchers/azure/redis_cache_configuration/fetcher.yaml @@ -1,5 +1,5 @@ name: azure_redis_cache_configuration -version: 0.2.1 +version: 0.3.0 description: >- Shows each classic Azure Cache for Redis cache's transport, authentication, network, audit logging, maintenance and resilience posture, and which caches fail each expectation. category: azure @@ -94,10 +94,10 @@ evidence_set: - in_scope_redis_caches — Number of caches read and in scope; null when the cache list could not be read; 0 means there are none or the patterns took out every cache, which a check can catch by requiring more than 0 Which caches exist? - - total_caches — Number of in-scope caches; every cache count below is out of this total; reads 0, not null, when the cache list could not be read, so read it together with in_scope_redis_caches + - total_caches — Number of in-scope caches; every cache count below is out of this total; null when the cache list could not be read, as is every count below - provider_registration_status — Whether the Redis provider (Microsoft.Cache) is registered on the subscription: registered, not_registered or unknown - - caches_by_sku — Number of caches for each SKU name Azure reports (such as Basic, Standard or Premium), or unknown when it reports none - - caches_by_redis_version — Number of caches for each Redis version Azure reports, or unknown when it reports none + - caches_by_sku — Number of caches for each SKU name Azure reports (such as Basic, Standard or Premium), or unknown when it reports none; null when the cache list could not be read + - caches_by_redis_version — Number of caches for each Redis version Azure reports, or unknown when it reports none; null when the cache list could not be read Is traffic encrypted? - tls_only_caches — Number of caches with a minimum TLS version of 1.2 or higher and the non-TLS port disabled; a cache with no minimum version accepts TLS 1.0 and is not counted @@ -109,27 +109,27 @@ evidence_set: - auth_not_required_caches — Number of caches that require no authentication (authnotrequired is true) - access_keys_disabled_caches — Number of caches with access-key authentication disabled, so only Microsoft Entra ID can be used - entra_auth_enabled_caches — Number of caches with Microsoft Entra authentication enabled - - access_policy_assignments — Number of Entra principals granted a data-access policy, summed over the caches; a cache whose assignments could not be read adds 0. They take effect only where Entra authentication is enabled + - access_policy_assignments — Number of Entra principals granted a data-access policy, summed over the caches; null when the cache list, or any cache's assignments, could not be read. They take effect only where Entra authentication is enabled Who can reach the caches? - public_network_access_disabled_caches — Number of caches with public network access set to Disabled - public_network_access_unset_caches — Number of caches that report no public network access setting, which count as not disabled - private_only_caches — Number of caches with public network access Disabled and either an Approved private endpoint or VNet injection (a subnet) - vnet_injected_caches — Number of caches injected into a virtual network subnet - - firewall_allows_all_ips_caches — Number of caches whose firewall rules together admit every IPv4 address, even when split across several rules; caches whose rules could not be read are not counted + - firewall_allows_all_ips_caches — Number of caches whose firewall rules together admit every IPv4 address, even when split across several rules; null when the cache list, or any cache's firewall rules, could not be read Are audit logs exported and maintenance scheduled? - - audit_logging_enabled_caches — Number of caches with a diagnostic setting that sends ConnectedClientList or MSEntraAuthenticationAuditLog logs (directly or through the audit or allLogs category group) to a destination; caches whose settings could not be read are not counted - - maintenance_window_caches — Number of caches with a patch schedule configured; a cache with none lets Azure pick the time, and one whose schedule could not be read is not counted + - audit_logging_enabled_caches — Number of caches with a diagnostic setting that sends ConnectedClientList or MSEntraAuthenticationAuditLog logs (directly or through the audit or allLogs category group) to a destination; null when the cache list, or any cache's settings, could not be read + - maintenance_window_caches — Number of caches with a patch schedule configured; a cache with none lets Azure pick the time, null when the cache list, or any cache's schedule, could not be read Are the caches resilient? - replicated_caches — Number of caches not on the Basic SKU, which is a single node with no replica and no SLA - zone_redundant_caches — Number of caches spread across more than one zone, or with the zonal allocation policy Automatic (Azure's default for Standard and Premium in zonal regions, which spreads nodes without listing the zones) - - geo_replicated_caches — Number of caches with at least one linked server; caches whose linked servers could not be read are not counted + - geo_replicated_caches — Number of caches with at least one linked server; null when the cache list, or any cache's linked servers, could not be read - persistence_enabled_caches — Number of caches with RDB or AOF persistence enabled Which caches fail an expectation? - - exceptions — List of cache names for each failed expectation, so a reviewer can sample them; each list covers in-scope caches only: + - exceptions — List of cache names for each failed expectation, so a reviewer can sample them; each list covers in-scope caches only; null when the cache list could not be read: - not_tls_only (minimum TLS version below 1.2 or non-TLS port enabled) - non_ssl_port_enabled (non-TLS port enabled) - auth_not_required (no authentication required) diff --git a/tests/test_azure_unread_lists_null_counts.py b/tests/test_azure_unread_lists_null_counts.py new file mode 100644 index 00000000..157f10c9 --- /dev/null +++ b/tests/test_azure_unread_lists_null_counts.py @@ -0,0 +1,119 @@ +"""aks / redis cache / managed redis / rbac custom roles: a list that could not be read gives null counts, not 0.""" +from __future__ import annotations + +import importlib.util +import json +import sys +from pathlib import Path + +import pytest + +REPO_ROOT = Path(__file__).resolve().parent.parent +AZURE = REPO_ROOT / "fetchers" / "azure" +sys.path.insert(0, str(AZURE / "_shared")) +sys.path.insert(0, str(REPO_ROOT / "fetchers" / "_lib")) + +from resource_exclusions import ENV # noqa: E402 + + +def _load(name): + spec = importlib.util.spec_from_file_location(f"azure_{name}_null_counts_under_test", AZURE / name / "fetcher.py") + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +aks = _load("aks_cluster_configuration") +redis_cache = _load("redis_cache_configuration") +managed_redis = _load("managed_redis_configuration") +rbac = _load("rbac_custom_roles") + +NOT_COUNTS = ("excluded_", "in_scope_", "resource_exclusion_patterns", "provider_registration_status") + + +def _run_refused(m, monkeypatch, tmp_path, collect_name, operation, filename, result): + """Runs main() with the top-level list refused (a 403), as the collect function reports it.""" + def refuse(subscription_id, cred, collector, *args, **kwargs): + collector.record(operation, PermissionError("(AuthorizationFailed) 403")) + return result + + monkeypatch.setattr(m, collect_name, refuse) + monkeypatch.setattr(m, "load_dotenv", lambda: None) + monkeypatch.setattr(m, "resolve_subscription", lambda c: {"subscription_id": "s1", "subscription_source": "env"}) + monkeypatch.setattr(m, "credential", lambda: object()) + monkeypatch.setattr(m, "provider_registration_status", lambda *a: "registered") + monkeypatch.setenv("EVIDENCE_DIR", str(tmp_path)) + monkeypatch.delenv(ENV, raising=False) + code = m.main() + return code, json.loads((tmp_path / f"{filename}_s1.json").read_text()) + + +@pytest.mark.parametrize("m, collect_name, operation, filename, result, sentinel", [ + (aks, "collect_clusters", "containerservice.managed_clusters.list", "azure_aks_cluster_configuration", None, + "total_clusters"), + (redis_cache, "collect_caches", "redis.redis.list_by_subscription", "azure_redis_cache_configuration", None, + "total_caches"), + (managed_redis, "collect_clusters", "redisenterprise.redis_enterprise.list", "azure_managed_redis_configuration", + None, "total_clusters"), + (rbac, "collect_custom_roles", "authorization.role_definitions.list", "azure_rbac_custom_roles", (None, 0), + "custom_role_definitions"), +], ids=["aks", "redis_cache", "managed_redis", "rbac_custom_roles"]) +def test_a_refused_list_leaves_every_count_null(m, collect_name, operation, filename, result, sentinel, + monkeypatch, tmp_path): + code, evidence = _run_refused(m, monkeypatch, tmp_path, collect_name, operation, filename, result) + counts = {k: v for k, v in evidence["summary"].items() if not k.startswith(NOT_COUNTS)} + assert code == 1 and sentinel in counts + assert set(counts.values()) == {None}, {k: v for k, v in counts.items() if v is not None} + + +def test_summaries_of_a_read_empty_list_are_still_numbers(): + for summary in (aks.summarize([]), redis_cache.summarize([]), managed_redis.summarize([]), rbac.summarize([], 5)): + # all_agent_pools_fips is null for a read estate with no pools, by design + assert summary and all(v is not None for k, v in summary.items() if k != "all_agent_pools_fips") + assert rbac.summarize([], 5)["builtin_role_definitions"] == 5 + + +def _cache(extras): + return redis_cache.cache_record({"id": "/subscriptions/s1/resourceGroups/rg/providers/Microsoft.Cache/Redis/c", + "name": "c", "sku_name": "Premium"}, extras) + + +FULL_EXTRAS = {"firewall_rules": [], "access_policies": [], "access_policy_assignments": [], + "patch_schedule": [], "linked_servers": [], "diagnostic_settings": []} +SUBLIST_COUNTS = { + "firewall_rules": "firewall_allows_all_ips_caches", + "access_policy_assignments": "access_policy_assignments", + "patch_schedule": "maintenance_window_caches", + "linked_servers": "geo_replicated_caches", + "diagnostic_settings": "audit_logging_enabled_caches", +} + + +@pytest.mark.parametrize("unread", sorted(SUBLIST_COUNTS)) +def test_redis_cache_count_is_null_while_one_caches_sublist_is_unread(unread): + read = _cache(FULL_EXTRAS) + broken = _cache({**FULL_EXTRAS, unread: None}) + assert redis_cache.summarize([read])[SUBLIST_COUNTS[unread]] == 0 + summary = redis_cache.summarize([read, broken]) + assert summary[SUBLIST_COUNTS[unread]] is None + assert all(summary[v] == 0 for k, v in SUBLIST_COUNTS.items() if k != unread) # the other reads succeeded + assert summary["total_caches"] == 2 + + +def _cluster(databases): + cluster = {"id": "/subscriptions/s1/resourceGroups/rg/providers/Microsoft.Cache/redisEnterprise/c", + "name": "c", "minimum_tls_version": "1.2"} + return managed_redis.cluster_record(cluster, databases) + + +def test_managed_redis_database_counts_are_null_while_one_clusters_database_list_is_unread(): + database = managed_redis.database_record({"id": "d1", "client_protocol": "Encrypted", + "access_keys_authentication": "Disabled"}) + read = _cluster([database]) + assert managed_redis.summarize([read])["total_databases"] == 1 + summary = managed_redis.summarize([read, _cluster(None)]) + for key in ("total_databases", "encrypted_protocol_databases", "plaintext_protocol_databases", + "access_keys_disabled_databases", "access_keys_enabled_databases", + "tls_only_clusters", "tls_only_percentage"): + assert summary[key] is None, key + assert summary["total_clusters"] == 2 and summary["databases_unread_clusters"] == 1 From 2141ba460fa0c657f19b4d3abe01d2c0f7ea6761 Mon Sep 17 00:00:00 2001 From: Connor Dalton Date: Mon, 16 Nov 2026 08:14:13 -0700 Subject: [PATCH 2/2] Bump azure_aks_cluster_configuration to 0.5.0 above main's 0.4.0 Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 2 +- fetchers/azure/aks_cluster_configuration/fetcher.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd7558c1..00af7b0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2532,7 +2532,7 @@ schemas and the `paramify` CLI — not the internal code. ### Fixed -- **`azure_aks_cluster_configuration` 0.4.0, `azure_redis_cache_configuration` +- **`azure_aks_cluster_configuration` 0.5.0, `azure_redis_cache_configuration` 0.3.0, `azure_managed_redis_configuration` 0.3.0 and `azure_rbac_custom_roles` 0.3.0: a list that could not be read gives null counts, not 0.** diff --git a/fetchers/azure/aks_cluster_configuration/fetcher.yaml b/fetchers/azure/aks_cluster_configuration/fetcher.yaml index 8f504ffd..01611160 100644 --- a/fetchers/azure/aks_cluster_configuration/fetcher.yaml +++ b/fetchers/azure/aks_cluster_configuration/fetcher.yaml @@ -1,5 +1,5 @@ name: azure_aks_cluster_configuration -version: 0.4.0 +version: 0.5.0 description: >- Shows whether each AKS cluster's API server is private or IP-restricted, who can sign in, and whether it has network policy, auto-upgrade, Defender and Azure Monitor. category: azure