From fbfbe9375fe61f75aae4161818cfe1e7074de9aa Mon Sep 17 00:00:00 2001 From: kiskaadee Date: Thu, 15 Oct 2026 03:45:22 -0500 Subject: [PATCH] feat(core): enforce platform genericism invariant and scrub hardcoded domains - Remove hardcoded roadtotech.me domain defaults in scripts/appctl and scripts/appctl_engine.py - Enforce domain environment variable precedence (HOMELAB_DOMAIN -> DOMAIN_SUFFIX -> DOMAIN) - Replace personal domains and operator usernames across test fixtures with RFC 2606 placeholders (example.com, example.org, example.test) - Add automated CI invariant test verifying zero personal domain/operator literals in scripts and tests --- AGENTS.md | 2 +- scripts/appctl | 5 +++-- scripts/appctl_engine.py | 6 ++--- tests/security/test_security_invariants.py | 24 +++++++++++++++++++- tests/unit/test_appctl_engine.py | 22 +++++++++--------- tests/unit/test_core_manifest.py | 26 +++++++++++----------- tests/unit/test_provenance.py | 6 ++--- 7 files changed, 57 insertions(+), 34 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 5010015..b597d3f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -106,7 +106,7 @@ Core platform code, templates, and documentation must remain strictly instance-a - Instance-specific domains (e.g. personal domain names), operator usernames, and deployment topologies must never be hardcoded into Core platform definitions. - All routing and service identities must be injected declaratively at runtime via environment variables (`HOMELAB_DOMAIN`, `DOMAIN_SUFFIX`) and local configuration overlays. -- Example manifests, tests, and documentation must use RFC-compliant generic placeholders (e.g. `example.com`, `example.org`, `testdomain.local`). +- Example manifests, tests, and documentation must use RFC-compliant generic placeholders (e.g. `example.com`, `example.org`, `example.test`). ### 9. License diff --git a/scripts/appctl b/scripts/appctl index a9b045c..0d5b2e6 100755 --- a/scripts/appctl +++ b/scripts/appctl @@ -36,7 +36,8 @@ if [ -f "$ENV_FILE" ]; then fi # Lock the homelab root domain before setup_app_env can mutate $DOMAIN -export HOMELAB_DOMAIN="${HOMELAB_DOMAIN:-${DOMAIN_SUFFIX:-${DOMAIN:-roadtotech.me}}}" +# Canonical precedence: HOMELAB_DOMAIN -> DOMAIN_SUFFIX -> DOMAIN +export HOMELAB_DOMAIN="${HOMELAB_DOMAIN:-${DOMAIN_SUFFIX:-${DOMAIN:-}}}" # Show help usage show_help() { @@ -98,7 +99,7 @@ setup_app_env() { export PROXY_NETWORK="${PROXY_NETWORK:-proxy-net}" export NETWORK_NAME="${NETWORK_NAME:-$PROXY_NETWORK}" export CERT_RESOLVER="${CERT_RESOLVER:-myresolver}" - export DOMAIN_SUFFIX="${DOMAIN_SUFFIX:-roadtotech.me}" + export DOMAIN_SUFFIX="${DOMAIN_SUFFIX:-$HOMELAB_DOMAIN}" # 2. Canonical application identity export SERVICE_NAME="$CANONICAL_NAME" diff --git a/scripts/appctl_engine.py b/scripts/appctl_engine.py index a53cb2a..12a932f 100755 --- a/scripts/appctl_engine.py +++ b/scripts/appctl_engine.py @@ -56,8 +56,8 @@ def validate_environment() -> None: if not HOMELAB_DOMAIN: errors.append( - "• Missing 'HOMELAB_DOMAIN' (or 'DOMAIN') environment variable.\n" - " Please export it (e.g. export HOMELAB_DOMAIN='roadtotech.me') or set it in your environment file." + "• Missing 'HOMELAB_DOMAIN' (or 'DOMAIN_SUFFIX' / 'DOMAIN') environment variable.\n" + " Please export it (e.g. export HOMELAB_DOMAIN='example.com') or set it in your environment file." ) if not os.path.isdir(CORE_DIR): @@ -77,7 +77,7 @@ ManifestError = ManifestValidationError class App: name: str # Canonical identifier (e.g., "traefik", "jellyfin") description: str = "" # Human-readable summary for dashboards and CLI info - domain: str = "" # Routing FQDN (e.g., "auth.roadtotech.me") or "internal". + domain: str = "" # Routing FQDN (e.g., "auth.example.com") or "internal". dir_path: str = "" # Filesystem directory (CORE_DIR for Core, or ~/Sites/ for Sites). @property diff --git a/tests/security/test_security_invariants.py b/tests/security/test_security_invariants.py index 1c9cd79..61a6909 100644 --- a/tests/security/test_security_invariants.py +++ b/tests/security/test_security_invariants.py @@ -101,7 +101,7 @@ def test_appctl_env_injection_resilience(tmp_path: Path): resolved_json = json.dumps({ "name": "test-app", - "domain": "test.roadtotech.me", + "domain": "test.example.com", "dir_path": str(tmp_path), "env": {"INJECTION_TEST": payload, "NORMAL_VAR": "safe_value"}, }) @@ -141,4 +141,26 @@ if isinstance(env_dict, dict): assert "NORMAL_VAR=safe_value" in res.stdout +def test_platform_genericism_no_hardcoded_personal_domains_in_scripts_and_tests(): + """Ensure personal domains and operator usernames are absent from scripts and test files.""" + forbidden = ["roadtotech.me", "kiskaadee"] + root_dirs = [CORE_ROOT / "scripts", CORE_ROOT / "tests"] + violations = [] + + for root_dir in root_dirs: + for file_path in root_dir.rglob("*"): + if ( + file_path.is_file() + and file_path.suffix in (".py", ".sh", ".bash", ".yml", ".yaml", "") + and file_path.name != "test_security_invariants.py" + ): + content = file_path.read_text(encoding="utf-8", errors="ignore") + for term in forbidden: + if term in content: + violations.append(f"{file_path.relative_to(CORE_ROOT)}: contains prohibited literal '{term}'") + + assert not violations, "Platform genericism violations detected:\n" + "\n".join(violations) + + + diff --git a/tests/unit/test_appctl_engine.py b/tests/unit/test_appctl_engine.py index 4c735eb..98b8f86 100644 --- a/tests/unit/test_appctl_engine.py +++ b/tests/unit/test_appctl_engine.py @@ -101,7 +101,7 @@ def test_sites_app_normalization(app_factory: AppFactory): dir_name="homelab-custom", manifest_yaml=""" name: testapp - # Missing domain - should fallback to .roadtotech.me + # Missing domain - should fallback to . aliases: single-string-alias # should become a list[str] auth: "False" # should evaluate based on boolean casting homepage: @@ -129,7 +129,7 @@ def test_sites_app_source_provenance_normalization(app_factory: AppFactory): name: bitetrack source: type: git - url: https://git.roadtotech.me/kiskaadee/bitetrack.git + url: https://git.example.com/operator/bitetrack.git ref: v1.2.0 """ ) @@ -139,7 +139,7 @@ def test_sites_app_source_provenance_normalization(app_factory: AppFactory): manifest_yaml=""" name: doc2site source: - url: https://git.roadtotech.me/kiskaadee/doc2site.git + url: https://git.example.com/operator/doc2site.git """ ) # 3. Image-only app (no source block) @@ -156,7 +156,7 @@ def test_sites_app_source_provenance_normalization(app_factory: AppFactory): assert bitetrack is not None assert bitetrack.source is not None assert bitetrack.source.type == "git" - assert bitetrack.source.url == "https://git.roadtotech.me/kiskaadee/bitetrack.git" + assert bitetrack.source.url == "https://git.example.com/operator/bitetrack.git" assert bitetrack.source.ref == "v1.2.0" assert bitetrack.to_dict()["source"]["ref"] == "v1.2.0" @@ -349,8 +349,8 @@ def test_homepage_sync_core_services_domain_isolation( hp_config_dir = mock_core_dir / "config" / "homepage" hp_config_dir.mkdir(parents=True, exist_ok=True) - monkeypatch.setattr(engine, "HOMELAB_DOMAIN", "roadtotech.me") - monkeypatch.setenv("DOMAIN", "mermaid.roadtotech.me") + monkeypatch.setattr(engine, "HOMELAB_DOMAIN", "example.com") + monkeypatch.setenv("DOMAIN", "mermaid.example.com") engine.cmd_sync_homepage(["--homepage-dir=" + str(hp_config_dir)]) @@ -358,10 +358,10 @@ def test_homepage_sync_core_services_domain_isolation( assert output_file.exists() content = output_file.read_text() - assert "https://dashboard.roadtotech.me" in content - assert "https://traefik.roadtotech.me" in content - assert "https://auth.roadtotech.me" in content - assert "mermaid.roadtotech.me" not in content + assert "https://dashboard.example.com" in content + assert "https://traefik.example.com" in content + assert "https://auth.example.com" in content + assert "mermaid.example.com" not in content def test_resolve_core_stack_type(): @@ -433,7 +433,7 @@ def test_unification_uses_core_manifest_dataclasses(app_factory: AppFactory): manifest_yaml=""" name: unified source: - url: https://git.roadtotech.me/kiskaadee/unified.git + url: https://git.example.com/operator/unified.git ref: v1.0.0 homepage: title: Unified App diff --git a/tests/unit/test_core_manifest.py b/tests/unit/test_core_manifest.py index 4b6f5dd..edb1ef2 100644 --- a/tests/unit/test_core_manifest.py +++ b/tests/unit/test_core_manifest.py @@ -22,25 +22,25 @@ from core_manifest import ( def test_validate_transport_https(): - scheme, url = validate_transport("https://gitea.roadtotech.me/kiskaadee/homelab-snappymail.git") + scheme, url = validate_transport("https://git.example.com/operator/homelab-snappymail.git") assert scheme == TransportScheme.HTTPS - assert url == "https://gitea.roadtotech.me/kiskaadee/homelab-snappymail.git" + assert url == "https://git.example.com/operator/homelab-snappymail.git" def test_validate_transport_ssh(): - scheme, url = validate_transport("ssh://git@gitea.roadtotech.me:2223/kiskaadee/homelab-docs.git") + scheme, url = validate_transport("ssh://git@git.example.com:2223/operator/homelab-docs.git") assert scheme == TransportScheme.SSH - assert url == "ssh://git@gitea.roadtotech.me:2223/kiskaadee/homelab-docs.git" + assert url == "ssh://git@git.example.com:2223/operator/homelab-docs.git" def test_validate_transport_git_scp(): - scheme, url = validate_transport("git@github.com:kiskaadee/custom-workload.git") + scheme, url = validate_transport("git@github.com:operator/custom-workload.git") assert scheme == TransportScheme.GIT_SCP - assert url == "git@github.com:kiskaadee/custom-workload.git" + assert url == "git@github.com:operator/custom-workload.git" @pytest.mark.parametrize("insecure_url", [ - "http://insecure.roadtotech.me/repo.git", + "http://insecure.example.com/repo.git", "http://github.com/repo.git", ]) def test_validate_transport_rejects_http(insecure_url: str): @@ -50,7 +50,7 @@ def test_validate_transport_rejects_http(insecure_url: str): @pytest.mark.parametrize("traversal_url", [ "../../etc/shadow", - "/home/kiskaadee/secret", + "/home/operator/secret", "~/vault", "file:///etc/passwd", ]) @@ -83,7 +83,7 @@ schemaVersion: "1.0" name: "bitetrack" aliases: - "bt" -domain: "bitetrack.roadtotech.me" +domain: "bitetrack.example.com" description: "Nutrition and macro tracking application" visible: true auth: true @@ -93,7 +93,7 @@ env: PORT: 8080 source: type: git - url: "https://git.roadtotech.me/kiskaadee/bitetrack.git" + url: "https://git.example.com/operator/bitetrack.git" ref: "v1.2.0" deployment: strategy: compose @@ -116,7 +116,7 @@ homepage: assert manifest.is_class_b is False assert manifest.is_internal is False assert manifest.source is not None - assert manifest.source.url == "https://git.roadtotech.me/kiskaadee/bitetrack.git" + assert manifest.source.url == "https://git.example.com/operator/bitetrack.git" assert manifest.source.ref == "v1.2.0" assert manifest.source.ref_type == RefType.TAG assert manifest.source.transport == TransportScheme.HTTPS @@ -128,7 +128,7 @@ homepage: def test_parse_manifest_class_b_image_only(): raw_yaml = """ name: "snappymail" -domain: "mail.roadtotech.me" +domain: "mail.example.com" description: "Webmail Client" deployment: actions: @@ -144,7 +144,7 @@ deployment: def test_parse_manifest_rejects_missing_name(): with pytest.raises(ManifestValidationError, match="missing mandatory string field 'name'"): - parse_manifest("domain: test.roadtotech.me\n") + parse_manifest("domain: test.example.com\n") def test_parse_manifest_rejects_invalid_name(): diff --git a/tests/unit/test_provenance.py b/tests/unit/test_provenance.py index 640a8c9..b828325 100644 --- a/tests/unit/test_provenance.py +++ b/tests/unit/test_provenance.py @@ -85,7 +85,7 @@ def test_resolve_upstream_provenance_image_only(): def test_resolve_upstream_provenance_synced(): source = SourceConfig( - url="https://git.roadtotech.me/kiskaadee/app.git", + url="https://git.example.com/operator/app.git", ref="main", ref_type=RefType.BRANCH, transport=TransportScheme.HTTPS, @@ -106,7 +106,7 @@ def test_resolve_upstream_provenance_synced(): def test_resolve_upstream_provenance_update_available(): source = SourceConfig( - url="https://git.roadtotech.me/kiskaadee/app.git", + url="https://git.example.com/operator/app.git", ref="main", ref_type=RefType.BRANCH, transport=TransportScheme.HTTPS, @@ -157,7 +157,7 @@ def test_resolve_upstream_provenance_unreachable(): def test_resolve_upstream_provenance_pinned_commit(): sha = "1234567890abcdef1234567890abcdef12345678" source = SourceConfig( - url="https://git.roadtotech.me/app.git", + url="https://git.example.com/app.git", ref=sha, ref_type=RefType.COMMIT, transport=TransportScheme.HTTPS,