Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ 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),
`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.
- `paramify upload --no-waf-check` turns off the check that drops a file holding `../`, `/etc/passwd`, `/bin/sh`,
`/bin/bash` or `<script` before the upload. Those strings were confirmed blocked on one host's WAF, but some hosts
exempt the upload routes, so CVE text in a findings file was dropped though the WAF would accept it. With the flag
Expand Down
15 changes: 15 additions & 0 deletions fetchers/azure/aks_cluster_configuration/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +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 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",)


Expand Down Expand Up @@ -298,6 +303,16 @@ 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 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.
"kubernetes_versions": sorted(
Expand Down
7 changes: 6 additions & 1 deletion fetchers/azure/aks_cluster_configuration/fetcher.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -90,6 +91,10 @@ 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; 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

Expand Down
10 changes: 10 additions & 0 deletions fetchers/azure/mysql_configuration/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
Expand Down Expand Up @@ -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
),
Expand Down Expand Up @@ -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
),
Expand Down
6 changes: 4 additions & 2 deletions fetchers/azure/mysql_configuration/fetcher.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
10 changes: 10 additions & 0 deletions fetchers/azure/postgresql_configuration/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
Expand Down Expand Up @@ -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
),
Expand Down Expand Up @@ -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),
}


Expand Down
6 changes: 4 additions & 2 deletions fetchers/azure/postgresql_configuration/fetcher.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
82 changes: 82 additions & 0 deletions tests/test_azure_config_summary_counts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
"""Summary counts added for capability Validators: database data encryption key source (PostgreSQL and MySQL), AKS
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

import importlib.util
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"
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 _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 _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_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_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, 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)


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)
# 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
54 changes: 53 additions & 1 deletion tests/test_azure_sdk_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -1624,6 +1636,46 @@ 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 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. 2.x (still allowed by
# the pin) has no ServerProperties and declares data_encryption on Server.
(
"azure.mgmt.postgresqlflexibleservers.models",
"ServerProperties|Server",
["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",
Expand Down Expand Up @@ -4000,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"
Expand Down
Loading