diff --git a/apps/gitea-runner/README.md b/apps/gitea-runner/README.md new file mode 100644 index 0000000..9740cee --- /dev/null +++ b/apps/gitea-runner/README.md @@ -0,0 +1,17 @@ +# Optional Kubernetes Gitea runner + +The default deployment has zero replicas across all profiles. The active CI +runner is the Debian-host `homelab-gitea-runner.service`; native K3s and Pimox +workers do not provide a host Docker socket automatically. + +Argo CD detects `kustomization.yaml` and renders only namespace, deployment and +PVC resources. The neighboring SOPS files and parent `application.yaml` must +not be applied as raw resources. Encrypted API versions/kinds are ciphertext, +not CRDs that need installing. The apps scheduling preflight rejects SOPS +documents that reach rendered Kubernetes resources before applying the plan. + +Keep encrypted credentials outside this resource list. Jeannie's separate +runner-secret path is used when the runner is explicitly enabled; enabling +requires an appropriate Docker-capable node, placement, hostPath permission and +valid credentials. Zero replicas skip secret application and pod readiness, +while preserving the declared storage resource. diff --git a/apps/gitea-runner/deployment.yaml b/apps/gitea-runner/deployment.yaml index 5239414..73806c0 100644 --- a/apps/gitea-runner/deployment.yaml +++ b/apps/gitea-runner/deployment.yaml @@ -4,9 +4,9 @@ metadata: name: gitea-runner namespace: gitea-runner spec: - # The Pimox Kubernetes cluster uses containerd workers and Kyverno hostPath - # policy. The Docker-socket runner remains documented here, but Jeannie keeps - # it scaled down so the homelab uses the Debian host systemd runner instead. + # Cluster nodes may use containerd and hostPath admission policy. The + # Docker-socket runner stays disabled across all cluster profiles; the + # homelab uses the Debian host systemd runner instead. replicas: 0 selector: matchLabels: diff --git a/apps/gitea-runner/kustomization.yaml b/apps/gitea-runner/kustomization.yaml new file mode 100644 index 0000000..b85233c --- /dev/null +++ b/apps/gitea-runner/kustomization.yaml @@ -0,0 +1,8 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - namespace.yaml + - deployment.yaml + - pvc.yaml +# Credentials are applied separately by Jeannie when the runner is enabled. +# Do not include SOPS ciphertext or the parent Application in rendered resources. diff --git a/docs/app-ops.md b/docs/app-ops.md index d37a00a..096941e 100644 --- a/docs/app-ops.md +++ b/docs/app-ops.md @@ -22,6 +22,13 @@ restart. The default rollout/readiness budget is 600 seconds, configurable with than starting a second full wait after rollout. Slow initial image pulls can consume this budget; a timeout does not by itself establish a container crash. +The optional Kubernetes Gitea runner stays at zero replicas across profiles; +the Debian host runner performs CI. Its explicit Kustomization includes only +namespace, deployment and PVC resources, leaving SOPS files and the parent Argo +Application outside the rendered resource list. Preflight rejects encrypted +documents in rendered app resources instead of allowing Argo to discover an +encrypted API group. See [runner source rules](../apps/gitea-runner/README.md). + ## Adding Apps Add Kubernetes manifests under `apps/` and register them in diff --git a/docs/templates/app-ops.md.tmpl b/docs/templates/app-ops.md.tmpl index 25c9f03..f6c58d8 100644 --- a/docs/templates/app-ops.md.tmpl +++ b/docs/templates/app-ops.md.tmpl @@ -22,6 +22,13 @@ restart. The default rollout/readiness budget is 600 seconds, configurable with than starting a second full wait after rollout. Slow initial image pulls can consume this budget; a timeout does not by itself establish a container crash. +The optional Kubernetes Gitea runner stays at zero replicas across profiles; +the Debian host runner performs CI. Its explicit Kustomization includes only +namespace, deployment and PVC resources, leaving SOPS files and the parent Argo +Application outside the rendered resource list. Preflight rejects encrypted +documents in rendered app resources instead of allowing Argo to discover an +encrypted API group. See [runner source rules](../apps/gitea-runner/README.md). + ## Adding Apps Add Kubernetes manifests under `apps/` and register them in diff --git a/scripts/scheduling-preflight.py b/scripts/scheduling-preflight.py index 3ad0c0e..70588a5 100644 --- a/scripts/scheduling-preflight.py +++ b/scripts/scheduling-preflight.py @@ -30,6 +30,15 @@ class CannotCheck(RuntimeError): pass +def require_decrypted_manifest(document, source): + if not isinstance(document, dict): + raise CannotCheck(f"{source}: rendered manifest must be a mapping") + if "sops" in document or any(str(document.get(field, "")).startswith("ENC[") + for field in ("apiVersion", "kind")): + raise CannotCheck(f"{source}: encrypted SOPS document is included in rendered Kubernetes resources; " + "use an explicit Kustomization resource list or a configured decryption renderer") + + def run(command, timeout=60): result = subprocess.run(command, capture_output=True, text=True, timeout=timeout, check=False) if result.returncode: @@ -543,6 +552,7 @@ def manifests_from_plan(args, plan, kubectl): item = value.get("manifest") if not item: raise CannotCheck(f"{resource['address']}: planned manifest is unknown") + require_decrypted_manifest(item, resource["address"]) if item.get("kind") == "Application": source = item.get("spec", {}).get("source") or {} if not source.get("path") or any(source.get(key) for key in ("helm", "plugin", "directory")): @@ -597,6 +607,7 @@ def manifests_from_plan(args, plan, kubectl): rendered.extend(yaml.safe_load_all(manifest.read_text())) for app_item in rendered or []: if app_item: + require_decrypted_manifest(app_item, f"Application {item['metadata']['name']}") metadata = app_item.setdefault("metadata", {}) metadata["namespace"] = metadata.get("namespace") or item["spec"]["destination"]["namespace"] app_item["_preflight_noop"] = already_synced diff --git a/tests/jeannie/test_scheduling_preflight.py b/tests/jeannie/test_scheduling_preflight.py index 4f13a15..ba6ce97 100644 --- a/tests/jeannie/test_scheduling_preflight.py +++ b/tests/jeannie/test_scheduling_preflight.py @@ -39,6 +39,24 @@ def deployment(unavailable=1): class SchedulingPreflightTests(unittest.TestCase): + def test_encrypted_api_identity_is_refused_without_echoing_ciphertext(self): + for field in ("apiVersion", "kind"): + with self.subTest(field=field): + document = {"apiVersion": "v1", "kind": "Secret", field: "ENC[AES256_GCM,example]"} + with self.assertRaises(MODULE.CannotCheck) as raised: + MODULE.require_decrypted_manifest(document, "Application gitea-runner") + self.assertIn("Application gitea-runner", str(raised.exception)) + self.assertIn("encrypted SOPS document", str(raised.exception)) + self.assertNotIn("AES256_GCM", str(raised.exception)) + + def test_sops_secret_is_refused_even_with_plaintext_kind(self): + document = {"apiVersion": "v1", "kind": "Secret", "sops": {"version": "3.9.0"}} + with self.assertRaisesRegex(MODULE.CannotCheck, "encrypted SOPS document"): + MODULE.require_decrypted_manifest(document, "Application example") + + def test_rendered_plaintext_resource_is_allowed(self): + MODULE.require_decrypted_manifest({"apiVersion": "apps/v1", "kind": "Deployment"}, "Application example") + def test_one_core_node_can_fit_small_request(self): estimate = MODULE.Estimate([node()], [pod(cpu="875m")], [], [], []) incoming = pod("agent", "125m")