Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(auth): close effective consumer attestation gaps

Alfredo Lopez7e2d9d37b027
diff --git a/docs/testing/minikube-t2-runbook.md b/docs/testing/minikube-t2-runbook.md
index 0f3501e94..e5e291c5c 100644
--- a/docs/testing/minikube-t2-runbook.md
+++ b/docs/testing/minikube-t2-runbook.md
@@ -163,11 +163,13 @@ when `gfs-config.jwt-public-key` is empty — the overlay re-applies the base
ConfigMap with an empty value — so `full-setup.sh` and `pre-gate-sync` re-run
`scripts/minikube/sync-auth-key.sh` before each GFS reconcile; otherwise no
new reader pod can start and the readiness wait can only time out. Auth sync
-commits a SHA-256 convergence annotation only after every active managed
-mcp-host and the exact `gfsc-writer`/`gfsc-reader` consumers prove—through a
-stdin-only in-process check—that they loaded the target public key. A matching
-ConfigMap without that annotation is an interrupted rollout and is resumed;
-it is never treated as converged.
+commits a SHA-256 convergence annotation only after every active Deployment
+binding whose effective source is
+`mcp-host-config.CLERUM_AUTH_JWT_PUBLIC_KEY`—including Workspace Files
+Controllers—and the exact `gfsc-writer`/`gfsc-reader` consumers prove through
+a stdin-only in-process check that they loaded the target public key. A
+matching ConfigMap without that annotation is an interrupted rollout and is
+resumed; it is never treated as converged.
`pre-gate-sync` provisions GFS serving with the same opt-ins only in the
`minikube-t2` transition (including its "no cluster sync required" fast path).
Other platform security gates refresh MCP auth with `--skip-gfs` and do not
diff --git a/scripts/minikube/discover-configmap-key-consumers.py b/scripts/minikube/discover-configmap-key-consumers.py
index 458e5f136..267f17569 100755
--- a/scripts/minikube/discover-configmap-key-consumers.py
+++ b/scripts/minikube/discover-configmap-key-consumers.py
@@ -1,23 +1,33 @@
#!/usr/bin/env python3
"""Discover effective Deployment env bindings to one ConfigMap key.
-The DeploymentList is read from stdin. Each binding is emitted as one record
-whose fields are separated by ASCII unit separator (0x1f): namespace,
-Deployment, desired replicas, exact label selector, container, and effective
-environment-variable name. Kubernetes names and label selectors cannot
-contain that delimiter, so the shell caller can preserve empty fields without
-inventing an escaping convention.
+The helper is intentionally pure: Kubernetes JSON is read from stdin and a
+sanitized object inventory is supplied by the shell caller. It never invokes
+kubectl and never receives ConfigMap or Secret values.
+
+Binding records use ASCII unit separator (0x1f): namespace, Deployment,
+desired replicas, exact label selector, container, and effective environment
+name. Resolve mode prefixes those rows with a snapshot hash record so the
+caller can prove that pod templates and referenced key presence stayed stable.
"""
from __future__ import annotations
import argparse
+import hashlib
import json
+import os
+import re
import sys
from typing import Any
FIELD_SEPARATOR = "\x1f"
+TARGET = "TARGET"
+OTHER = "OTHER"
+LITERAL = "LITERAL"
+EXACT_EXPANSION = re.compile(r"^\$\(([^)]+)\)$")
+ANY_EXPANSION = re.compile(r"\$\(([^)]+)\)")
class ConsumerContractError(ValueError):
@@ -29,6 +39,14 @@ def parse_args() -> argparse.Namespace:
parser.add_argument("--config-map", required=True)
parser.add_argument("--key", required=True)
parser.add_argument("--namespace", required=True)
+ parser.add_argument(
+ "--mode",
+ choices=("resolve", "references", "sanitize-object"),
+ default="resolve",
+ )
+ parser.add_argument("--object-kind", choices=("ConfigMap", "Secret"))
+ parser.add_argument("--object-name")
+ parser.add_argument("--required", choices=("true", "false"))
return parser.parse_args()
@@ -56,52 +74,304 @@ def text(value: Any, field: str, *, allow_empty: bool = False) -> str:
return value
-def references_target(env: dict[str, Any], config_map: str, key: str) -> bool:
- value_from = mapping(env.get("valueFrom"), "env.valueFrom")
- key_ref = mapping(value_from.get("configMapKeyRef"), "env.valueFrom.configMapKeyRef")
- return key_ref.get("name") == config_map and key_ref.get("key") == key
+def boolean(value: Any, field: str, *, default: bool = False) -> bool:
+ if value is None:
+ return default
+ if not isinstance(value, bool):
+ raise ConsumerContractError(f"{field} is not a boolean")
+ return value
+
+def env_from_reference(source: dict[str, Any], field: str) -> tuple[str, dict[str, Any]]:
+ refs: list[tuple[str, dict[str, Any]]] = []
+ if source.get("configMapRef") is not None:
+ refs.append(("ConfigMap", mapping(source.get("configMapRef"), f"{field}.configMapRef")))
+ if source.get("secretRef") is not None:
+ refs.append(("Secret", mapping(source.get("secretRef"), f"{field}.secretRef")))
+ if len(refs) != 1:
+ raise ConsumerContractError(
+ f"{field} must contain exactly one ConfigMap or Secret reference"
+ )
+ return refs[0]
-def effective_bindings(
+
+def key_reference(value_from: dict[str, Any], field: str) -> tuple[str, dict[str, Any]] | None:
+ refs: list[tuple[str, dict[str, Any]]] = []
+ if value_from.get("configMapKeyRef") is not None:
+ refs.append(
+ (
+ "ConfigMap",
+ mapping(value_from.get("configMapKeyRef"), f"{field}.configMapKeyRef"),
+ )
+ )
+ if value_from.get("secretKeyRef") is not None:
+ refs.append(("Secret", mapping(value_from.get("secretKeyRef"), f"{field}.secretKeyRef")))
+ if len(refs) > 1:
+ raise ConsumerContractError(f"{field} contains competing key references")
+ return refs[0] if refs else None
+
+
+def explicit_key_reference(env: dict[str, Any], field: str) -> tuple[str, dict[str, Any]] | None:
+ value = text(env.get("value", ""), f"{field}.value", allow_empty=True)
+ if value or env.get("valueFrom") is None:
+ return None
+ return key_reference(mapping(env.get("valueFrom"), f"{field}.valueFrom"), f"{field}.valueFrom")
+
+
+def container_references_target(
container: dict[str, Any], config_map: str, key: str
-) -> list[tuple[str, str]]:
+) -> bool:
container_name = text(container.get("name"), "container.name")
- env = sequence(container.get("env"), f"container {container_name}.env")
- env_from = sequence(container.get("envFrom"), f"container {container_name}.envFrom")
-
- # Explicit env entries override values imported through envFrom. Keep the
- # last definition for defensive parity with the runtime environment build;
- # valid Kubernetes templates normally de-duplicate this merge-keyed list.
- explicit_by_name: dict[str, dict[str, Any]] = {}
- for index, raw_env in enumerate(env):
- explicit = mapping(raw_env, f"container {container_name}.env[{index}]")
- env_name = text(explicit.get("name"), f"container {container_name}.env[{index}].name")
- explicit_by_name[env_name] = explicit
-
- names: set[str] = set()
- for index, raw_source in enumerate(env_from):
+ for index, raw_source in enumerate(
+ sequence(container.get("envFrom"), f"container {container_name}.envFrom")
+ ):
source = mapping(raw_source, f"container {container_name}.envFrom[{index}]")
- config_ref = mapping(
- source.get("configMapRef"),
- f"container {container_name}.envFrom[{index}].configMapRef",
- )
- if config_ref.get("name") != config_map:
+ kind, ref = env_from_reference(source, f"container {container_name}.envFrom[{index}]")
+ if kind == "ConfigMap" and ref.get("name") == config_map:
+ return True
+
+ for index, raw_env in enumerate(
+ sequence(container.get("env"), f"container {container_name}.env")
+ ):
+ env = mapping(raw_env, f"container {container_name}.env[{index}]")
+ ref = explicit_key_reference(env, f"container {container_name}.env[{index}]")
+ if ref is None:
continue
- prefix = text(
- source.get("prefix", ""),
- f"container {container_name}.envFrom[{index}].prefix",
- allow_empty=True,
+ kind, key_ref = ref
+ if kind == "ConfigMap" and key_ref.get("name") == config_map and key_ref.get("key") == key:
+ return True
+ return False
+
+
+def container_object_references(container: dict[str, Any]) -> dict[tuple[str, str], bool]:
+ container_name = text(container.get("name"), "container.name")
+ references: dict[tuple[str, str], bool] = {}
+ for index, raw_source in enumerate(
+ sequence(container.get("envFrom"), f"container {container_name}.envFrom")
+ ):
+ field = f"container {container_name}.envFrom[{index}]"
+ source = mapping(raw_source, field)
+ kind, ref = env_from_reference(source, field)
+ name = text(ref.get("name"), f"{field}.name")
+ required = not boolean(ref.get("optional"), f"{field}.optional")
+ references[(kind, name)] = references.get((kind, name), False) or required
+
+ for index, raw_env in enumerate(
+ sequence(container.get("env"), f"container {container_name}.env")
+ ):
+ field = f"container {container_name}.env[{index}]"
+ env = mapping(raw_env, field)
+ ref = explicit_key_reference(env, field)
+ if ref is None:
+ continue
+ kind, key_ref = ref
+ name = text(key_ref.get("name"), f"{field}.valueFrom.name")
+ text(key_ref.get("key"), f"{field}.valueFrom.key")
+ required = not boolean(key_ref.get("optional"), f"{field}.valueFrom.optional")
+ references[(kind, name)] = references.get((kind, name), False) or required
+ return references
+
+
+def candidate_containers(payload: dict[str, Any], args: argparse.Namespace):
+ items = sequence(payload.get("items"), "DeploymentList.items")
+ for index, raw_deployment in enumerate(items):
+ deployment = mapping(raw_deployment, f"DeploymentList.items[{index}]")
+ metadata = mapping(deployment.get("metadata"), "deployment.metadata")
+ name = text(metadata.get("name"), "deployment.metadata.name")
+ namespace = text(metadata.get("namespace", args.namespace), "deployment.metadata.namespace")
+ if namespace != args.namespace:
+ raise ConsumerContractError(
+ f"deployment {namespace}/{name} escaped namespace-scoped discovery"
+ )
+ spec = mapping(deployment.get("spec"), f"deployment {namespace}/{name}.spec")
+ template = mapping(spec.get("template"), f"deployment {namespace}/{name}.spec.template")
+ pod_spec = mapping(
+ template.get("spec"), f"deployment {namespace}/{name}.spec.template.spec"
)
- effective_name = prefix + key
- override = explicit_by_name.get(effective_name)
- if override is None or references_target(override, config_map, key):
- names.add(effective_name)
+ for raw_container in sequence(
+ pod_spec.get("containers"),
+ f"deployment {namespace}/{name}.spec.template.spec.containers",
+ ):
+ container = mapping(raw_container, f"deployment {namespace}/{name} container")
+ if container_references_target(container, args.config_map, args.key):
+ yield deployment, container
- for env_name, explicit in explicit_by_name.items():
- if references_target(explicit, config_map, key):
- names.add(env_name)
- return [(container_name, env_name) for env_name in sorted(names)]
+def referenced_objects(
+ payload: dict[str, Any], args: argparse.Namespace
+) -> dict[tuple[str, str], bool]:
+ references: dict[tuple[str, str], bool] = {}
+ for _deployment, container in candidate_containers(payload, args):
+ for identity, required in container_object_references(container).items():
+ references[identity] = references.get(identity, False) or required
+ return references
+
+
+def parse_inventory(namespace: str) -> dict[tuple[str, str], dict[str, Any]]:
+ raw = os.environ.get("CONSUMER_OBJECT_INVENTORY")
+ if raw is None:
+ raise ConsumerContractError("sanitized referenced-object inventory was not provided")
+ try:
+ decoded = json.loads(raw)
+ entries = decoded if isinstance(decoded, list) else [decoded]
+ except json.JSONDecodeError:
+ try:
+ entries = [json.loads(line) for line in raw.splitlines() if line.strip()]
+ except json.JSONDecodeError as error:
+ raise ConsumerContractError(
+ f"referenced-object inventory is invalid JSON: {error}"
+ ) from error
+
+ inventory: dict[tuple[str, str], dict[str, Any]] = {}
+ for index, raw_entry in enumerate(entries):
+ entry = mapping(raw_entry, f"referenced-object inventory[{index}]")
+ kind = text(entry.get("kind"), f"referenced-object inventory[{index}].kind")
+ if kind not in ("ConfigMap", "Secret"):
+ raise ConsumerContractError(f"referenced-object inventory[{index}].kind is unsupported")
+ entry_namespace = text(
+ entry.get("namespace"), f"referenced-object inventory[{index}].namespace"
+ )
+ if entry_namespace != namespace:
+ raise ConsumerContractError(
+ f"referenced object {entry_namespace}/{entry.get('name')} escaped "
+ "namespace-scoped discovery"
+ )
+ name = text(entry.get("name"), f"referenced-object inventory[{index}].name")
+ present = boolean(entry.get("present"), f"referenced-object inventory[{index}].present")
+ keys = sorted(
+ {
+ text(key, f"referenced-object inventory[{index}].keys")
+ for key in sequence(entry.get("keys"), f"referenced-object inventory[{index}].keys")
+ }
+ )
+ normalized: dict[str, Any] = {
+ "kind": kind,
+ "namespace": entry_namespace,
+ "name": name,
+ "present": present,
+ "keys": keys,
+ }
+ if present:
+ normalized["uid"] = text(
+ entry.get("uid"), f"referenced-object inventory[{index}].uid"
+ )
+ normalized["resourceVersion"] = text(
+ entry.get("resourceVersion"),
+ f"referenced-object inventory[{index}].resourceVersion",
+ )
+ elif keys:
+ raise ConsumerContractError(
+ f"absent referenced-object inventory[{index}] unexpectedly contains keys"
+ )
+ identity = (kind, name)
+ if identity in inventory:
+ raise ConsumerContractError(f"referenced-object inventory duplicates {kind} {name}")
+ inventory[identity] = normalized
+ return inventory
+
+
+def inventory_object(
+ inventory: dict[tuple[str, str], dict[str, Any]],
+ kind: str,
+ ref: dict[str, Any],
+ field: str,
+) -> dict[str, Any] | None:
+ name = text(ref.get("name"), f"{field}.name")
+ optional = boolean(ref.get("optional"), f"{field}.optional")
+ obj = inventory.get((kind, name))
+ if obj is None:
+ raise ConsumerContractError(f"sanitized inventory omitted referenced {kind} {name}")
+ if not obj["present"]:
+ if optional:
+ return None
+ raise ConsumerContractError(f"required referenced {kind} {name} is absent")
+ return obj
+
+
+def effective_bindings(
+ container: dict[str, Any],
+ config_map: str,
+ key: str,
+ inventory: dict[tuple[str, str], dict[str, Any]],
+) -> list[tuple[str, str]]:
+ container_name = text(container.get("name"), "container.name")
+ state: dict[str, str] = {}
+
+ for index, raw_source in enumerate(
+ sequence(container.get("envFrom"), f"container {container_name}.envFrom")
+ ):
+ field = f"container {container_name}.envFrom[{index}]"
+ source = mapping(raw_source, field)
+ kind, ref = env_from_reference(source, field)
+ obj = inventory_object(inventory, kind, ref, field)
+ if obj is None:
+ continue
+ prefix = text(source.get("prefix", ""), f"{field}.prefix", allow_empty=True)
+ ref_name = text(ref.get("name"), f"{field}.name")
+ for raw_key in obj["keys"]:
+ effective_name = text(prefix + raw_key, f"{field} effective environment name")
+ state[effective_name] = (
+ TARGET
+ if kind == "ConfigMap" and ref_name == config_map and raw_key == key
+ else OTHER
+ )
+
+ for index, raw_env in enumerate(
+ sequence(container.get("env"), f"container {container_name}.env")
+ ):
+ field = f"container {container_name}.env[{index}]"
+ env = mapping(raw_env, field)
+ env_name = text(env.get("name"), f"{field}.name")
+ value = text(env.get("value", ""), f"{field}.value", allow_empty=True)
+ if value:
+ exact = EXACT_EXPANSION.fullmatch(value)
+ if exact:
+ source_name = text(exact.group(1), f"{field}.value expansion")
+ state[env_name] = state.get(source_name, LITERAL)
+ continue
+ dependencies = ANY_EXPANSION.findall(value)
+ if any(state.get(dependency) == TARGET for dependency in dependencies):
+ raise ConsumerContractError(
+ f"{field}.value has an ambiguous composite expansion of the target key"
+ )
+ state[env_name] = LITERAL
+ continue
+
+ if env.get("valueFrom") is None:
+ state[env_name] = LITERAL
+ continue
+ value_from = mapping(env.get("valueFrom"), f"{field}.valueFrom")
+ ref = key_reference(value_from, f"{field}.valueFrom")
+ if ref is None:
+ if (
+ value_from.get("fieldRef") is not None
+ or value_from.get("resourceFieldRef") is not None
+ ):
+ state[env_name] = OTHER
+ continue
+ raise ConsumerContractError(f"{field}.valueFrom has no supported runtime source")
+ kind, key_ref = ref
+ obj = inventory_object(inventory, kind, key_ref, f"{field}.valueFrom")
+ raw_key = text(key_ref.get("key"), f"{field}.valueFrom.key")
+ if obj is None or raw_key not in obj["keys"]:
+ if boolean(key_ref.get("optional"), f"{field}.valueFrom.optional"):
+ continue
+ ref_name = text(key_ref.get("name"), f"{field}.valueFrom.name")
+ raise ConsumerContractError(
+ f"required key {raw_key} is absent from referenced {kind} {ref_name}"
+ )
+ ref_name = text(key_ref.get("name"), f"{field}.valueFrom.name")
+ state[env_name] = (
+ TARGET
+ if kind == "ConfigMap" and ref_name == config_map and raw_key == key
+ else OTHER
+ )
+
+ return [
+ (container_name, env_name)
+ for env_name, provenance in sorted(state.items())
+ if provenance == TARGET
+ ]
def render_selector(deployment: dict[str, Any]) -> str:
@@ -113,28 +383,36 @@ def render_selector(deployment: dict[str, Any]) -> str:
)
terms: list[str] = []
for raw_key in sorted(match_labels):
- key = text(raw_key, "deployment selector label key")
- value = text(match_labels[raw_key], f"deployment selector label {key}", allow_empty=True)
- terms.append(f"{key}={value}")
+ label_key = text(raw_key, "deployment selector label key")
+ value = text(
+ match_labels[raw_key], f"deployment selector label {label_key}", allow_empty=True
+ )
+ terms.append(f"{label_key}={value}")
for index, raw_expression in enumerate(match_expressions):
expression = mapping(raw_expression, f"deployment selector expression[{index}]")
- key = text(expression.get("key"), f"deployment selector expression[{index}].key")
+ label_key = text(
+ expression.get("key"), f"deployment selector expression[{index}].key"
+ )
operator = expression.get("operator")
values = [
- text(value, f"deployment selector expression[{index}].values")
+ text(
+ value,
+ f"deployment selector expression[{index}].values",
+ allow_empty=True,
+ )
for value in sequence(
expression.get("values"), f"deployment selector expression[{index}].values"
)
]
if operator == "In" and values:
- terms.append(f"{key} in ({','.join(values)})")
+ terms.append(f"{label_key} in ({','.join(values)})")
elif operator == "NotIn" and values:
- terms.append(f"{key} notin ({','.join(values)})")
+ terms.append(f"{label_key} notin ({','.join(values)})")
elif operator == "Exists" and not values:
- terms.append(key)
+ terms.append(label_key)
elif operator == "DoesNotExist" and not values:
- terms.append(f"!{key}")
+ terms.append(f"!{label_key}")
else:
raise ConsumerContractError(
f"deployment selector expression[{index}] has unsupported operator/value shape"
@@ -153,9 +431,16 @@ def desired_replicas(deployment: dict[str, Any]) -> int:
return replicas
-def records(payload: dict[str, Any], args: argparse.Namespace) -> list[tuple[str, ...]]:
+def resolve_records(
+ payload: dict[str, Any],
+ args: argparse.Namespace,
+ inventory: dict[tuple[str, str], dict[str, Any]],
+) -> tuple[list[tuple[str, ...]], str]:
items = sequence(payload.get("items"), "DeploymentList.items")
discovered: list[tuple[str, ...]] = []
+ deployment_snapshots: list[dict[str, Any]] = []
+ reference_contract = referenced_objects(payload, args)
+
for index, raw_deployment in enumerate(items):
deployment = mapping(raw_deployment, f"DeploymentList.items[{index}]")
metadata = mapping(deployment.get("metadata"), "deployment.metadata")
@@ -172,36 +457,154 @@ def records(payload: dict[str, Any], args: argparse.Namespace) -> list[tuple[str
pod_spec = mapping(
template.get("spec"), f"deployment {namespace}/{name}.spec.template.spec"
)
- containers = sequence(
+ candidate_contracts: list[dict[str, Any]] = []
+ bindings: list[tuple[str, str]] = []
+ for raw_container in sequence(
pod_spec.get("containers"),
f"deployment {namespace}/{name}.spec.template.spec.containers",
- )
- bindings: list[tuple[str, str]] = []
- for raw_container in containers:
+ ):
container = mapping(raw_container, f"deployment {namespace}/{name} container")
- bindings.extend(effective_bindings(container, args.config_map, args.key))
- bindings = sorted(set(bindings))
- if not bindings:
+ if not container_references_target(container, args.config_map, args.key):
+ continue
+ container_name = text(container.get("name"), "container.name")
+ env_from = sequence(container.get("envFrom"), f"container {container_name}.envFrom")
+ env = sequence(container.get("env"), f"container {container_name}.env")
+ candidate_contracts.append(
+ {"name": container_name, "envFrom": env_from, "env": env}
+ )
+ bindings.extend(
+ effective_bindings(container, args.config_map, args.key, inventory)
+ )
+ if not candidate_contracts:
continue
+ bindings = sorted(set(bindings))
replicas = desired_replicas(deployment)
- # A scaled-to-zero consumer has no active process to select or prove.
- # Do not let a selector shape block ConfigMap convergence for its next pod.
- selector = "" if replicas == 0 else render_selector(deployment)
+ selector = "" if replicas == 0 or not bindings else render_selector(deployment)
+ # A legitimate rollout and its status updates change Deployment
+ # resourceVersion. Hash only the immutable identity and normalized
+ # binding contract so that the expected rollout is not mistaken for
+ # concurrent contract drift.
+ deployment_snapshots.append(
+ {
+ "namespace": namespace,
+ "name": name,
+ "uid": text(metadata.get("uid"), f"deployment {namespace}/{name}.metadata.uid"),
+ "replicas": replicas,
+ "selector": selector,
+ "containers": candidate_contracts,
+ "bindings": bindings,
+ }
+ )
for container_name, env_name in bindings:
discovered.append(
(namespace, name, str(replicas), selector, container_name, env_name)
)
- return sorted(discovered)
+
+ inventory_snapshot = []
+ for kind, name in sorted(reference_contract):
+ obj = inventory.get((kind, name))
+ if obj is None:
+ raise ConsumerContractError(f"sanitized inventory omitted referenced {kind} {name}")
+ inventory_snapshot.append(obj)
+ canonical = json.dumps(
+ {
+ "deployments": sorted(
+ deployment_snapshots, key=lambda item: (item["namespace"], item["name"])
+ ),
+ "inventory": inventory_snapshot,
+ },
+ sort_keys=True,
+ separators=(",", ":"),
+ ).encode("utf-8")
+ return sorted(discovered), hashlib.sha256(canonical).hexdigest()
+
+
+def sanitize_object(args: argparse.Namespace) -> None:
+ if args.object_kind is None or args.object_name is None or args.required is None:
+ raise ConsumerContractError(
+ "sanitize-object mode requires --object-kind, --object-name and --required"
+ )
+ name = text(args.object_name, "referenced object name")
+ required = args.required == "true"
+ raw = sys.stdin.read()
+ if not raw.strip():
+ if required:
+ raise ConsumerContractError(
+ f"required referenced {args.object_kind} {name} is absent"
+ )
+ print(
+ json.dumps(
+ {
+ "kind": args.object_kind,
+ "namespace": args.namespace,
+ "name": name,
+ "present": False,
+ "keys": [],
+ },
+ sort_keys=True,
+ separators=(",", ":"),
+ )
+ )
+ return
+
+ obj = json.loads(raw)
+ if not isinstance(obj, dict):
+ raise ConsumerContractError("referenced Kubernetes object is not an object")
+ actual_kind = obj.get("kind", args.object_kind)
+ if actual_kind != args.object_kind:
+ raise ConsumerContractError(
+ f"referenced object kind {actual_kind} did not match {args.object_kind}"
+ )
+ metadata = mapping(obj.get("metadata"), "referenced object metadata")
+ actual_name = text(metadata.get("name"), "referenced object metadata.name")
+ namespace = text(
+ metadata.get("namespace", args.namespace), "referenced object metadata.namespace"
+ )
+ if actual_name != name or namespace != args.namespace:
+ raise ConsumerContractError(
+ f"referenced object identity {namespace}/{actual_name} did not match "
+ f"{args.namespace}/{name}"
+ )
+ data = mapping(obj.get("data"), "referenced object data")
+ normalized = {
+ "kind": args.object_kind,
+ "namespace": namespace,
+ "name": name,
+ "present": True,
+ "uid": text(metadata.get("uid"), "referenced object metadata.uid"),
+ "resourceVersion": text(
+ metadata.get("resourceVersion"), "referenced object metadata.resourceVersion"
+ ),
+ "keys": sorted(text(key, "referenced object data key") for key in data),
+ }
+ print(json.dumps(normalized, sort_keys=True, separators=(",", ":")))
+
+
+def load_payload() -> dict[str, Any]:
+ payload = json.load(sys.stdin)
+ if not isinstance(payload, dict):
+ raise ConsumerContractError("DeploymentList is not an object")
+ return payload
def main() -> int:
args = parse_args()
try:
- payload = json.load(sys.stdin)
- if not isinstance(payload, dict):
- raise ConsumerContractError("DeploymentList is not an object")
- for record in records(payload, args):
+ if args.mode == "sanitize-object":
+ sanitize_object(args)
+ return 0
+
+ payload = load_payload()
+ if args.mode == "references":
+ for (kind, name), required in sorted(referenced_objects(payload, args).items()):
+ print(FIELD_SEPARATOR.join((kind, name, "true" if required else "false")))
+ return 0
+
+ inventory = parse_inventory(args.namespace)
+ records, snapshot_hash = resolve_records(payload, args, inventory)
+ print(FIELD_SEPARATOR.join(("@snapshot", snapshot_hash)))
+ for record in records:
print(FIELD_SEPARATOR.join(record))
except (ConsumerContractError, json.JSONDecodeError) as error:
print(f"cannot discover ConfigMap key consumers: {error}", file=sys.stderr)
diff --git a/scripts/minikube/sync-auth-key.sh b/scripts/minikube/sync-auth-key.sh
index 22f1c282c..9525f2959 100755
--- a/scripts/minikube/sync-auth-key.sh
+++ b/scripts/minikube/sync-auth-key.sh
@@ -270,18 +270,59 @@ deployment_desired_replicas() {
printf '%s' "${desired}"
}
-discover_mcp_consumer_bindings() {
- local deployments_json bindings
+discover_mcp_consumer_snapshot() {
+ local deployments_json references inventory_records="" snapshot
+ local kind name required resource sanitized extra
if ! deployments_json="$("${KCTL[@]}" get deployments -n "${CONFIG_NAMESPACE}" -o json 2>&1)"; then
log "cannot enumerate Deployment pod templates in ${CONFIG_NAMESPACE}: ${deployments_json}" >&2
return 1
fi
- if ! bindings="$(printf '%s' "${deployments_json}" | python3 "${MCP_BINDING_DISCOVERY}" \
- --namespace "${CONFIG_NAMESPACE}" --config-map "${CONFIGMAP}" --key "${TARGET_KEY}" 2>&1)"; then
- log "cannot derive ${CONFIGMAP}.${TARGET_KEY} consumer bindings: ${bindings}" >&2
+
+ if ! references="$(printf '%s' "${deployments_json}" | python3 "${MCP_BINDING_DISCOVERY}" \
+ --mode references --namespace "${CONFIG_NAMESPACE}" \
+ --config-map "${CONFIGMAP}" --key "${TARGET_KEY}" 2>&1)"; then
+ log "cannot enumerate references that affect ${CONFIGMAP}.${TARGET_KEY} bindings: ${references}" >&2
+ return 1
+ fi
+
+ while IFS=$'\x1f' read -r kind name required extra; do
+ [[ -n "${kind}" ]] || continue
+ [[ -n "${name}" && ( "${required}" == "true" || "${required}" == "false" ) && -z "${extra}" ]] || {
+ log "consumer reference discovery returned an incomplete object record" >&2
+ return 1
+ }
+ case "${kind}" in
+ ConfigMap) resource=configmap ;;
+ Secret) resource=secret ;;
+ *)
+ log "consumer reference discovery returned unsupported object kind ${kind}" >&2
+ return 1
+ ;;
+ esac
+ if ! sanitized="$(
+ "${KCTL[@]}" get "${resource}" "${name}" -n "${CONFIG_NAMESPACE}" \
+ --ignore-not-found -o json |
+ python3 "${MCP_BINDING_DISCOVERY}" --mode sanitize-object \
+ --namespace "${CONFIG_NAMESPACE}" --config-map "${CONFIGMAP}" --key "${TARGET_KEY}" \
+ --object-kind "${kind}" --object-name "${name}" --required "${required}" 2>&1
+ )"; then
+ log "cannot snapshot referenced ${kind} ${CONFIG_NAMESPACE}/${name}: ${sanitized}" >&2
+ return 1
+ fi
+ if [[ -n "${inventory_records}" ]]; then
+ inventory_records+=$'\n'
+ fi
+ inventory_records+="${sanitized}"
+ done <<<"${references}"
+
+ if ! snapshot="$(printf '%s' "${deployments_json}" | \
+ CONSUMER_OBJECT_INVENTORY="${inventory_records}" \
+ python3 "${MCP_BINDING_DISCOVERY}" --mode resolve \
+ --namespace "${CONFIG_NAMESPACE}" --config-map "${CONFIGMAP}" --key "${TARGET_KEY}" 2>&1)"; then
+ log "cannot derive ${CONFIGMAP}.${TARGET_KEY} consumer bindings: ${snapshot}" >&2
return 1
fi
- printf '%s' "${bindings}"
+ printf '%s' "${snapshot}"
}
write_source_key() {
@@ -368,7 +409,7 @@ deployment_pods_use_key_bindings() {
binding_count=$((binding_count + 1))
if ! write_source_key | "${KCTL[@]}" exec -i "${pod}" -n "${namespace}" -c "${container}" -- \
node -e 'const fs=require("fs");const expected=fs.readFileSync(0,"utf8");process.exit(process.env[process.argv[1]]===expected?0:42)' \
- "${env_name}" >/dev/null; then
+ -- "${env_name}" >/dev/null; then
log "${consumer} pod ${namespace}/${pod} binding ${container}/${env_name} has not consumed the target auth key" >&2
return 1
fi
@@ -493,12 +534,22 @@ sync_mcp_consumers() {
fi
fi
- local binding_records
- if ! binding_records="$(discover_mcp_consumer_bindings)"; then
+ local consumer_snapshot snapshot_header snapshot_hash snapshot_tag snapshot_extra binding_records
+ if ! consumer_snapshot="$(discover_mcp_consumer_snapshot)"; then
die "cannot enumerate effective ${CONFIGMAP}.${TARGET_KEY} consumers before auth key rollout"
fi
+ snapshot_header="${consumer_snapshot%%$'\n'*}"
+ IFS=$'\x1f' read -r snapshot_tag snapshot_hash snapshot_extra <<<"${snapshot_header}"
+ [[ "${snapshot_tag}" == "@snapshot" && "${snapshot_hash}" =~ ^[0-9a-f]{64}$ && \
+ -z "${snapshot_extra}" ]] ||
+ die "consumer discovery returned an invalid contract snapshot"
+ if [[ "${consumer_snapshot}" == *$'\n'* ]]; then
+ binding_records="${consumer_snapshot#*$'\n'}"
+ else
+ binding_records=""
+ fi
if [[ -z "${binding_records}" ]]; then
- log "No Deployment pod templates reference ${CONFIGMAP}.${TARGET_KEY}; auth key is synced for future consumers"
+ log "No effective Deployment bindings consume ${CONFIGMAP}.${TARGET_KEY}; auth key is synced for future consumers"
else
local namespace deployment desired_replicas selector container env_name
local current_namespace="" current_deployment="" current_replicas="" current_selector=""
@@ -535,11 +586,11 @@ sync_mcp_consumers() {
fi
fi
- local final_binding_records final_hash
- if ! final_binding_records="$(discover_mcp_consumer_bindings)"; then
+ local final_consumer_snapshot final_hash
+ if ! final_consumer_snapshot="$(discover_mcp_consumer_snapshot)"; then
die "cannot re-enumerate effective ${CONFIGMAP}.${TARGET_KEY} consumers before attestation"
fi
- [[ "${final_binding_records}" == "${binding_records}" ]] ||
+ [[ "${final_consumer_snapshot}" == "${consumer_snapshot}" ]] ||
die "${CONFIGMAP}.${TARGET_KEY} consumer contracts changed during convergence"
if ! final_hash="$(configmap_key_hash "${CONFIG_NAMESPACE}" "${CONFIGMAP}" "${TARGET_KEY}" 2>&1)"; then
die "cannot re-read auth target ${CONFIG_NAMESPACE}/${CONFIGMAP} before attestation: ${final_hash}"
diff --git a/scripts/tests/test-minikube-sync-auth-key-durable.sh b/scripts/tests/test-minikube-sync-auth-key-durable.sh
index 736c47529..4d61e383a 100755
--- a/scripts/tests/test-minikube-sync-auth-key-durable.sh
+++ b/scripts/tests/test-minikube-sync-auth-key-durable.sh
@@ -38,6 +38,139 @@ PROCESS_START=${T2_PROCESS_START}
EOF
export T2_PROJECT_DIR="${ROOT}" T2_PROFILE=fake T2_CONTEXT=fake T2_LOCK_ROOT T2_LOCK_TOKEN
+# The discovery helper resolves target-key provenance from a sanitized view of
+# the exact ConfigMaps and Secrets referenced by candidate containers. These
+# fixtures exercise kubelet ordering without exposing object values.
+DISCOVERY_INVENTORY='[
+ {"kind":"ConfigMap","namespace":"mcp-host","name":"mcp-host-config","present":true,"uid":"target-uid","resourceVersion":"10","keys":["CLERUM_AUTH_JWT_PUBLIC_KEY"]},
+ {"kind":"ConfigMap","namespace":"mcp-host","name":"override-present","present":true,"uid":"override-uid","resourceVersion":"11","keys":["CLERUM_AUTH_JWT_PUBLIC_KEY"]},
+ {"kind":"ConfigMap","namespace":"mcp-host","name":"override-key-absent","present":true,"uid":"override-empty-uid","resourceVersion":"12","keys":["OTHER_KEY"]},
+ {"kind":"ConfigMap","namespace":"mcp-host","name":"optional-config-absent","present":false,"keys":[]},
+ {"kind":"Secret","namespace":"mcp-host","name":"secret-present","present":true,"uid":"secret-uid","resourceVersion":"13","keys":["CLERUM_AUTH_JWT_PUBLIC_KEY"]},
+ {"kind":"Secret","namespace":"mcp-host","name":"secret-key-absent","present":true,"uid":"secret-empty-uid","resourceVersion":"14","keys":["OTHER_KEY"]},
+ {"kind":"Secret","namespace":"mcp-host","name":"optional-secret-absent","present":false,"keys":[]}
+]'
+
+write_discovery_fixture() {
+ DISCOVERY_FIXTURE="$1" python3 - <<'PY'
+import json
+import os
+
+target = {"configMapRef": {"name": "mcp-host-config"}}
+
+
+def key_ref(kind, name, key="CLERUM_AUTH_JWT_PUBLIC_KEY", optional=False):
+ field = "configMapKeyRef" if kind == "ConfigMap" else "secretKeyRef"
+ return {"valueFrom": {field: {"name": name, "key": key, "optional": optional}}}
+
+
+def env_from(kind, name, prefix="", optional=False):
+ field = "configMapRef" if kind == "ConfigMap" else "secretRef"
+ source = {field: {"name": name, "optional": optional}}
+ if prefix:
+ source["prefix"] = prefix
+ return source
+
+
+def deployment(name, container, expression=None):
+ selector = {"matchLabels": {"app": name}}
+ if expression is not None:
+ selector = {"matchExpressions": [expression]}
+ return {
+ "apiVersion": "apps/v1",
+ "kind": "Deployment",
+ "metadata": {
+ "name": name,
+ "namespace": "mcp-host",
+ "uid": f"{name}-uid",
+ "resourceVersion": "20",
+ },
+ "spec": {
+ "replicas": 1,
+ "selector": selector,
+ "template": {"spec": {"containers": [{"name": "runtime", **container}]}},
+ },
+ }
+
+
+fixture = os.environ["DISCOVERY_FIXTURE"]
+if fixture == "effective":
+ items = [
+ deployment("optional-cm-absent", {"envFrom": [target], "env": [{"name": "CLERUM_AUTH_JWT_PUBLIC_KEY", **key_ref("ConfigMap", "optional-config-absent", optional=True)}]}),
+ deployment("optional-cm-key-absent", {"envFrom": [target], "env": [{"name": "CLERUM_AUTH_JWT_PUBLIC_KEY", **key_ref("ConfigMap", "override-key-absent", optional=True)}]}),
+ deployment("optional-cm-key-present", {"envFrom": [target], "env": [{"name": "CLERUM_AUTH_JWT_PUBLIC_KEY", **key_ref("ConfigMap", "override-present", optional=True)}]}),
+ deployment("optional-secret-absent", {"envFrom": [target], "env": [{"name": "CLERUM_AUTH_JWT_PUBLIC_KEY", **key_ref("Secret", "optional-secret-absent", optional=True)}]}),
+ deployment("optional-secret-key-absent", {"envFrom": [target], "env": [{"name": "CLERUM_AUTH_JWT_PUBLIC_KEY", **key_ref("Secret", "secret-key-absent", optional=True)}]}),
+ deployment("optional-secret-key-present", {"envFrom": [target], "env": [{"name": "CLERUM_AUTH_JWT_PUBLIC_KEY", **key_ref("Secret", "secret-present", optional=True)}]}),
+ deployment("self-expansion", {"envFrom": [target], "env": [{"name": "CLERUM_AUTH_JWT_PUBLIC_KEY", "value": "$(CLERUM_AUTH_JWT_PUBLIC_KEY)"}]}),
+ deployment("cm-shadow", {"envFrom": [target, env_from("ConfigMap", "override-present")]}),
+ deployment("cm-no-shadow", {"envFrom": [target, env_from("ConfigMap", "override-key-absent")]}),
+ deployment("optional-envfrom-cm-absent", {"envFrom": [target, env_from("ConfigMap", "optional-config-absent", optional=True)]}),
+ deployment("secret-shadow", {"envFrom": [target, env_from("Secret", "secret-present")]}),
+ deployment("secret-no-shadow", {"envFrom": [target, env_from("Secret", "secret-key-absent")]}),
+ deployment("optional-envfrom-secret-absent", {"envFrom": [target, env_from("Secret", "optional-secret-absent", optional=True)]}),
+ deployment("target-last", {"envFrom": [env_from("ConfigMap", "override-present"), target]}),
+ deployment("secret-target-last", {"envFrom": [env_from("Secret", "secret-present"), target]}),
+ deployment("prefix-shadow", {"envFrom": [env_from("ConfigMap", "mcp-host-config", "AUTH_"), env_from("ConfigMap", "override-present", "AUTH_")]}),
+ deployment("prefix-distinct", {"envFrom": [env_from("ConfigMap", "mcp-host-config", "AUTH_"), env_from("ConfigMap", "override-present", "OTHER_")]}),
+ ]
+elif fixture == "required-missing":
+ items = [deployment("required-missing", {"envFrom": [target], "env": [{"name": "CLERUM_AUTH_JWT_PUBLIC_KEY", **key_ref("ConfigMap", "optional-config-absent")}]} )]
+elif fixture == "complex-expansion":
+ items = [deployment("complex-expansion", {"envFrom": [target], "env": [{"name": "CLERUM_AUTH_JWT_PUBLIC_KEY", "value": "$(CLERUM_AUTH_JWT_PUBLIC_KEY)$(EMPTY)"}]})]
+elif fixture == "empty-selectors":
+ items = [
+ deployment("selector-in-empty", {"envFrom": [target]}, {"key": "tier", "operator": "In", "values": [""]}),
+ deployment("selector-notin-empty", {"envFrom": [target]}, {"key": "tier", "operator": "NotIn", "values": [""]}),
+ ]
+else:
+ raise SystemExit(f"unknown discovery fixture: {fixture}")
+
+print(json.dumps({"apiVersion": "v1", "kind": "DeploymentList", "items": items}))
+PY
+}
+
+resolve_discovery_fixture() {
+ local fixture="$1"
+ write_discovery_fixture "${fixture}" | CONSUMER_OBJECT_INVENTORY="${DISCOVERY_INVENTORY}" \
+ python3 "${ROOT}/scripts/minikube/discover-configmap-key-consumers.py" \
+ --namespace mcp-host --config-map mcp-host-config --key CLERUM_AUTH_JWT_PUBLIC_KEY
+}
+
+effective_output="$(resolve_discovery_fixture effective)" || {
+ echo 'FAIL: effective-binding fixture was not resolvable' >&2
+ exit 1
+}
+for expected in optional-cm-absent optional-cm-key-absent optional-secret-absent \
+ optional-secret-key-absent optional-envfrom-cm-absent optional-envfrom-secret-absent \
+ self-expansion cm-no-shadow secret-no-shadow target-last secret-target-last prefix-distinct; do
+ grep -q "${expected}" <<<"${effective_output}" || {
+ echo "FAIL: ${expected} lost its effective target binding" >&2
+ exit 1
+ }
+done
+for shadowed in optional-cm-key-present optional-secret-key-present cm-shadow secret-shadow prefix-shadow; do
+ if grep -q "${shadowed}" <<<"${effective_output}"; then
+ echo "FAIL: ${shadowed} retained a shadowed target binding" >&2
+ exit 1
+ fi
+done
+
+if resolve_discovery_fixture required-missing >/dev/null 2>&1; then
+ echo 'FAIL: a missing required override was treated as a provable contract' >&2
+ exit 1
+fi
+if resolve_discovery_fixture complex-expansion >/dev/null 2>&1; then
+ echo 'FAIL: a composite target-derived expansion was treated as a provable contract' >&2
+ exit 1
+fi
+selector_output="$(resolve_discovery_fixture empty-selectors)" || {
+ echo 'FAIL: valid empty selector values were rejected' >&2
+ exit 1
+}
+grep -q 'tier in ()' <<<"${selector_output}"
+grep -q 'tier notin ()' <<<"${selector_output}"
+
cat >"${TMP_DIR}/kubectl" <<'SH'
#!/usr/bin/env bash
set -euo pipefail
@@ -91,7 +224,9 @@ state = Path(os.environ['TEST_STATE_DIR'])
annotations = {}
if (state / 'mcp.applied').exists():
annotations['clerum.io/auth-key-applied-sha256'] = (state / 'mcp.applied').read_text()
-print(json.dumps({'metadata': {'resourceVersion': '42', 'annotations': annotations},
+print(json.dumps({'metadata': {'name': 'mcp-host-config', 'namespace': 'mcp-host',
+ 'uid': 'mcp-host-config-uid', 'resourceVersion': '42',
+ 'annotations': annotations},
'data': {'CLERUM_AUTH_JWT_PUBLIC_KEY': (state / 'mcp.key').read_text()}}))
PY
elif [[ "$*" == *jsonpath* ]]; then
@@ -152,6 +287,8 @@ def deployment(name, labels, containers, replicas=1, managed_by="host-context-co
"metadata": {
"name": name,
"namespace": "mcp-host",
+ "uid": f"{name}-uid",
+ "resourceVersion": "30",
"labels": {"clerum.io/managed-by": managed_by},
},
"spec": {
@@ -247,10 +384,52 @@ elif mode == "multiple-bindings":
"envFrom": [target_ref],
"env": [{"name": "CLERUM_AUTH_JWT_PUBLIC_KEY", "value": "literal-override"}],
},
+ {
+ "name": "optional-kept",
+ "envFrom": [target_ref],
+ "env": [
+ {
+ "name": "CLERUM_AUTH_JWT_PUBLIC_KEY",
+ "valueFrom": {
+ "configMapKeyRef": {
+ "name": "optional-config-absent",
+ "key": "CLERUM_AUTH_JWT_PUBLIC_KEY",
+ "optional": True,
+ }
+ },
+ }
+ ],
+ },
+ {
+ "name": "self-expanded",
+ "envFrom": [target_ref],
+ "env": [
+ {
+ "name": "CLERUM_AUTH_JWT_PUBLIC_KEY",
+ "value": "$(CLERUM_AUTH_JWT_PUBLIC_KEY)",
+ }
+ ],
+ },
+ {
+ "name": "shadowed",
+ "envFrom": [
+ target_ref,
+ {"configMapRef": {"name": "override-present"}},
+ ],
+ },
],
replicas,
)
]
+elif mode == "option-binding":
+ items = [
+ deployment(
+ "option-consumer",
+ {"app": "option-runtime"},
+ [{"name": "option-runtime", "env": [{"name": "--version", **direct_ref}]}],
+ replicas,
+ )
+ ]
else:
items = [mcp("chatllm", replicas)]
@@ -259,6 +438,21 @@ PY
exit 0
fi
+if [[ "${1:-}" == get && "${2:-}" == configmap && "${3:-}" == override-present ]]; then
+ if [[ "$*" == *'-o json'* ]]; then
+ printf '%s' '{"metadata":{"name":"override-present","namespace":"mcp-host","uid":"override-present-uid","resourceVersion":"50"},"data":{"CLERUM_AUTH_JWT_PUBLIC_KEY":"shadow"}}'
+ fi
+ exit 0
+fi
+
+if [[ "${1:-}" == get && "${2:-}" == configmap && "${3:-}" == optional-config-absent ]]; then
+ if [[ "$*" == *--ignore-not-found* ]]; then
+ exit 0
+ fi
+ echo 'Error from server (NotFound): configmaps "optional-config-absent" not found' >&2
+ exit 1
+fi
+
if [[ "${1:-}" == get && "${2:-}" == deployment && "${3:-}" == -l ]]; then
case "${TEST_MCP_DEPLOYMENTS:-chatllm}" in
none) ;;
@@ -290,7 +484,7 @@ fi
if [[ "${1:-}" == get && "${2:-}" == deployment/* ]]; then
case "${2}" in
- deployment/chatllm|deployment/custom-host|deployment/wfc-21352205ce|deployment/hcc-unrelated)
+ deployment/chatllm|deployment/custom-host|deployment/wfc-21352205ce|deployment/hcc-unrelated|deployment/multi-consumer|deployment/option-consumer)
[[ "$*" == *'.spec.replicas'* ]] && printf '%s' "${TEST_MCP_REPLICAS:-1}"
exit 0 ;;
deployment/mcp-host) echo 'Error from server (NotFound): deployments.apps "mcp-host" not found' >&2; exit 1 ;;
@@ -344,6 +538,7 @@ if [[ "${1:-}" == get && "${2:-}" == pods ]]; then
fi
;;
*'app=multi-runtime,clerum.io/host=multi'*) printf 'multi-consumer-pod|True|\n' ;;
+ *app=option-runtime*) printf 'option-consumer-pod|True|\n' ;;
*gfsc-role=writer*) printf 'gfsc-writer-pod|True|\n' ;;
*gfsc-role=reader*) printf 'gfsc-reader-pod|True|\n' ;;
*) echo "unexpected pod selector: $*" >&2; exit 92 ;;
@@ -353,7 +548,6 @@ fi
if [[ "${1:-}" == exec ]]; then
input_file="${TEST_STATE_DIR}/exec-input"
- expected_file="${TEST_STATE_DIR}/exec-expected"
cat >"${input_file}"
expected_key="${TEST_RUNTIME_KEY}"
[[ "$*" == *GFS_JWT_PUBLIC_KEY* ]] && expected_key="${TEST_RUNTIME_KEY_GFS:-${expected_key}}"
@@ -376,6 +570,7 @@ if [[ "${1:-}" == exec ]]; then
custom-host-pod) deployment_name=custom-host ;;
wfc-21352205ce-pod) deployment_name=wfc-21352205ce ;;
multi-consumer-pod) deployment_name=multi-consumer ;;
+ option-consumer-pod) deployment_name=option-consumer ;;
gfsc-writer-pod) deployment_name=gfsc-writer ;;
gfsc-reader-pod) deployment_name=gfsc-reader ;;
*) deployment_name="${pod%-pod}" ;;
@@ -389,9 +584,20 @@ if [[ "${1:-}" == exec ]]; then
if [[ ",${TEST_PERSIST_STALE_BINDINGS:-}," == *",${binding},"* ]]; then
expected_key=old-key
fi
- printf '%s' "${expected_key}" >"${expected_file}"
- cmp -s "${input_file}" "${expected_file}"
- exit
+ remote_argv=()
+ capture_remote=false
+ for argument in "$@"; do
+ if [[ "${capture_remote}" == true ]]; then
+ remote_argv+=("${argument}")
+ elif [[ "${argument}" == -- ]]; then
+ capture_remote=true
+ fi
+ done
+ (( ${#remote_argv[@]} > 0 )) || {
+ echo 'kubectl exec fixture did not receive a remote argv' >&2
+ exit 93
+ }
+ /usr/bin/env -- "${env_name}=${expected_key}" "${remote_argv[@]}" <"${input_file}"
fi
echo "unexpected kubectl invocation: $*" >&2
@@ -584,7 +790,7 @@ if grep -q 'deployment/wrc-recipe-host' "${LOG_FILE}"; then
exit 1
fi
grep -q -- '-l app=workspace-files-controller,clerum.io/sharedfilesystem=workspace-alpha,clerum.io/sharedfilesystem-namespace=mcp-host' "${LOG_FILE}"
-grep -q -- '-c workspace-files-controller -- node -e .* WSF_JWT_PUBLIC_KEY' "${LOG_FILE}"
+grep -q -- '-c workspace-files-controller -- node -e .* -- WSF_JWT_PUBLIC_KEY' "${LOG_FILE}"
# A rotation must restart only the stale MCP host. WFC is independently
# verified through its own binding and remains untouched.
@@ -622,7 +828,7 @@ fi
[[ ! -e "${STATE_DIR}/chatllm-restart.count" ]]
grep -q 'rollout restart deployment/wfc-21352205ce' "${LOG_FILE}"
grep -q -- '-l app=workspace-files-controller,clerum.io/sharedfilesystem=workspace-alpha,clerum.io/sharedfilesystem-namespace=mcp-host' "${LOG_FILE}"
-grep -q -- '-c workspace-files-controller -- node -e .* WSF_JWT_PUBLIC_KEY' "${LOG_FILE}"
+grep -q -- '-c workspace-files-controller -- node -e .* -- WSF_JWT_PUBLIC_KEY' "${LOG_FILE}"
# A rollout that still yields no Ready, provable WFC pod must fail closed and
# leave the convergence marker absent.
@@ -656,13 +862,20 @@ if ! run_sync env TEST_RUNTIME_KEY=public-key TEST_MCP_DEPLOYMENTS=multiple-bind
exit 1
fi
[[ ! -e "${STATE_DIR}/multi-consumer-restart.count" ]]
-grep -q -- '-c prefixed -- node -e .* AUTH_CLERUM_AUTH_JWT_PUBLIC_KEY' "${LOG_FILE}"
-grep -q -- '-c direct -- node -e .* DIRECT_JWT_PUBLIC_KEY' "${LOG_FILE}"
+grep -q -- '-c prefixed -- node -e .* -- AUTH_CLERUM_AUTH_JWT_PUBLIC_KEY' "${LOG_FILE}"
+grep -q -- '-c direct -- node -e .* -- DIRECT_JWT_PUBLIC_KEY' "${LOG_FILE}"
+grep -q -- '-c optional-kept -- node -e .* -- CLERUM_AUTH_JWT_PUBLIC_KEY' "${LOG_FILE}"
+grep -q -- '-c self-expanded -- node -e .* -- CLERUM_AUTH_JWT_PUBLIC_KEY' "${LOG_FILE}"
if grep -q -- '-c overridden --' "${LOG_FILE}"; then
echo 'FAIL: an explicit literal env override was treated as a ConfigMap binding' >&2
cat "${LOG_FILE}" >&2
exit 1
fi
+if grep -q -- '-c shadowed --' "${LOG_FILE}"; then
+ echo 'FAIL: a later envFrom source that contains the key did not shadow the target binding' >&2
+ cat "${LOG_FILE}" >&2
+ exit 1
+fi
# One stale binding makes the whole Deployment stale, but it is restarted only
# once and every binding is re-proved after rollout.
@@ -680,6 +893,28 @@ fi
[[ "$(cat "${STATE_DIR}/multi-consumer-restart.count")" == 1 ]]
[[ "$(grep -c 'rollout restart deployment/multi-consumer' "${LOG_FILE}")" == 1 ]]
+# A Kubernetes-valid environment name that resembles a Node option must still
+# reach the comparison script as data. It starts stale, triggers exactly one
+# rollout, and can pass only after the fake runtime switches to the source key.
+rm -f "${STATE_DIR}/mcp.applied" "${STATE_DIR}/option-consumer-restart.count"
+: >"${LOG_FILE}"
+if ! run_sync env TEST_RUNTIME_KEY=public-key TEST_MCP_DEPLOYMENTS=option-binding \
+ TEST_STALE_BINDINGS='option-consumer/option-runtime/--version' \
+ bash "${ROOT}/scripts/minikube/sync-auth-key.sh" --context fake --require-mcp --skip-gfs \
+ >"${OUT_FILE}" 2>&1; then
+ cat "${OUT_FILE}" >&2
+ cat "${LOG_FILE}" >&2
+ echo 'FAIL: option-like env binding did not converge after one rollout' >&2
+ exit 1
+fi
+if [[ ! -f "${STATE_DIR}/option-consumer-restart.count" || \
+ "$(cat "${STATE_DIR}/option-consumer-restart.count")" != 1 ]]; then
+ echo 'FAIL: Node accepted an option-like env name without executing the stale-value probe' >&2
+ cat "${LOG_FILE}" >&2
+ exit 1
+fi
+grep -q -- '-c option-runtime -- node -e .* -- --version' "${LOG_FILE}"
+
# A source rotation after consumer proof must invalidate the run before the
# final success message, even when the previous convergence marker was already
# written. This is the race the resourceVersion+key snapshot closes.
diff --git a/scripts/tests/test-minikube-sync-auth-key.sh b/scripts/tests/test-minikube-sync-auth-key.sh
index 35f95136b..22626f406 100755
--- a/scripts/tests/test-minikube-sync-auth-key.sh
+++ b/scripts/tests/test-minikube-sync-auth-key.sh
@@ -101,7 +101,7 @@ fi
if [[ "${1:-}" == "get" && "${2:-}" == "configmap" && "${3:-}" == "mcp-host-config" ]]; then
if has_output_flag "$@"; then
if [[ "$*" == *'-o json' ]]; then
- printf '{"metadata":{"resourceVersion":"42","annotations":{}},"data":{"CLERUM_AUTH_JWT_PUBLIC_KEY":"%s"}}' \
+ printf '{"metadata":{"name":"mcp-host-config","namespace":"mcp-host","uid":"mcp-host-config-uid","resourceVersion":"42","annotations":{}},"data":{"CLERUM_AUTH_JWT_PUBLIC_KEY":"%s"}}' \
"$(cat "${TEST_STATE_DIR}/mcp.key")"
elif [[ "$*" == *auth-key-applied-sha256* ]]; then
printf '%s' "${TEST_MCP_APPLIED_HASH:-old-hash}"
@@ -153,9 +153,9 @@ fi
if [[ "${1:-}" == "get" && ( "${2:-}" == "deployment" || "${2:-}" == "deployments" ) && "$*" == *'-o json'* ]]; then
printf '%s' '{"apiVersion":"v1","kind":"List","items":[
- {"metadata":{"name":"chatllm","namespace":"mcp-host"},"spec":{"replicas":1,"selector":{"matchLabels":{"app":"chatllm"}},"template":{"spec":{"containers":[{"name":"mcp-host","envFrom":[{"configMapRef":{"name":"mcp-host-config"}}]}]}}}},
- {"metadata":{"name":"mcp-host","namespace":"mcp-host"},"spec":{"replicas":1,"selector":{"matchLabels":{"app":"mcp-host"}},"template":{"spec":{"containers":[{"name":"mcp-host","envFrom":[{"configMapRef":{"name":"mcp-host-config"}}]}]}}}},
- {"metadata":{"name":"custom-host","namespace":"mcp-host"},"spec":{"replicas":1,"selector":{"matchLabels":{"app":"custom-host"}},"template":{"spec":{"containers":[{"name":"mcp-host","envFrom":[{"configMapRef":{"name":"mcp-host-config"}}]}]}}}}
+ {"metadata":{"name":"chatllm","namespace":"mcp-host","uid":"chatllm-uid","resourceVersion":"30"},"spec":{"replicas":1,"selector":{"matchLabels":{"app":"chatllm"}},"template":{"spec":{"containers":[{"name":"mcp-host","envFrom":[{"configMapRef":{"name":"mcp-host-config"}}]}]}}}},
+ {"metadata":{"name":"mcp-host","namespace":"mcp-host","uid":"mcp-host-uid","resourceVersion":"30"},"spec":{"replicas":1,"selector":{"matchLabels":{"app":"mcp-host"}},"template":{"spec":{"containers":[{"name":"mcp-host","envFrom":[{"configMapRef":{"name":"mcp-host-config"}}]}]}}}},
+ {"metadata":{"name":"custom-host","namespace":"mcp-host","uid":"custom-host-uid","resourceVersion":"30"},"spec":{"replicas":1,"selector":{"matchLabels":{"app":"custom-host"}},"template":{"spec":{"containers":[{"name":"mcp-host","envFrom":[{"configMapRef":{"name":"mcp-host-config"}}]}]}}}}
]}'
exit 0
fi