Exclude runner ciphertext from Argo resources and reject encrypted manifests in preflight
This commit is contained in:
parent
492adcb0db
commit
71cd0db9d3
|
|
@ -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.
|
||||||
|
|
@ -4,9 +4,9 @@ metadata:
|
||||||
name: gitea-runner
|
name: gitea-runner
|
||||||
namespace: gitea-runner
|
namespace: gitea-runner
|
||||||
spec:
|
spec:
|
||||||
# The Pimox Kubernetes cluster uses containerd workers and Kyverno hostPath
|
# Cluster nodes may use containerd and hostPath admission policy. The
|
||||||
# policy. The Docker-socket runner remains documented here, but Jeannie keeps
|
# Docker-socket runner stays disabled across all cluster profiles; the
|
||||||
# it scaled down so the homelab uses the Debian host systemd runner instead.
|
# homelab uses the Debian host systemd runner instead.
|
||||||
replicas: 0
|
replicas: 0
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
@ -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
|
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.
|
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
|
## Adding Apps
|
||||||
|
|
||||||
Add Kubernetes manifests under `apps/<name>` and register them in
|
Add Kubernetes manifests under `apps/<name>` and register them in
|
||||||
|
|
|
||||||
|
|
@ -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
|
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.
|
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
|
## Adding Apps
|
||||||
|
|
||||||
Add Kubernetes manifests under `apps/<name>` and register them in
|
Add Kubernetes manifests under `apps/<name>` and register them in
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,15 @@ class CannotCheck(RuntimeError):
|
||||||
pass
|
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):
|
def run(command, timeout=60):
|
||||||
result = subprocess.run(command, capture_output=True, text=True, timeout=timeout, check=False)
|
result = subprocess.run(command, capture_output=True, text=True, timeout=timeout, check=False)
|
||||||
if result.returncode:
|
if result.returncode:
|
||||||
|
|
@ -543,6 +552,7 @@ def manifests_from_plan(args, plan, kubectl):
|
||||||
item = value.get("manifest")
|
item = value.get("manifest")
|
||||||
if not item:
|
if not item:
|
||||||
raise CannotCheck(f"{resource['address']}: planned manifest is unknown")
|
raise CannotCheck(f"{resource['address']}: planned manifest is unknown")
|
||||||
|
require_decrypted_manifest(item, resource["address"])
|
||||||
if item.get("kind") == "Application":
|
if item.get("kind") == "Application":
|
||||||
source = item.get("spec", {}).get("source") or {}
|
source = item.get("spec", {}).get("source") or {}
|
||||||
if not source.get("path") or any(source.get(key) for key in ("helm", "plugin", "directory")):
|
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()))
|
rendered.extend(yaml.safe_load_all(manifest.read_text()))
|
||||||
for app_item in rendered or []:
|
for app_item in rendered or []:
|
||||||
if app_item:
|
if app_item:
|
||||||
|
require_decrypted_manifest(app_item, f"Application {item['metadata']['name']}")
|
||||||
metadata = app_item.setdefault("metadata", {})
|
metadata = app_item.setdefault("metadata", {})
|
||||||
metadata["namespace"] = metadata.get("namespace") or item["spec"]["destination"]["namespace"]
|
metadata["namespace"] = metadata.get("namespace") or item["spec"]["destination"]["namespace"]
|
||||||
app_item["_preflight_noop"] = already_synced
|
app_item["_preflight_noop"] = already_synced
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,24 @@ def deployment(unavailable=1):
|
||||||
|
|
||||||
|
|
||||||
class SchedulingPreflightTests(unittest.TestCase):
|
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):
|
def test_one_core_node_can_fit_small_request(self):
|
||||||
estimate = MODULE.Estimate([node()], [pod(cpu="875m")], [], [], [])
|
estimate = MODULE.Estimate([node()], [pod(cpu="875m")], [], [], [])
|
||||||
incoming = pod("agent", "125m")
|
incoming = pod("agent", "125m")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue