From d0213d720948d650b5088a1361acd17f7059a0ee Mon Sep 17 00:00:00 2001 From: kiskaadee Date: Sat, 31 Oct 2026 14:06:09 -0500 Subject: [PATCH] security(router): prevent workload .env override of reserved platform configuration - Add platform routing, networking, and Docker config keys to RESERVED_ENV_KEYS (CR-DI-07) - Add unit tests verifying rejection of reserved platform variables in manifest.env --- scripts/core_manifest.py | 22 ++++++++++++++++------ tests/unit/test_core_manifest.py | 23 +++++++++++++++++++---- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/scripts/core_manifest.py b/scripts/core_manifest.py index 590b582..efb4735 100644 --- a/scripts/core_manifest.py +++ b/scripts/core_manifest.py @@ -72,10 +72,25 @@ RESERVED_ENV_KEYS = { "SITES_DIR", "ENV_FILE", "HOMESERVER_ENV", + "HOMELAB_DOMAIN", + "DOMAIN_SUFFIX", + "DOMAIN", + "PROXY_NETWORK", + "CERT_RESOLVER", + "DOCKER_CONFIG", + "SERVICE_NAME", + "CONTAINER_NAME", + "SERVICE_DOMAIN", } ALLOWED_STRATEGIES = {"compose"} -ALLOWED_ACTIONS = {"git_pull", "compose_pull", "compose_up", "compose_build", "compose_restart"} +ALLOWED_ACTIONS = { + "git_pull", + "compose_pull", + "compose_up", + "compose_build", + "compose_restart", +} def validate_transport(url: str) -> tuple[TransportScheme, str]: @@ -168,13 +183,11 @@ def classify_ref(ref_str: str) -> tuple[RefType, str]: return RefType.BRANCH, ref - class SourceConfig(BaseModel): """Upstream source provenance descriptor.""" model_config = ConfigDict(extra="forbid", ignored_types=(dict,)) - url: str ref: str = "main" type: str = "git" @@ -223,7 +236,6 @@ class DeploymentConfig(BaseModel): model_config = ConfigDict(extra="forbid", ignored_types=(dict,)) - strategy: str = "compose" branch: str = "main" actions: list[str] = Field(default_factory=lambda: ["git_pull", "compose_up"]) @@ -264,7 +276,6 @@ class HomepageConfig(BaseModel): model_config = ConfigDict(extra="forbid", ignored_types=(dict,)) - title: str group: str = "Applications" icon: str = "default.png" @@ -295,7 +306,6 @@ class Manifest(BaseModel): ignored_types=(dict,), ) - name: str schema_version: str = Field(default="1.0", alias="schemaVersion") domain: str = "" diff --git a/tests/unit/test_core_manifest.py b/tests/unit/test_core_manifest.py index edf2f5e..af9905a 100644 --- a/tests/unit/test_core_manifest.py +++ b/tests/unit/test_core_manifest.py @@ -66,7 +66,9 @@ def test_validate_transport_rejects_http(insecure_url: str): ], ) def test_validate_transport_rejects_empty_or_non_string(empty_or_invalid_url): - with pytest.raises(ManifestValidationError, match=r"^Source URL cannot be empty\.$"): + with pytest.raises( + ManifestValidationError, match=r"^Source URL cannot be empty\.$" + ): validate_transport(empty_or_invalid_url) # type: ignore[arg-type] @@ -77,7 +79,9 @@ def test_validate_transport_rejects_empty_or_non_string(empty_or_invalid_url): ("ssh://git.example.com/", "SSH"), ], ) -def test_validate_transport_rejects_root_repository_path(root_path_url: str, scheme: str): +def test_validate_transport_rejects_root_repository_path( + root_path_url: str, scheme: str +): with pytest.raises( ManifestValidationError, match=rf"^Malformed {scheme} source URL \(missing repository path\)", @@ -132,8 +136,10 @@ def test_classify_ref_branches(): "feat/manifest-engine", ) assert classify_ref("release/v1.0") == (RefType.BRANCH, "release/v1.0") - assert classify_ref("custom-adhoc-branch") == (RefType.BRANCH, "custom-adhoc-branch") - + assert classify_ref("custom-adhoc-branch") == ( + RefType.BRANCH, + "custom-adhoc-branch", + ) def test_classify_ref_tags(): @@ -271,6 +277,15 @@ def test_parse_manifest_from_path(tmp_path: Path): "IFS", "CORE_DIR", "SITES_DIR", + "HOMELAB_DOMAIN", + "DOMAIN_SUFFIX", + "DOMAIN", + "PROXY_NETWORK", + "CERT_RESOLVER", + "DOCKER_CONFIG", + "SERVICE_NAME", + "CONTAINER_NAME", + "SERVICE_DOMAIN", ], ) def test_parse_manifest_rejects_invalid_or_reserved_env_keys(invalid_key: str):