From 62b80227293fe73b4c7414159cd99db80a3f85a4 Mon Sep 17 00:00:00 2001 From: Bruce Weygandt Date: Tue, 17 Nov 2026 11:08:03 -0700 Subject: [PATCH 1/3] feat(azure): summary counts for database encryption, AKS autoscaling and node OS patching --- CHANGELOG.md | 6 ++ .../aks_cluster_configuration/fetcher.py | 8 ++ .../aks_cluster_configuration/fetcher.yaml | 5 +- fetchers/azure/mysql_configuration/fetcher.py | 10 +++ .../azure/mysql_configuration/fetcher.yaml | 4 +- .../azure/postgresql_configuration/fetcher.py | 10 +++ .../postgresql_configuration/fetcher.yaml | 4 +- tests/test_azure_config_summary_counts.py | 90 +++++++++++++++++++ 8 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 tests/test_azure_config_summary_counts.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 56a905d2..0b969ecc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,12 @@ schemas and the `paramify` CLI — not the internal code. ### Added +- **Summary counts for database encryption, AKS autoscaling and node OS patching.** + `azure_postgresql_configuration` and `azure_mysql_configuration` 0.3.0 add `customer_managed_key_servers` and + `data_encryption_unknown_servers` from each server's data encryption type (AzureKeyVault or SystemManaged); a + server with no type is counted apart, never as platform-managed. `azure_aks_cluster_configuration` 0.6.0 adds + `autoscaling_agent_pools`, `node_os_auto_upgrade_clusters` (SecurityPatch or NodeImage) and + `node_os_upgrade_channel_unknown_clusters`, null like the other counts when the cluster list can't be read. - **`wiz_inventory`**, the Wiz cloud resource inventory, as a pipeline fetcher (`kind: inventory`, `id_scheme: wiz-resource-id`). One record per resource from `cloudResourcesV2` under `payload.data`, keyed by the Wiz resource id, with its cloud ID (`external_id`), account, region, type, IPs, OS, image, environment and owner, and internet diff --git a/fetchers/azure/aks_cluster_configuration/fetcher.py b/fetchers/azure/aks_cluster_configuration/fetcher.py index 6c50281b..369e1ae9 100644 --- a/fetchers/azure/aks_cluster_configuration/fetcher.py +++ b/fetchers/azure/aks_cluster_configuration/fetcher.py @@ -42,6 +42,8 @@ # auto_upgrade_profile.upgrade_channel: "none" is the literal for "no automatic # upgrades"; an absent field means the same thing. UPGRADE_CHANNEL_NONE = "none" +# auto_upgrade_profile.node_os_upgrade_channel values that patch node images on their own. +NODE_OS_AUTO_UPGRADE_CHANNELS = frozenset({"securitypatch", "nodeimage"}) KINDS = ("cluster",) @@ -298,6 +300,12 @@ def summarize(clusters: list[dict] | None) -> dict: ), "clusters_with_public_node_ips": sum(1 for c in clusters if c["node_public_ip_pools"]), "total_agent_pools": sum(len(c["agent_pool_profiles"]) for c in clusters), + "autoscaling_agent_pools": sum(1 for c in clusters for p in c["agent_pool_profiles"] if p.get("enable_auto_scaling") is True), + # SecurityPatch and NodeImage patch node images automatically; None and Unmanaged do not. + "node_os_auto_upgrade_clusters": sum( + 1 for c in clusters if str(c.get("node_os_upgrade_channel") or "").lower() in NODE_OS_AUTO_UPGRADE_CHANNELS + ), + "node_os_upgrade_channel_unknown_clusters": sum(1 for c in clusters if c.get("node_os_upgrade_channel") is None), **summarize_node_security([p for c in clusters for p in c["agent_pool_profiles"]]), # Sorted unique: the version spread at a glance, and a byte-stable payload. "kubernetes_versions": sorted( diff --git a/fetchers/azure/aks_cluster_configuration/fetcher.yaml b/fetchers/azure/aks_cluster_configuration/fetcher.yaml index 01611160..04947511 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.5.0 +version: 0.6.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 @@ -90,6 +90,9 @@ evidence_set: 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; 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 + - autoscaling_agent_pools — Number of node pools with the cluster autoscaler enabled; null when the cluster list could not be read + - node_os_auto_upgrade_clusters — Number of clusters whose node OS upgrade channel patches node images automatically (SecurityPatch or NodeImage); None and Unmanaged do not + - node_os_upgrade_channel_unknown_clusters — Number of clusters for which Azure returned no node OS upgrade channel; counted apart, never as automatic - 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 diff --git a/fetchers/azure/mysql_configuration/fetcher.py b/fetchers/azure/mysql_configuration/fetcher.py index bf1ab1ba..e39fad4b 100644 --- a/fetchers/azure/mysql_configuration/fetcher.py +++ b/fetchers/azure/mysql_configuration/fetcher.py @@ -91,6 +91,8 @@ def project_mysql_server(server) -> dict: "delegated_subnet_resource_id": model_attr(network, "delegated_subnet_resource_id"), "backup_retention_days": model_attr(backup, "backup_retention_days"), "geo_redundant_backup": model_attr(backup, "geo_redundant_backup"), + # SystemManaged or AzureKeyVault; None when Azure returned no data_encryption block. + "data_encryption_type": model_attr(model_attr(server, "data_encryption"), "type"), "high_availability_mode": model_attr(high_availability, "mode"), "high_availability_state": model_attr(high_availability, "state"), } @@ -184,6 +186,12 @@ def server_record(server: dict, configurations: list[dict]) -> dict: # --- durability --- "backup_retention_days": server.get("backup_retention_days"), "geo_redundant_backup": server.get("geo_redundant_backup"), + "data_encryption_type": server.get("data_encryption_type"), + # Unknown (None) when no type was returned: counted apart, never as platform-managed. + "customer_managed_key": ( + str(server["data_encryption_type"]).lower() == "azurekeyvault" + if server.get("data_encryption_type") else None + ), "geo_redundant_backup_enabled": ( str(server.get("geo_redundant_backup") or "").lower() == GEO_REDUNDANT_ENABLED ), @@ -218,6 +226,8 @@ def summarize(servers: list[dict]) -> dict: 1 for s in servers if s["geo_redundant_backup_enabled"] ), "high_availability_servers": sum(1 for s in servers if s["high_availability_enabled"]), + "customer_managed_key_servers": sum(1 for s in servers if s["customer_managed_key"] is True), + "data_encryption_unknown_servers": sum(1 for s in servers if s["customer_managed_key"] is None), "total_configuration_parameters": sum( s["total_configuration_parameters"] for s in servers ), diff --git a/fetchers/azure/mysql_configuration/fetcher.yaml b/fetchers/azure/mysql_configuration/fetcher.yaml index 23067560..5aac3c17 100644 --- a/fetchers/azure/mysql_configuration/fetcher.yaml +++ b/fetchers/azure/mysql_configuration/fetcher.yaml @@ -1,5 +1,5 @@ name: azure_mysql_configuration -version: 0.2.1 +version: 0.3.0 description: >- Shows whether each MySQL flexible server requires encrypted connections, accepts only current TLS versions, logs connections, blocks public access, and has geo-redundant backups and a standby. category: azure @@ -107,3 +107,5 @@ evidence_set: Will the server survive a zone or region loss? - geo_redundant_backup_servers — Number of servers whose backups are geo-redundant (stored in a second region too) - high_availability_servers — Number of servers with a high-availability mode other than Disabled (ZoneRedundant or SameZone); Disabled or no mode doesn't count + - customer_managed_key_servers — Number of servers whose data is encrypted with a customer-managed key from Azure Key Vault (data encryption type AzureKeyVault) rather than a platform-managed key + - data_encryption_unknown_servers — Number of servers for which Azure returned no data encryption type; counted apart, never as platform-managed diff --git a/fetchers/azure/postgresql_configuration/fetcher.py b/fetchers/azure/postgresql_configuration/fetcher.py index 99f9557e..7386aaae 100644 --- a/fetchers/azure/postgresql_configuration/fetcher.py +++ b/fetchers/azure/postgresql_configuration/fetcher.py @@ -119,6 +119,8 @@ def project_postgresql_server(server) -> dict: "delegated_subnet_resource_id": model_attr(network, "delegated_subnet_resource_id"), "backup_retention_days": model_attr(backup, "backup_retention_days"), "geo_redundant_backup": model_attr(backup, "geo_redundant_backup"), + # SystemManaged or AzureKeyVault; None when Azure returned no data_encryption block. + "data_encryption_type": model_attr(model_attr(server, "data_encryption"), "type"), "high_availability_mode": model_attr(high_availability, "mode"), "high_availability_state": model_attr(high_availability, "state"), } @@ -263,6 +265,12 @@ def server_record( # --- durability --- "backup_retention_days": server.get("backup_retention_days"), "geo_redundant_backup": server.get("geo_redundant_backup"), + "data_encryption_type": server.get("data_encryption_type"), + # Unknown (None) when no type was returned: counted apart, never as platform-managed. + "customer_managed_key": ( + str(server["data_encryption_type"]).lower() == "azurekeyvault" + if server.get("data_encryption_type") else None + ), "geo_redundant_backup_enabled": ( str(server.get("geo_redundant_backup") or "").lower() == GEO_REDUNDANT_ENABLED ), @@ -312,6 +320,8 @@ def summarize(servers: list[dict]) -> dict: 1 for s in servers if s["geo_redundant_backup_enabled"] ), "high_availability_servers": sum(1 for s in servers if s["high_availability_enabled"]), + "customer_managed_key_servers": sum(1 for s in servers if s["customer_managed_key"] is True), + "data_encryption_unknown_servers": sum(1 for s in servers if s["customer_managed_key"] is None), } diff --git a/fetchers/azure/postgresql_configuration/fetcher.yaml b/fetchers/azure/postgresql_configuration/fetcher.yaml index 41d9d87f..e9a14735 100644 --- a/fetchers/azure/postgresql_configuration/fetcher.yaml +++ b/fetchers/azure/postgresql_configuration/fetcher.yaml @@ -1,5 +1,5 @@ name: azure_postgresql_configuration -version: 0.2.1 +version: 0.3.0 description: >- Shows whether each PostgreSQL flexible server requires encrypted connections, uses Entra ID sign-in, logs activity, keeps its firewall closed, and has geo-redundant backups and a standby. category: azure @@ -120,3 +120,5 @@ evidence_set: Will the server survive a zone or region loss? - geo_redundant_backup_servers — Number of servers whose backups are geo-redundant (stored in a second region too) - high_availability_servers — Number of servers with a high-availability mode other than Disabled (ZoneRedundant or SameZone); Disabled or no mode doesn't count + - customer_managed_key_servers — Number of servers whose data is encrypted with a customer-managed key from Azure Key Vault (data encryption type AzureKeyVault) rather than a platform-managed key + - data_encryption_unknown_servers — Number of servers for which Azure returned no data encryption type; counted apart, never as platform-managed diff --git a/tests/test_azure_config_summary_counts.py b/tests/test_azure_config_summary_counts.py new file mode 100644 index 00000000..c51e1d6f --- /dev/null +++ b/tests/test_azure_config_summary_counts.py @@ -0,0 +1,90 @@ +"""Summary counts added for capability Validators: database data encryption key source (PostgreSQL and MySQL), AKS +autoscaling node pools and node OS auto-upgrade. Built from real SDK models deserialized from wire JSON, so an SDK that +renamed a field would fail here instead of reading every server as unknown. No network.""" + +from __future__ import annotations + +import importlib.util +import inspect +import sys +from pathlib import Path + +REPO_ROOT = Path(__file__).resolve().parent.parent +AZURE = REPO_ROOT / "fetchers" / "azure" +sys.path.insert(0, str(REPO_ROOT / "fetchers" / "_lib")) +sys.path.insert(0, str(AZURE / "_shared")) + + +def _load(name): + spec = importlib.util.spec_from_file_location(f"{name}_under_test", AZURE / name / "fetcher.py") + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +pg = _load("postgresql_configuration") +my = _load("mysql_configuration") +aks = _load("aks_cluster_configuration") + + +def _record(module, projected): + params = list(inspect.signature(module.server_record).parameters) + args = [projected] + [{} if "param" in p else [] for p in params[1:]] + return module.server_record(*args) + + +def _pg(encryption): + from azure.mgmt.postgresqlflexibleservers.models import Server + props = {"backup": {"backupRetentionDays": 7, "geoRedundantBackup": "Disabled"}} + if encryption: + props["dataEncryption"] = {"type": encryption} + return _record(pg, pg.project_postgresql_server(Server({"id": "/subscriptions/s/resourceGroups/rg/providers/x/flexibleServers/pg", + "name": "pg", "properties": props}))) + + +def _my(encryption): + from azure.mgmt.rdbms.mysql_flexibleservers.models import Server + props = {"backup": {"backupRetentionDays": 7, "geoRedundantBackup": "Disabled"}} + if encryption: + props["dataEncryption"] = {"type": encryption} + return _record(my, my.project_mysql_server(Server.deserialize({"id": "/subscriptions/s/resourceGroups/rg/providers/x/flexibleServers/my", + "name": "my", "properties": props}))) + + +def test_postgresql_key_source_is_read_from_the_sdk_model(): + assert (_pg("AzureKeyVault")["customer_managed_key"], _pg("SystemManaged")["customer_managed_key"], _pg(None)["customer_managed_key"]) == (True, False, None) + + +def test_mysql_key_source_is_read_from_the_sdk_model(): + assert (_my("AzureKeyVault")["customer_managed_key"], _my("SystemManaged")["customer_managed_key"], _my(None)["customer_managed_key"]) == (True, False, None) + + +def test_database_summaries_count_customer_keys_and_keep_unknown_apart(): + for module, make in ((pg, _pg), (my, _my)): + s = module.summarize([make("AzureKeyVault"), make("SystemManaged"), make(None)]) + assert (s["customer_managed_key_servers"], s["data_encryption_unknown_servers"]) == (1, 1) + + +def _cluster(channel, pools): + return {"agent_pool_profiles": [{"enable_auto_scaling": a} for a in pools], "node_os_upgrade_channel": channel, + "private_cluster": False, "api_server_access_restricted": False, "authorized_ip_ranges": [], "rbac_enabled": True, + "azure_rbac_enabled": False, "local_accounts_disabled": False, "workload_identity_enabled": False, + "network_policy_enabled": False, "auto_upgrade_enabled": False, "defender_enabled": False, + "azure_monitor_enabled": False, "node_public_ip_pools": [], "kubernetes_version": "1.30"} + + +def test_aks_counts_autoscaling_pools_and_node_os_auto_upgrade(): + clusters = [_cluster("NodeImage", [True, False]), _cluster("SecurityPatch", [True]), _cluster("Unmanaged", [False]), _cluster(None, [])] + s = aks.summarize(clusters) + assert (s["autoscaling_agent_pools"], s["node_os_auto_upgrade_clusters"], s["node_os_upgrade_channel_unknown_clusters"]) == (2, 2, 1) + + +def test_aks_new_counts_are_null_when_the_cluster_list_was_unread(): + s = aks.summarize(None) + assert (s["autoscaling_agent_pools"], s["node_os_auto_upgrade_clusters"], s["node_os_upgrade_channel_unknown_clusters"]) == (None, None, None) + + +def test_aks_node_os_channel_comes_from_the_sdk_model(): + from azure.mgmt.containerservice.models import ManagedCluster + cluster = ManagedCluster({"location": "eastus", "properties": {"autoUpgradeProfile": {"nodeOSUpgradeChannel": "SecurityPatch"}}}) + assert aks.project_managed_cluster(cluster)["node_os_upgrade_channel"] == "SecurityPatch" From d2f11d150872bf8e1cf66fc4e70422dc5d07b628 Mon Sep 17 00:00:00 2001 From: Bruce Weygandt Date: Tue, 17 Nov 2026 11:22:52 -0700 Subject: [PATCH 2/3] test(azure): run summary-count tests without the Azure SDK; pin the new fields in the SDK surface test --- tests/test_azure_config_summary_counts.py | 57 +++++++++-------------- tests/test_azure_sdk_surface.py | 39 ++++++++++++++++ 2 files changed, 62 insertions(+), 34 deletions(-) diff --git a/tests/test_azure_config_summary_counts.py b/tests/test_azure_config_summary_counts.py index c51e1d6f..77366cf8 100644 --- a/tests/test_azure_config_summary_counts.py +++ b/tests/test_azure_config_summary_counts.py @@ -1,6 +1,7 @@ """Summary counts added for capability Validators: database data encryption key source (PostgreSQL and MySQL), AKS -autoscaling node pools and node OS auto-upgrade. Built from real SDK models deserialized from wire JSON, so an SDK that -renamed a field would fail here instead of reading every server as unknown. No network.""" +autoscaling node pools and node OS auto-upgrade. Runs without the Azure SDKs: the fetchers read models through +model_attr (attribute access), so SimpleNamespace stands in for the SDK objects and the projection code still runs. +That the SDK models still declare these fields is pinned in test_azure_sdk_surface.py (the azure-sdk CI job).""" from __future__ import annotations @@ -8,6 +9,7 @@ import inspect import sys from pathlib import Path +from types import SimpleNamespace as NS REPO_ROOT = Path(__file__).resolve().parent.parent AZURE = REPO_ROOT / "fetchers" / "azure" @@ -27,41 +29,34 @@ def _load(name): aks = _load("aks_cluster_configuration") -def _record(module, projected): - params = list(inspect.signature(module.server_record).parameters) - args = [projected] + [{} if "param" in p else [] for p in params[1:]] - return module.server_record(*args) - - -def _pg(encryption): - from azure.mgmt.postgresqlflexibleservers.models import Server - props = {"backup": {"backupRetentionDays": 7, "geoRedundantBackup": "Disabled"}} - if encryption: - props["dataEncryption"] = {"type": encryption} - return _record(pg, pg.project_postgresql_server(Server({"id": "/subscriptions/s/resourceGroups/rg/providers/x/flexibleServers/pg", - "name": "pg", "properties": props}))) +def _server(encryption): + """The attributes the projections read; data_encryption absent when Azure returned none.""" + return NS(id="/subscriptions/s/resourceGroups/rg/providers/x/flexibleServers/db", name="db", type=None, location="eastus", + version=None, state="Ready", fully_qualified_domain_name=None, auth_config=None, + network=NS(public_network_access="Disabled", delegated_subnet_resource_id=None), + backup=NS(backup_retention_days=7, geo_redundant_backup="Disabled"), high_availability=None, + data_encryption=NS(type=encryption) if encryption else None) -def _my(encryption): - from azure.mgmt.rdbms.mysql_flexibleservers.models import Server - props = {"backup": {"backupRetentionDays": 7, "geoRedundantBackup": "Disabled"}} - if encryption: - props["dataEncryption"] = {"type": encryption} - return _record(my, my.project_mysql_server(Server.deserialize({"id": "/subscriptions/s/resourceGroups/rg/providers/x/flexibleServers/my", - "name": "my", "properties": props}))) +def _record(module, project, encryption): + params = list(inspect.signature(module.server_record).parameters) + args = [project(_server(encryption))] + [{} if "param" in p else [] for p in params[1:]] + return module.server_record(*args) -def test_postgresql_key_source_is_read_from_the_sdk_model(): - assert (_pg("AzureKeyVault")["customer_managed_key"], _pg("SystemManaged")["customer_managed_key"], _pg(None)["customer_managed_key"]) == (True, False, None) +def test_postgresql_key_source_comes_through_the_projection(): + got = [_record(pg, pg.project_postgresql_server, e)["customer_managed_key"] for e in ("AzureKeyVault", "SystemManaged", None)] + assert got == [True, False, None] -def test_mysql_key_source_is_read_from_the_sdk_model(): - assert (_my("AzureKeyVault")["customer_managed_key"], _my("SystemManaged")["customer_managed_key"], _my(None)["customer_managed_key"]) == (True, False, None) +def test_mysql_key_source_comes_through_the_projection(): + got = [_record(my, my.project_mysql_server, e)["customer_managed_key"] for e in ("AzureKeyVault", "SystemManaged", None)] + assert got == [True, False, None] def test_database_summaries_count_customer_keys_and_keep_unknown_apart(): - for module, make in ((pg, _pg), (my, _my)): - s = module.summarize([make("AzureKeyVault"), make("SystemManaged"), make(None)]) + for module, project in ((pg, pg.project_postgresql_server), (my, my.project_mysql_server)): + s = module.summarize([_record(module, project, e) for e in ("AzureKeyVault", "SystemManaged", None)]) assert (s["customer_managed_key_servers"], s["data_encryption_unknown_servers"]) == (1, 1) @@ -82,9 +77,3 @@ def test_aks_counts_autoscaling_pools_and_node_os_auto_upgrade(): def test_aks_new_counts_are_null_when_the_cluster_list_was_unread(): s = aks.summarize(None) assert (s["autoscaling_agent_pools"], s["node_os_auto_upgrade_clusters"], s["node_os_upgrade_channel_unknown_clusters"]) == (None, None, None) - - -def test_aks_node_os_channel_comes_from_the_sdk_model(): - from azure.mgmt.containerservice.models import ManagedCluster - cluster = ManagedCluster({"location": "eastus", "properties": {"autoUpgradeProfile": {"nodeOSUpgradeChannel": "SecurityPatch"}}}) - assert aks.project_managed_cluster(cluster)["node_os_upgrade_channel"] == "SecurityPatch" diff --git a/tests/test_azure_sdk_surface.py b/tests/test_azure_sdk_surface.py index 58742707..6e76bfb8 100644 --- a/tests/test_azure_sdk_surface.py +++ b/tests/test_azure_sdk_surface.py @@ -1624,6 +1624,45 @@ def test_operation_group_surface( ["enable_fips", "node_image_version", "security_profile"], "azure/aks_cluster_configuration — a renamed enable_fips reads every pool as FIPS unknown", ), + ( + "azure.mgmt.containerservice.models", + "ManagedClusterAgentPoolProfile", + ["enable_auto_scaling"], + "azure/aks_cluster_configuration — a renamed enable_auto_scaling counts no pool as autoscaling", + ), + ( + "azure.mgmt.containerservice.models", + "ManagedClusterAutoUpgradeProfile", + ["node_os_upgrade_channel"], + "azure/aks_cluster_configuration — a renamed node_os_upgrade_channel reads every cluster's node OS channel as unknown", + ), + # azure-mgmt-postgresqlflexibleservers is a TypeSpec SDK: data_encryption is + # declared on ServerProperties and flattened onto Server for attribute access, + # so the properties model is where a rename would show. + ( + "azure.mgmt.postgresqlflexibleservers.models", + "ServerProperties", + ["data_encryption"], + "azure/postgresql_configuration — a renamed data_encryption reads every server's key source as unknown", + ), + ( + "azure.mgmt.postgresqlflexibleservers.models", + "DataEncryption", + ["type"], + "azure/postgresql_configuration — data encryption type (AzureKeyVault or SystemManaged)", + ), + ( + "azure.mgmt.rdbms.mysql_flexibleservers.models", + "Server", + ["data_encryption"], + "azure/mysql_configuration — a renamed data_encryption reads every server's key source as unknown", + ), + ( + "azure.mgmt.rdbms.mysql_flexibleservers.models", + "DataEncryption", + ["type"], + "azure/mysql_configuration — data encryption type (AzureKeyVault or SystemManaged)", + ), ( "azure.mgmt.containerservice.models", "AgentPoolSecurityProfile", From f01061057d6b59b03fdf7bb8cd257a13b92697be Mon Sep 17 00:00:00 2001 From: Bruce Weygandt Date: Tue, 17 Nov 2026 13:23:23 -0700 Subject: [PATCH 3/3] fix(azure): SDK surface row accepts postgresqlflexibleservers 2.x, count Unmanaged node OS apart, clarify autoscaling and KSIs --- CHANGELOG.md | 3 ++- .../aks_cluster_configuration/fetcher.py | 11 ++++++++-- .../aks_cluster_configuration/fetcher.yaml | 6 ++++-- .../azure/mysql_configuration/fetcher.yaml | 2 +- .../postgresql_configuration/fetcher.yaml | 2 +- tests/test_azure_config_summary_counts.py | 3 +++ tests/test_azure_sdk_surface.py | 21 +++++++++++++++---- 7 files changed, 37 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b969ecc..54fe1684 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,8 @@ schemas and the `paramify` CLI — not the internal code. `azure_postgresql_configuration` and `azure_mysql_configuration` 0.3.0 add `customer_managed_key_servers` and `data_encryption_unknown_servers` from each server's data encryption type (AzureKeyVault or SystemManaged); a server with no type is counted apart, never as platform-managed. `azure_aks_cluster_configuration` 0.6.0 adds - `autoscaling_agent_pools`, `node_os_auto_upgrade_clusters` (SecurityPatch or NodeImage) and + `autoscaling_agent_pools`, `node_os_auto_upgrade_clusters` (SecurityPatch or NodeImage), + `node_os_unmanaged_clusters` (Unmanaged, where the node OS may still install its own updates, counted apart) and `node_os_upgrade_channel_unknown_clusters`, null like the other counts when the cluster list can't be read. - **`wiz_inventory`**, the Wiz cloud resource inventory, as a pipeline fetcher (`kind: inventory`, `id_scheme: wiz-resource-id`). One record per resource from `cloudResourcesV2` under `payload.data`, keyed by the Wiz resource diff --git a/fetchers/azure/aks_cluster_configuration/fetcher.py b/fetchers/azure/aks_cluster_configuration/fetcher.py index 369e1ae9..35dc885c 100644 --- a/fetchers/azure/aks_cluster_configuration/fetcher.py +++ b/fetchers/azure/aks_cluster_configuration/fetcher.py @@ -42,8 +42,11 @@ # auto_upgrade_profile.upgrade_channel: "none" is the literal for "no automatic # upgrades"; an absent field means the same thing. UPGRADE_CHANNEL_NONE = "none" -# auto_upgrade_profile.node_os_upgrade_channel values that patch node images on their own. +# auto_upgrade_profile.node_os_upgrade_channel values that replace node images (or apply security patches to them) +# on their own. Unmanaged leaves node images alone but lets the node OS's own updater install security updates, such +# as Ubuntu's nightly unattended upgrades with no automatic reboot; None installs nothing. NODE_OS_AUTO_UPGRADE_CHANNELS = frozenset({"securitypatch", "nodeimage"}) +NODE_OS_UNMANAGED_CHANNEL = "unmanaged" KINDS = ("cluster",) @@ -301,10 +304,14 @@ def summarize(clusters: list[dict] | None) -> dict: "clusters_with_public_node_ips": sum(1 for c in clusters if c["node_public_ip_pools"]), "total_agent_pools": sum(len(c["agent_pool_profiles"]) for c in clusters), "autoscaling_agent_pools": sum(1 for c in clusters for p in c["agent_pool_profiles"] if p.get("enable_auto_scaling") is True), - # SecurityPatch and NodeImage patch node images automatically; None and Unmanaged do not. + # SecurityPatch and NodeImage update node images automatically. Unmanaged is counted apart: the node OS may + # still install its own updates, which this count must not read as "no patching". "node_os_auto_upgrade_clusters": sum( 1 for c in clusters if str(c.get("node_os_upgrade_channel") or "").lower() in NODE_OS_AUTO_UPGRADE_CHANNELS ), + "node_os_unmanaged_clusters": sum( + 1 for c in clusters if str(c.get("node_os_upgrade_channel") or "").lower() == NODE_OS_UNMANAGED_CHANNEL + ), "node_os_upgrade_channel_unknown_clusters": sum(1 for c in clusters if c.get("node_os_upgrade_channel") is None), **summarize_node_security([p for c in clusters for p in c["agent_pool_profiles"]]), # Sorted unique: the version spread at a glance, and a byte-stable payload. diff --git a/fetchers/azure/aks_cluster_configuration/fetcher.yaml b/fetchers/azure/aks_cluster_configuration/fetcher.yaml index 04947511..2be0e763 100644 --- a/fetchers/azure/aks_cluster_configuration/fetcher.yaml +++ b/fetchers/azure/aks_cluster_configuration/fetcher.yaml @@ -63,6 +63,7 @@ ksis: - KSI-IAM-ELP # Kubernetes RBAC + Entra-integrated Azure RBAC, local admin accounts disabled - KSI-IAM-SNU # workload identity and the OIDC issuer - KSI-SVC-EIS # cluster and node-OS auto-upgrade channels + - KSI-CNA-OFA # node pools with the cluster autoscaler evidence_set: reference_id: EVD-AZURE-AKS-CONFIG @@ -90,8 +91,9 @@ evidence_set: 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; 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 - - autoscaling_agent_pools — Number of node pools with the cluster autoscaler enabled; null when the cluster list could not be read - - node_os_auto_upgrade_clusters — Number of clusters whose node OS upgrade channel patches node images automatically (SecurityPatch or NodeImage); None and Unmanaged do not + - autoscaling_agent_pools — Number of node pools with the cluster autoscaler enabled; a cluster that scales with node auto-provisioning instead adds nodes without the cluster autoscaler on its pools, so its pools do not count here; null when the cluster list could not be read + - node_os_auto_upgrade_clusters — Number of clusters whose node OS upgrade channel replaces or patches node images automatically (SecurityPatch or NodeImage); Unmanaged and None do not, and an enabled channel does not show that updates were applied + - node_os_unmanaged_clusters — Number of clusters on the Unmanaged node OS channel, which leaves node images alone but lets the node OS install its own updates (on Ubuntu, nightly security updates with no automatic reboot); counted apart, never as automatic and never as unpatched - node_os_upgrade_channel_unknown_clusters — Number of clusters for which Azure returned no node OS upgrade channel; counted apart, never as automatic - 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 diff --git a/fetchers/azure/mysql_configuration/fetcher.yaml b/fetchers/azure/mysql_configuration/fetcher.yaml index 5aac3c17..6fadb094 100644 --- a/fetchers/azure/mysql_configuration/fetcher.yaml +++ b/fetchers/azure/mysql_configuration/fetcher.yaml @@ -57,7 +57,7 @@ target_schema: secrets: [] # DefaultAzureCredential only — no handed-over secret (see _categories/azure.yaml) ksis: - - KSI-SVC-SIN # require_secure_transport and the tls_version ACCEPTED list + - KSI-SVC-SIN # require_secure_transport, the tls_version ACCEPTED list, and customer-managed key encryption at rest - KSI-CNA-MAT # public network access - KSI-MLA-LET # audit_log_enabled and the audit_log_events classes - KSI-RPL-ABO # geo-redundant backup diff --git a/fetchers/azure/postgresql_configuration/fetcher.yaml b/fetchers/azure/postgresql_configuration/fetcher.yaml index e9a14735..03cecba9 100644 --- a/fetchers/azure/postgresql_configuration/fetcher.yaml +++ b/fetchers/azure/postgresql_configuration/fetcher.yaml @@ -58,7 +58,7 @@ target_schema: secrets: [] # DefaultAzureCredential only — no handed-over secret (see _categories/azure.yaml) ksis: - - KSI-SVC-SIN # require_secure_transport + - KSI-SVC-SIN # require_secure_transport, and customer-managed key encryption at rest - KSI-CNA-RNT # firewall rules, allow-all-Azure pseudo-rule flagged - KSI-IAM-APM # Entra ID authentication and its assigned administrators - KSI-MLA-LET # log_checkpoints / log_connections / log_disconnections / log_retention_days diff --git a/tests/test_azure_config_summary_counts.py b/tests/test_azure_config_summary_counts.py index 77366cf8..eee49928 100644 --- a/tests/test_azure_config_summary_counts.py +++ b/tests/test_azure_config_summary_counts.py @@ -72,8 +72,11 @@ def test_aks_counts_autoscaling_pools_and_node_os_auto_upgrade(): clusters = [_cluster("NodeImage", [True, False]), _cluster("SecurityPatch", [True]), _cluster("Unmanaged", [False]), _cluster(None, [])] s = aks.summarize(clusters) assert (s["autoscaling_agent_pools"], s["node_os_auto_upgrade_clusters"], s["node_os_upgrade_channel_unknown_clusters"]) == (2, 2, 1) + # Unmanaged is its own count: not automatic, and not read as unpatched either. + assert s["node_os_unmanaged_clusters"] == 1 def test_aks_new_counts_are_null_when_the_cluster_list_was_unread(): s = aks.summarize(None) assert (s["autoscaling_agent_pools"], s["node_os_auto_upgrade_clusters"], s["node_os_upgrade_channel_unknown_clusters"]) == (None, None, None) + assert s["node_os_unmanaged_clusters"] is None diff --git a/tests/test_azure_sdk_surface.py b/tests/test_azure_sdk_surface.py index 6e76bfb8..98e637fd 100644 --- a/tests/test_azure_sdk_surface.py +++ b/tests/test_azure_sdk_surface.py @@ -95,6 +95,18 @@ def _build(module: str, client_name: str) -> object: raise AssertionError(f"could not construct {client_name} offline: {last}") +def _import_first(module: str, names: str) -> object: + """`names` may list alternatives as `A|B`: the first one the installed SDK declares is returned. For a field one + major declares on a properties model and an older major declares on the resource model itself.""" + *alternatives, last = names.split("|") + for name in alternatives: + try: + return _import(module, name) + except AttributeError: + continue + return _import(module, last) + + def _model_fields(model: type) -> set[str]: """Declared field names, across both Azure model generations. @@ -1636,12 +1648,13 @@ def test_operation_group_surface( ["node_os_upgrade_channel"], "azure/aks_cluster_configuration — a renamed node_os_upgrade_channel reads every cluster's node OS channel as unknown", ), - # azure-mgmt-postgresqlflexibleservers is a TypeSpec SDK: data_encryption is + # azure-mgmt-postgresqlflexibleservers 3 is a TypeSpec SDK: data_encryption is # declared on ServerProperties and flattened onto Server for attribute access, - # so the properties model is where a rename would show. + # so the properties model is where a rename would show. 2.x (still allowed by + # the pin) has no ServerProperties and declares data_encryption on Server. ( "azure.mgmt.postgresqlflexibleservers.models", - "ServerProperties", + "ServerProperties|Server", ["data_encryption"], "azure/postgresql_configuration — a renamed data_encryption reads every server's key source as unknown", ), @@ -4039,7 +4052,7 @@ def test_model_fields_present( module: str, model: str, fields: list[str], affects: str ) -> None: """A model field a fetcher reads must still be declared.""" - declared = _model_fields(_import(module, model)) # type: ignore[arg-type] + declared = _model_fields(_import_first(module, model)) # type: ignore[arg-type] missing = [f for f in fields if f not in declared] assert not missing, ( f"{model} no longer declares: {', '.join(missing)}\n"