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
This commit is contained in:
1 parent
ea0ce0b1d6
commit
fbfbe9375f
7 files changed
+57
-34
No files matched your search
@@ -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.
|
- 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.
|
- 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
|
### 9. License
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -36,7 +36,8 @@ if [ -f "$ENV_FILE" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Lock the homelab root domain before setup_app_env can mutate $DOMAIN
|
# 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 usage
|
||||||
show_help() {
|
show_help() {
|
||||||
@@ -98,7 +99,7 @@ setup_app_env() {
|
|||||||
export PROXY_NETWORK="${PROXY_NETWORK:-proxy-net}"
|
export PROXY_NETWORK="${PROXY_NETWORK:-proxy-net}"
|
||||||
export NETWORK_NAME="${NETWORK_NAME:-$PROXY_NETWORK}"
|
export NETWORK_NAME="${NETWORK_NAME:-$PROXY_NETWORK}"
|
||||||
export CERT_RESOLVER="${CERT_RESOLVER:-myresolver}"
|
export CERT_RESOLVER="${CERT_RESOLVER:-myresolver}"
|
||||||
export DOMAIN_SUFFIX="${DOMAIN_SUFFIX:-roadtotech.me}"
|
export DOMAIN_SUFFIX="${DOMAIN_SUFFIX:-$HOMELAB_DOMAIN}"
|
||||||
|
|
||||||
# 2. Canonical application identity
|
# 2. Canonical application identity
|
||||||
export SERVICE_NAME="$CANONICAL_NAME"
|
export SERVICE_NAME="$CANONICAL_NAME"
|
||||||
|
|||||||
@@ -56,8 +56,8 @@ def validate_environment() -> None:
|
|||||||
|
|
||||||
if not HOMELAB_DOMAIN:
|
if not HOMELAB_DOMAIN:
|
||||||
errors.append(
|
errors.append(
|
||||||
"• Missing 'HOMELAB_DOMAIN' (or 'DOMAIN') environment variable.\n"
|
"• Missing 'HOMELAB_DOMAIN' (or 'DOMAIN_SUFFIX' / 'DOMAIN') environment variable.\n"
|
||||||
" Please export it (e.g. export HOMELAB_DOMAIN='roadtotech.me') or set it in your environment file."
|
" Please export it (e.g. export HOMELAB_DOMAIN='example.com') or set it in your environment file."
|
||||||
)
|
)
|
||||||
|
|
||||||
if not os.path.isdir(CORE_DIR):
|
if not os.path.isdir(CORE_DIR):
|
||||||
@@ -77,7 +77,7 @@ ManifestError = ManifestValidationError
|
|||||||
class App:
|
class App:
|
||||||
name: str # Canonical identifier (e.g., "traefik", "jellyfin")
|
name: str # Canonical identifier (e.g., "traefik", "jellyfin")
|
||||||
description: str = "" # Human-readable summary for dashboards and CLI info
|
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/<app> for Sites).
|
dir_path: str = "" # Filesystem directory (CORE_DIR for Core, or ~/Sites/<app> for Sites).
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ def test_appctl_env_injection_resilience(tmp_path: Path):
|
|||||||
|
|
||||||
resolved_json = json.dumps({
|
resolved_json = json.dumps({
|
||||||
"name": "test-app",
|
"name": "test-app",
|
||||||
"domain": "test.roadtotech.me",
|
"domain": "test.example.com",
|
||||||
"dir_path": str(tmp_path),
|
"dir_path": str(tmp_path),
|
||||||
"env": {"INJECTION_TEST": payload, "NORMAL_VAR": "safe_value"},
|
"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
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ def test_sites_app_normalization(app_factory: AppFactory):
|
|||||||
dir_name="homelab-custom",
|
dir_name="homelab-custom",
|
||||||
manifest_yaml="""
|
manifest_yaml="""
|
||||||
name: testapp
|
name: testapp
|
||||||
# Missing domain - should fallback to <name>.roadtotech.me
|
# Missing domain - should fallback to <name>.<HOMELAB_DOMAIN>
|
||||||
aliases: single-string-alias # should become a list[str]
|
aliases: single-string-alias # should become a list[str]
|
||||||
auth: "False" # should evaluate based on boolean casting
|
auth: "False" # should evaluate based on boolean casting
|
||||||
homepage:
|
homepage:
|
||||||
@@ -129,7 +129,7 @@ def test_sites_app_source_provenance_normalization(app_factory: AppFactory):
|
|||||||
name: bitetrack
|
name: bitetrack
|
||||||
source:
|
source:
|
||||||
type: git
|
type: git
|
||||||
url: https://git.roadtotech.me/kiskaadee/bitetrack.git
|
url: https://git.example.com/operator/bitetrack.git
|
||||||
ref: v1.2.0
|
ref: v1.2.0
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
@@ -139,7 +139,7 @@ def test_sites_app_source_provenance_normalization(app_factory: AppFactory):
|
|||||||
manifest_yaml="""
|
manifest_yaml="""
|
||||||
name: doc2site
|
name: doc2site
|
||||||
source:
|
source:
|
||||||
url: https://git.roadtotech.me/kiskaadee/doc2site.git
|
url: https://git.example.com/operator/doc2site.git
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
# 3. Image-only app (no source block)
|
# 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 is not None
|
||||||
assert bitetrack.source is not None
|
assert bitetrack.source is not None
|
||||||
assert bitetrack.source.type == "git"
|
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.source.ref == "v1.2.0"
|
||||||
assert bitetrack.to_dict()["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 = mock_core_dir / "config" / "homepage"
|
||||||
hp_config_dir.mkdir(parents=True, exist_ok=True)
|
hp_config_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
monkeypatch.setattr(engine, "HOMELAB_DOMAIN", "roadtotech.me")
|
monkeypatch.setattr(engine, "HOMELAB_DOMAIN", "example.com")
|
||||||
monkeypatch.setenv("DOMAIN", "mermaid.roadtotech.me")
|
monkeypatch.setenv("DOMAIN", "mermaid.example.com")
|
||||||
|
|
||||||
engine.cmd_sync_homepage(["--homepage-dir=" + str(hp_config_dir)])
|
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()
|
assert output_file.exists()
|
||||||
content = output_file.read_text()
|
content = output_file.read_text()
|
||||||
|
|
||||||
assert "https://dashboard.roadtotech.me" in content
|
assert "https://dashboard.example.com" in content
|
||||||
assert "https://traefik.roadtotech.me" in content
|
assert "https://traefik.example.com" in content
|
||||||
assert "https://auth.roadtotech.me" in content
|
assert "https://auth.example.com" in content
|
||||||
assert "mermaid.roadtotech.me" not in content
|
assert "mermaid.example.com" not in content
|
||||||
|
|
||||||
|
|
||||||
def test_resolve_core_stack_type():
|
def test_resolve_core_stack_type():
|
||||||
@@ -433,7 +433,7 @@ def test_unification_uses_core_manifest_dataclasses(app_factory: AppFactory):
|
|||||||
manifest_yaml="""
|
manifest_yaml="""
|
||||||
name: unified
|
name: unified
|
||||||
source:
|
source:
|
||||||
url: https://git.roadtotech.me/kiskaadee/unified.git
|
url: https://git.example.com/operator/unified.git
|
||||||
ref: v1.0.0
|
ref: v1.0.0
|
||||||
homepage:
|
homepage:
|
||||||
title: Unified App
|
title: Unified App
|
||||||
|
|||||||
@@ -22,25 +22,25 @@ from core_manifest import (
|
|||||||
|
|
||||||
|
|
||||||
def test_validate_transport_https():
|
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 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():
|
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 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():
|
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 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", [
|
@pytest.mark.parametrize("insecure_url", [
|
||||||
"http://insecure.roadtotech.me/repo.git",
|
"http://insecure.example.com/repo.git",
|
||||||
"http://github.com/repo.git",
|
"http://github.com/repo.git",
|
||||||
])
|
])
|
||||||
def test_validate_transport_rejects_http(insecure_url: str):
|
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", [
|
@pytest.mark.parametrize("traversal_url", [
|
||||||
"../../etc/shadow",
|
"../../etc/shadow",
|
||||||
"/home/kiskaadee/secret",
|
"/home/operator/secret",
|
||||||
"~/vault",
|
"~/vault",
|
||||||
"file:///etc/passwd",
|
"file:///etc/passwd",
|
||||||
])
|
])
|
||||||
@@ -83,7 +83,7 @@ schemaVersion: "1.0"
|
|||||||
name: "bitetrack"
|
name: "bitetrack"
|
||||||
aliases:
|
aliases:
|
||||||
- "bt"
|
- "bt"
|
||||||
domain: "bitetrack.roadtotech.me"
|
domain: "bitetrack.example.com"
|
||||||
description: "Nutrition and macro tracking application"
|
description: "Nutrition and macro tracking application"
|
||||||
visible: true
|
visible: true
|
||||||
auth: true
|
auth: true
|
||||||
@@ -93,7 +93,7 @@ env:
|
|||||||
PORT: 8080
|
PORT: 8080
|
||||||
source:
|
source:
|
||||||
type: git
|
type: git
|
||||||
url: "https://git.roadtotech.me/kiskaadee/bitetrack.git"
|
url: "https://git.example.com/operator/bitetrack.git"
|
||||||
ref: "v1.2.0"
|
ref: "v1.2.0"
|
||||||
deployment:
|
deployment:
|
||||||
strategy: compose
|
strategy: compose
|
||||||
@@ -116,7 +116,7 @@ homepage:
|
|||||||
assert manifest.is_class_b is False
|
assert manifest.is_class_b is False
|
||||||
assert manifest.is_internal is False
|
assert manifest.is_internal is False
|
||||||
assert manifest.source is not None
|
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 == "v1.2.0"
|
||||||
assert manifest.source.ref_type == RefType.TAG
|
assert manifest.source.ref_type == RefType.TAG
|
||||||
assert manifest.source.transport == TransportScheme.HTTPS
|
assert manifest.source.transport == TransportScheme.HTTPS
|
||||||
@@ -128,7 +128,7 @@ homepage:
|
|||||||
def test_parse_manifest_class_b_image_only():
|
def test_parse_manifest_class_b_image_only():
|
||||||
raw_yaml = """
|
raw_yaml = """
|
||||||
name: "snappymail"
|
name: "snappymail"
|
||||||
domain: "mail.roadtotech.me"
|
domain: "mail.example.com"
|
||||||
description: "Webmail Client"
|
description: "Webmail Client"
|
||||||
deployment:
|
deployment:
|
||||||
actions:
|
actions:
|
||||||
@@ -144,7 +144,7 @@ deployment:
|
|||||||
|
|
||||||
def test_parse_manifest_rejects_missing_name():
|
def test_parse_manifest_rejects_missing_name():
|
||||||
with pytest.raises(ManifestValidationError, match="missing mandatory string field '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():
|
def test_parse_manifest_rejects_invalid_name():
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ def test_resolve_upstream_provenance_image_only():
|
|||||||
|
|
||||||
def test_resolve_upstream_provenance_synced():
|
def test_resolve_upstream_provenance_synced():
|
||||||
source = SourceConfig(
|
source = SourceConfig(
|
||||||
url="https://git.roadtotech.me/kiskaadee/app.git",
|
url="https://git.example.com/operator/app.git",
|
||||||
ref="main",
|
ref="main",
|
||||||
ref_type=RefType.BRANCH,
|
ref_type=RefType.BRANCH,
|
||||||
transport=TransportScheme.HTTPS,
|
transport=TransportScheme.HTTPS,
|
||||||
@@ -106,7 +106,7 @@ def test_resolve_upstream_provenance_synced():
|
|||||||
|
|
||||||
def test_resolve_upstream_provenance_update_available():
|
def test_resolve_upstream_provenance_update_available():
|
||||||
source = SourceConfig(
|
source = SourceConfig(
|
||||||
url="https://git.roadtotech.me/kiskaadee/app.git",
|
url="https://git.example.com/operator/app.git",
|
||||||
ref="main",
|
ref="main",
|
||||||
ref_type=RefType.BRANCH,
|
ref_type=RefType.BRANCH,
|
||||||
transport=TransportScheme.HTTPS,
|
transport=TransportScheme.HTTPS,
|
||||||
@@ -157,7 +157,7 @@ def test_resolve_upstream_provenance_unreachable():
|
|||||||
def test_resolve_upstream_provenance_pinned_commit():
|
def test_resolve_upstream_provenance_pinned_commit():
|
||||||
sha = "1234567890abcdef1234567890abcdef12345678"
|
sha = "1234567890abcdef1234567890abcdef12345678"
|
||||||
source = SourceConfig(
|
source = SourceConfig(
|
||||||
url="https://git.roadtotech.me/app.git",
|
url="https://git.example.com/app.git",
|
||||||
ref=sha,
|
ref=sha,
|
||||||
ref_type=RefType.COMMIT,
|
ref_type=RefType.COMMIT,
|
||||||
transport=TransportScheme.HTTPS,
|
transport=TransportScheme.HTTPS,
|
||||||
|
|||||||
Reference in new issue
Block a user