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
This commit is contained in:
kiskaadee committed 2026-10-31 14:06:09 -05:00
1 parent 178a0c8990
commit d0213d7209
2 files changed
+35 -10

No files matched your search

+16 -6
View File
@@ -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 = ""
+19 -4
View File
@@ -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):