Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(wrc): cover NetworkPolicy service convergence
Alfredo Lopezb05264096758
diff --git a/.github/workflows/ci-public.yml b/.github/workflows/ci-public.ymlindex b77601d73..28f1c64e3 100644--- a/.github/workflows/ci-public.yml+++ b/.github/workflows/ci-public.yml@@ -545,6 +545,9 @@ jobs:- name: Test E2E Vitest node-unit public gaterun: bash scripts/tests/test-e2e-vitest-node-unit-gate.sh+ - name: Test WRC NetworkPolicy live-convergence E2E contract+ run: bash scripts/tests/test-wrc-networkpolicy-live-convergence-e2e.sh+- name: Test GFS real-Postgres Minikube runner contractrun: bash scripts/tests/test-gfs-real-pg-minikube-gate.shdiff --git a/Makefile b/Makefileindex 487f3903f..6813b3f68 100644--- a/Makefile+++ b/Makefile@@ -1083,7 +1083,7 @@ test-contracts: test-e2e-deps ## Run contract tests onlytest-e2e-bash: ## Run bash-based E2E suites (scripts/e2e/*.sh)@echo "Running bash E2E suites..."KUBECONTEXT=$(E2E_KUBECONTEXT) bash scripts/e2e/e2e-workflow-runtime-gate.sh- KUBECONTEXT=$(E2E_KUBECONTEXT) bash scripts/e2e/e2e-wrc-internal-dependency-networkpolicy.sh+ KUBECONTEXT=$(E2E_KUBECONTEXT) bash scripts/e2e/e2e-wrc-networkpolicy-live-convergence.shKUBECONTEXT=$(E2E_KUBECONTEXT) bash scripts/e2e/e2e-workflow-backend-compat.shKUBECONTEXT=$(E2E_KUBECONTEXT) bash scripts/e2e/e2e-sfs-legacy-job-cleanup.shKUBECONTEXT=$(E2E_KUBECONTEXT) bash scripts/e2e/e2e-sfs-security.sh@@ -1098,6 +1098,11 @@ test-e2e-wrc-internal-dependency-networkpolicy: ## Run issue #485 WRC internal-d@echo "Running WRC internal-dependency NetworkPolicy E2E gate..."KUBECONTEXT=$(E2E_KUBECONTEXT) bash scripts/e2e/e2e-wrc-internal-dependency-networkpolicy.sh+.PHONY: test-e2e-wrc-networkpolicy-live-convergence+test-e2e-wrc-networkpolicy-live-convergence: ## Run all PR #580 WRC NetworkPolicy family, route, repair, owner, and no-churn E2E gates+ @echo "Running WRC NetworkPolicy live-convergence E2E gate..."+ KUBECONTEXT=$(E2E_KUBECONTEXT) bash scripts/e2e/e2e-wrc-networkpolicy-live-convergence.sh+.PHONY: test-e2e-codex-subscription-network-boundarytest-e2e-codex-subscription-network-boundary: ## Codex LLM proxy NetworkPolicy boundary (exit 3 before deploy)@echo "Running Codex subscription network-boundary gate..."diff --git a/docs/deploy/workflow-recipes-guide.md b/docs/deploy/workflow-recipes-guide.mdindex 0ab802b46..3462f707a 100644--- a/docs/deploy/workflow-recipes-guide.md+++ b/docs/deploy/workflow-recipes-guide.md@@ -332,7 +332,8 @@ it cannot hide later drift.- **NetworkPolicy drift is auto-reverted.** A live change to `podSelector`,`policyTypes`, `ingress`, `egress`, WRC-authored metadata or the gateway controllerowner forces one optimistic-concurrency replace using the `resourceVersion` from the- same validated read. The following reconcile is read-only.+ same validated read on the next parent recipe reconcile. NetworkPolicy-only changes do+ not emit a WorkflowRecipe event. The following reconcile is read-only.- **Other spec-hash-managed objects retain their existing drift contract.** For example,a manually scaled recipe Deployment is not reverted until the desired manifest changes;its replica-health drift remains visible in recipe status.@@ -344,6 +345,34 @@ it cannot hide later drift.## Automated Tests+### WRC NetworkPolicy live-convergence E2E++NetworkPolicy changes must run the aggregate gate against an isolated development+cluster with an explicit context:++```bash+E2E_KUBECONTEXT=<branch-owned-context> \+ make test-e2e-wrc-networkpolicy-live-convergence+```++The aggregate fails unless all four executable suites run. Together they cover every+NetworkPolicy family routed through the live-convergence helper:++- `ui-ingress`, `workload-ingress` and `workload-egress`: correctly configured UI→API+ and API→sibling traffic, unlabelled negative controls, forced live-spec drift, a real+ parent recipe reconcile, repair, and a post-repair resourceVersion stability window;+- `internal-dependency`: inferred source→backend traffic, an unlabelled denied pod,+ two-sided policy repair and no-churn;+- `oauth-broker-egress`: opted-in workload→Control API reachability, an unlabelled+ denied workload, drift repair and no-churn;+- `webhook-gateway`: all three policies, a signed public webhook business signal,+ spec drift, stale/missing owner repair, route recovery and no-churn.++The public CI runner cannot provide this Calico-backed cluster. It therefore runs the+fail-loud composition/syntax contract, while the real dataplane result is recorded by+the exact-head local T2/pre-merge evidence lane. Missing prerequisites, a missing family+suite, incomplete cleanup or zero executed suites are failures, never skips.+### Unit tests (vitest + @testing-library/react)```bashdiff --git a/scripts/e2e/_lib/wrc-networkpolicy-convergence.sh b/scripts/e2e/_lib/wrc-networkpolicy-convergence.shnew file mode 100644index 000000000..f94fe666b--- /dev/null+++ b/scripts/e2e/_lib/wrc-networkpolicy-convergence.sh@@ -0,0 +1,116 @@+#!/usr/bin/env bash+# Shared, fail-loud helpers for WRC NetworkPolicy live-convergence E2E gates.+# Source after e2e-lib.sh so kctl/ok/fail are available.++set -euo pipefail++wrc_np_spec_hash() {+ local namespace=$1 name=$2+ kctl get networkpolicy "$name" -n "$namespace" -o json |+ python3 -c 'import hashlib,json,sys; spec=json.load(sys.stdin)["spec"]; payload=json.dumps(spec,sort_keys=True,separators=(",",":")).encode(); print(hashlib.sha256(payload).hexdigest())'+}++wrc_np_resource_version() {+ local namespace=$1 name=$2+ kctl get networkpolicy "$name" -n "$namespace" -o jsonpath='{.metadata.resourceVersion}'+}++wrc_wait_for_np() {+ local namespace=$1 name=$2 timeout=${3:-120} elapsed=0+ while [ "$elapsed" -lt "$timeout" ]; do+ if kctl get networkpolicy "$name" -n "$namespace" >/dev/null 2>&1; then+ return 0+ fi+ sleep "$POLL_INTERVAL"+ elapsed=$((elapsed + POLL_INTERVAL))+ done+ fail "Timed out waiting for NetworkPolicy ${namespace}/${name}"+ return 1+}++wrc_wait_for_np_spec_hash() {+ local namespace=$1 name=$2 expected=$3 timeout=${4:-120} elapsed=0 actual+ while [ "$elapsed" -lt "$timeout" ]; do+ actual="$(wrc_np_spec_hash "$namespace" "$name" 2>/dev/null || true)"+ if [ -n "$actual" ] && [ "$actual" = "$expected" ]; then+ return 0+ fi+ sleep "$POLL_INTERVAL"+ elapsed=$((elapsed + POLL_INTERVAL))+ done+ fail "NetworkPolicy ${namespace}/${name} did not restore its baseline spec"+ return 1+}++wrc_inject_selector_drift() {+ local namespace=$1 name=$2+ kctl patch networkpolicy "$name" -n "$namespace" --type=merge \+ -p '{"spec":{"podSelector":{"matchLabels":{"e2e.clerum.io/forced-drift":"true"}}}}' \+ >/dev/null+}++wrc_trigger_recipe_reconcile() {+ local namespace=$1 name=$2 timeout=${3:-120}+ local before_generation after_generation marker patch since_time elapsed=0+ local controller_namespace=${WRC_CONTROLLER_NAMESPACE:-control-plane}+ local controller_deployment=${WRC_CONTROLLER_DEPLOYMENT:-workflow-recipes}+ local needle="[WR-Reconciler] Reconciling \"${name}\""++ before_generation="$(+ kctl get workflowrecipe "$name" -n "$namespace" -o jsonpath='{.metadata.generation}'+ )"+ [[ "$before_generation" =~ ^[0-9]+$ ]] || {+ fail "WorkflowRecipe ${namespace}/${name} has no numeric generation before reconcile trigger"+ return 1+ }++ WRC_NP_RECONCILE_SEQUENCE=${WRC_NP_RECONCILE_SEQUENCE:-0}+ WRC_NP_RECONCILE_SEQUENCE=$((WRC_NP_RECONCILE_SEQUENCE + 1))+ marker="np-e2e-${WRC_NP_RECONCILE_SEQUENCE}-$(date +%s)"+ patch="$(jq -cn --arg description "$marker" '{spec:{description:$description}}')"+ since_time="$(+ python3 -c 'from datetime import datetime, timezone; print(datetime.now(timezone.utc).isoformat().replace("+00:00", "Z"))'+ )"++ kctl patch workflowrecipe "$name" -n "$namespace" --type=merge -p "$patch" >/dev/null+ after_generation="$(+ kctl get workflowrecipe "$name" -n "$namespace" -o jsonpath='{.metadata.generation}'+ )"+ if [[ ! "$after_generation" =~ ^[0-9]+$ ]] || [ "$after_generation" -le "$before_generation" ]; then+ fail "WorkflowRecipe ${namespace}/${name} generation did not advance (${before_generation} -> ${after_generation})"+ return 1+ fi++ while [ "$elapsed" -lt "$timeout" ]; do+ if kctl logs -n "$controller_namespace" "deployment/${controller_deployment}" \+ --since-time="$since_time" 2>/dev/null | grep -Fq "$needle"; then+ ok "WorkflowRecipe ${namespace}/${name} entered reconcile at generation ${after_generation}"+ return 0+ fi+ sleep "$POLL_INTERVAL"+ elapsed=$((elapsed + POLL_INTERVAL))+ done++ fail "Timed out waiting for WRC to reconcile WorkflowRecipe ${namespace}/${name} generation ${after_generation}"+ return 1+}++wrc_assert_np_stable() {+ local namespace=$1 name=$2 settle_seconds=${3:-20}+ local before after+ before="$(wrc_np_resource_version "$namespace" "$name")"+ [ -n "$before" ] || {+ fail "NetworkPolicy ${namespace}/${name} has no resourceVersion before stability window"+ return 1+ }+ # This is an intentional no-churn observation window, not a readiness sleep:+ # the policy is already converged and the assertion is that later reconciles+ # do not update it.+ sleep "$settle_seconds"+ after="$(wrc_np_resource_version "$namespace" "$name")"+ if [ "$after" != "$before" ]; then+ fail "NetworkPolicy ${namespace}/${name} churned while converged (${before} -> ${after})"+ return 1+ fi+ ok "NetworkPolicy ${namespace}/${name} stayed at resourceVersion ${before}"+}diff --git a/scripts/e2e/e2e-sandbox-ui-oauth.sh b/scripts/e2e/e2e-sandbox-ui-oauth.shindex 520b455a4..f033571b8 100755--- a/scripts/e2e/e2e-sandbox-ui-oauth.sh+++ b/scripts/e2e/e2e-sandbox-ui-oauth.sh@@ -27,14 +27,25 @@set -euo pipefailSCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"+# shellcheck disable=SC1091source "${SCRIPT_DIR}/e2e-lib.sh"+# shellcheck disable=SC1091+source "${SCRIPT_DIR}/_lib/wrc-networkpolicy-convergence.sh"RECIPE_FILE="workflow-recipes/samples/sandbox-ui-oauth-hello.yaml"RECIPE_NAME="sandbox-ui-oauth-hello"WORKLOAD_ID="hello"SANDBOX_UI_NS="sandbox-ui"OAUTH_SECRET_NAME="slack-oauth-creds"+BACKGROUND_RECIPE_NAME="e2e-wrc-oauth-broker"+BACKGROUND_WORKLOAD_ID="background-worker"+BACKGROUND_POLICY_NAME="wf-${BACKGROUND_RECIPE_NAME}-oauth-broker-egress"+BACKGROUND_PROBE_POD="e2e-wrc-oauth-unlabelled"+STABILITY_SECONDS="${E2E_NP_STABILITY_SECONDS:-20}"TIMEOUT_RECIPE_ACTIVE="${TIMEOUT_RECIPE_ACTIVE:-180}"+UI_DEPLOYMENT=""+UI_PORT_FWD_PORT="${E2E_OAUTH_UI_PORT:-18096}"+UI_PORT_FWD_PID=""wait_for_recipe_phase() {local name=$1 ns=$2 want=$3 timeout=$4 elapsed=0@@ -51,27 +62,103 @@ wait_for_recipe_phase() {return 1}+wait_for_workload_instance() {+ local recipe_name=$1 workload_id=$2 timeout=${3:-120} elapsed=0 instance+ while [ "$elapsed" -lt "$timeout" ]; do+ instance="$(kctl get workflowrecipe "$recipe_name" -n "$WORKFLOW_RECIPE_NS" -o "jsonpath={.status.workloadInstances.${workload_id}}" 2>/dev/null || true)"+ if [ -n "$instance" ]; then+ printf '%s\n' "$instance"+ return 0+ fi+ sleep "$POLL_INTERVAL"+ elapsed=$((elapsed + POLL_INTERVAL))+ done+ return 1+}++http_response_from_target() {+ local target=$1 host=$2 port=$3+ # shellcheck disable=SC2016+ kctl exec "$target" -n "$WORKFLOW_RECIPE_NS" -- sh -c 'printf "GET /health HTTP/1.0\r\nHost: e2e\r\nConnection: close\r\n\r\n" | nc -w 6 "$1" "$2"' -- "$host" "$port" 2>/dev/null || true+}++create_background_probe() {+ cat <<YAML | kctl apply -f - >/dev/null+apiVersion: v1+kind: Pod+metadata:+ name: ${BACKGROUND_PROBE_POD}+ namespace: ${WORKFLOW_RECIPE_NS}+ labels:+ e2e.clerum.io/probe: wrc-oauth-unlabelled+spec:+ restartPolicy: Never+ securityContext:+ runAsNonRoot: true+ runAsUser: 65532+ runAsGroup: 65532+ seccompProfile:+ type: RuntimeDefault+ containers:+ - name: probe+ image: busybox:1.36.1+ command: ["sh", "-c", "trap 'exit 0' TERM INT; while true; do sleep 3600; done"]+ securityContext:+ allowPrivilegeEscalation: false+ capabilities:+ drop: ["ALL"]+YAML+ wait_for_pod "$WORKFLOW_RECIPE_NS" "e2e.clerum.io/probe=wrc-oauth-unlabelled" 60+}+cleanup() {header "Cleanup"+ if [ -n "$UI_PORT_FWD_PID" ]; then+ kill "$UI_PORT_FWD_PID" 2>/dev/null || true+ wait "$UI_PORT_FWD_PID" 2>/dev/null || true+ UI_PORT_FWD_PID=""+ fi+ kctl delete pod "$BACKGROUND_PROBE_POD" -n "$WORKFLOW_RECIPE_NS" --ignore-not-found --wait=false 2>/dev/null || true+ kctl delete workflowrecipe "$BACKGROUND_RECIPE_NAME" -n "$WORKFLOW_RECIPE_NS" --ignore-not-found --wait=false 2>/dev/null || truekctl delete workflowrecipe "$RECIPE_NAME" -n "$WORKFLOW_RECIPE_NS" \--ignore-not-found --wait=false 2>/dev/null || true# WRC GC follows ownerReferences inside the recipe namespace, but UI# workloads are reconciled cross-namespace (sandbox-recipes →# sandbox-ui) so K8s GC can't follow the link. Force-delete leftovers.- kctl delete deployment "$WORKLOAD_ID" -n "$SANDBOX_UI_NS" --ignore-not-found 2>/dev/null || true- kctl delete svc "$WORKLOAD_ID" -n "$SANDBOX_UI_NS" --ignore-not-found 2>/dev/null || true+ if [ -n "$UI_DEPLOYMENT" ]; then+ kctl delete deployment "$UI_DEPLOYMENT" -n "$SANDBOX_UI_NS" --ignore-not-found 2>/dev/null || true+ kctl delete svc "$UI_DEPLOYMENT" -n "$SANDBOX_UI_NS" --ignore-not-found 2>/dev/null || true+ fi+ kctl delete deployment,service -n "$SANDBOX_UI_NS" -l "clerum.io/recipe=${RECIPE_NAME}" \+ --ignore-not-found 2>/dev/null || truekctl delete networkpolicy "ui-egress-${RECIPE_NAME}" -n "$SANDBOX_UI_NS" \--ignore-not-found 2>/dev/null || true+ kctl delete networkpolicy "$BACKGROUND_POLICY_NAME" -n "$WORKFLOW_RECIPE_NS" --ignore-not-found 2>/dev/null || truekctl delete secret "$OAUTH_SECRET_NAME" -n "$WORKFLOW_RECIPE_NS" \--ignore-not-found 2>/dev/null || true}+on_exit() {+ local status=$?+ if [ -n "$UI_PORT_FWD_PID" ]; then+ kill "$UI_PORT_FWD_PID" 2>/dev/null || true+ wait "$UI_PORT_FWD_PID" 2>/dev/null || true+ UI_PORT_FWD_PID=""+ fi+ if [ "${E2E_KEEP_RESOURCES:-0}" = "1" ]; then+ warn "E2E_KEEP_RESOURCES=1; preserving OAuth fixtures for inspection"+ return "$status"+ fi+ cleanup+ return "$status"+}+if [[ "${1:-}" == "--cleanup-only" ]]; thencleanupexit 0fi-trap cleanup EXIT+trap on_exit EXIT# ─── Phase 0: Prerequisites ──────────────────────────────────────────check_prerequisites@@ -91,6 +178,37 @@ ok "Secret '${OAUTH_SECRET_NAME}' created in '${WORKFLOW_RECIPE_NS}'"# ─── Phase 3: Apply Recipe ───────────────────────────────────────────apply_recipe "$RECIPE_FILE" "$RECIPE_NAME"+cat <<YAML | kctl apply -f - >/dev/null+apiVersion: clerum.io/v1alpha1+kind: WorkflowRecipe+metadata:+ name: ${BACKGROUND_RECIPE_NAME}+ namespace: ${WORKFLOW_RECIPE_NS}+ labels:+ e2e.clerum.io/suite: wrc-oauth-broker-networkpolicy+spec:+ description: "Background OAuth NetworkPolicy route fixture."+ oauthClients:+ - id: slack-background+ provider: slack+ clientIdRef:+ name: ${OAUTH_SECRET_NAME}+ key: client-id+ clientSecretRef:+ name: ${OAUTH_SECRET_NAME}+ key: client-secret+ scopes: ["users:read"]+ backgroundAccess: true+ workloads:+ - id: ${BACKGROUND_WORKLOAD_ID}+ type: deployment+ image: busybox:1.36.1+ oauthClientRefs: ["slack-background"]+ command: ["sh", "-c"]+ args:+ - "trap 'exit 0' TERM INT; while true; do sleep 3600; done"+YAML+ok "Background OAuth fixture applied"# ─── Phase 4: Reconciliation reaches active ──────────────────────────header "Phase 4 — WorkflowRecipe reconciles to phase=active"@@ -105,6 +223,66 @@ elseexit 1fi+UI_DEPLOYMENT="$(wait_for_workload_instance "$RECIPE_NAME" "$WORKLOAD_ID" 120)"+[ -n "$UI_DEPLOYMENT" ] || {+ fail "UI workload instance was not assigned"+ exit 1+}++# ─── Phase 4b: background OAuth NetworkPolicy route ─────────────────+header "Phase 4b — background OAuth broker NetworkPolicy"+if ! wait_for_recipe_phase "$BACKGROUND_RECIPE_NAME" "$WORKFLOW_RECIPE_NS" "active" "$TIMEOUT_RECIPE_ACTIVE"; then+ phase=$(kctl get workflowrecipe "$BACKGROUND_RECIPE_NAME" -n "$WORKFLOW_RECIPE_NS" -o jsonpath='{.status.phase}' 2>/dev/null || echo "unknown")+ fail "Background OAuth recipe did not reach active (got '${phase}')"+ exit 1+fi++background_deployment="$(+ wait_for_workload_instance "$BACKGROUND_RECIPE_NAME" "$BACKGROUND_WORKLOAD_ID" 120+)"+[ -n "$background_deployment" ] || {+ fail "Background OAuth workload instance was not assigned"+ exit 1+}+wait_for_deployment "$WORKFLOW_RECIPE_NS" "$background_deployment" "$TIMEOUT_POD"+wrc_wait_for_np "$WORKFLOW_RECIPE_NS" "$BACKGROUND_POLICY_NAME" 120++control_api_ip="$(kctl get service control-api -n "$CONTROL_NS" -o jsonpath='{.spec.clusterIP}')"+[ -n "$control_api_ip" ] || {+ fail "Control API Service address discovery failed"+ exit 1+}++response="$(http_response_from_target "deploy/${background_deployment}" "$control_api_ip" 8090)"+if printf '%s' "$response" | grep -Eq 'HTTP/1\.[01] [2345][0-9][0-9]'; then+ ok "Opted-in background workload reaches the OAuth broker network boundary"+else+ fail "Opted-in background workload cannot reach the OAuth broker network boundary"+ exit 1+fi++create_background_probe+response="$(http_response_from_target "$BACKGROUND_PROBE_POD" "$control_api_ip" 8090)"+if printf '%s' "$response" | grep -Eq 'HTTP/1\.[01] [2345][0-9][0-9]'; then+ fail "Unlabelled sandbox workload reached Control API through the OAuth policy"+ exit 1+fi+ok "Unlabelled sandbox workload cannot use the OAuth broker egress"++oauth_policy_hash="$(wrc_np_spec_hash "$WORKFLOW_RECIPE_NS" "$BACKGROUND_POLICY_NAME")"+wrc_inject_selector_drift "$WORKFLOW_RECIPE_NS" "$BACKGROUND_POLICY_NAME"+wrc_trigger_recipe_reconcile "$WORKFLOW_RECIPE_NS" "$BACKGROUND_RECIPE_NAME" 120+wrc_wait_for_np_spec_hash "$WORKFLOW_RECIPE_NS" "$BACKGROUND_POLICY_NAME" "$oauth_policy_hash" 120+response="$(http_response_from_target "deploy/${background_deployment}" "$control_api_ip" 8090)"+if printf '%s' "$response" | grep -Eq 'HTTP/1\.[01] [2345][0-9][0-9]'; then+ ok "OAuth broker route recovered after live NetworkPolicy repair"+else+ fail "OAuth broker route did not recover after live NetworkPolicy repair"+ exit 1+fi+wrc_trigger_recipe_reconcile "$WORKFLOW_RECIPE_NS" "$BACKGROUND_RECIPE_NAME" 120+wrc_assert_np_stable "$WORKFLOW_RECIPE_NS" "$BACKGROUND_POLICY_NAME" "$STABILITY_SECONDS"+# ─── Phase 5: spec.oauthClients[] survives the round-trip ────────────header "Phase 5 — spec.oauthClients[] preserved on the WorkflowRecipe"oauth_id=$(kctl get workflowrecipe "$RECIPE_NAME" -n "$WORKFLOW_RECIPE_NS" \@@ -133,109 +311,120 @@ fi# ─── Phase 6: UI workload lands in sandbox-ui ────────────────────────header "Phase 6 — UI workload in sandbox-ui namespace"-if kctl get deployment "$WORKLOAD_ID" -n "$SANDBOX_UI_NS" &>/dev/null; then- ok "Deployment '${WORKLOAD_ID}' created in '${SANDBOX_UI_NS}'"+if kctl get deployment "$UI_DEPLOYMENT" -n "$SANDBOX_UI_NS" &>/dev/null; then+ ok "Deployment '${UI_DEPLOYMENT}' created in '${SANDBOX_UI_NS}'"else- fail "Deployment '${WORKLOAD_ID}' not found in '${SANDBOX_UI_NS}'"+ fail "Deployment '${UI_DEPLOYMENT}' not found in '${SANDBOX_UI_NS}'"fi-if kctl get deployment "$WORKLOAD_ID" -n "$WORKFLOW_RECIPE_NS" &>/dev/null; then- fail "Deployment '${WORKLOAD_ID}' leaked into '${WORKFLOW_RECIPE_NS}' (three-way split broken)"+if kctl get deployment "$UI_DEPLOYMENT" -n "$WORKFLOW_RECIPE_NS" &>/dev/null; then+ fail "Deployment '${UI_DEPLOYMENT}' leaked into '${WORKFLOW_RECIPE_NS}' (three-way split broken)"else- ok "Deployment '${WORKLOAD_ID}' is NOT in '${WORKFLOW_RECIPE_NS}' (split correct)"+ ok "Deployment '${UI_DEPLOYMENT}' is NOT in '${WORKFLOW_RECIPE_NS}' (split correct)"fi-if wait_for_deployment "$SANDBOX_UI_NS" "$WORKLOAD_ID" "$TIMEOUT_POD"; then- ok "Deployment '${WORKLOAD_ID}' reached Ready"+if wait_for_deployment "$SANDBOX_UI_NS" "$UI_DEPLOYMENT" "$TIMEOUT_POD"; then+ ok "Deployment '${UI_DEPLOYMENT}' reached Ready"else- fail "Deployment '${WORKLOAD_ID}' did not reach Ready within ${TIMEOUT_POD}s"- kctl describe deployment "$WORKLOAD_ID" -n "$SANDBOX_UI_NS" || true- kctl get pods -n "$SANDBOX_UI_NS" -l "clerum.io/workload-id=${WORKLOAD_ID}" || true+ fail "Deployment '${UI_DEPLOYMENT}' did not reach Ready within ${TIMEOUT_POD}s"+ kctl describe deployment "$UI_DEPLOYMENT" -n "$SANDBOX_UI_NS" || true+ kctl get pods -n "$SANDBOX_UI_NS" -l "clerum.io/recipe=${RECIPE_NAME},clerum.io/workload-id=${WORKLOAD_ID}" || truefi-if kctl get svc "$WORKLOAD_ID" -n "$SANDBOX_UI_NS" &>/dev/null; then- ok "Service '${WORKLOAD_ID}' created in '${SANDBOX_UI_NS}'"+if kctl get svc "$UI_DEPLOYMENT" -n "$SANDBOX_UI_NS" &>/dev/null; then+ ok "Service '${UI_DEPLOYMENT}' created in '${SANDBOX_UI_NS}'"else- fail "Service '${WORKLOAD_ID}' not found in '${SANDBOX_UI_NS}'"+ fail "Service '${UI_DEPLOYMENT}' not found in '${SANDBOX_UI_NS}'"fi+kctl port-forward -n "$SANDBOX_UI_NS" "service/${UI_DEPLOYMENT}" \+ "${UI_PORT_FWD_PORT}:8080" >/dev/null 2>&1 &+UI_PORT_FWD_PID=$!+ui_base_url="http://127.0.0.1:${UI_PORT_FWD_PORT}"+elapsed=0+while [ "$elapsed" -lt 30 ]; do+ if curl -fsS --max-time 2 "${ui_base_url}/" >/dev/null 2>&1; then+ break+ fi+ sleep "$POLL_INTERVAL"+ elapsed=$((elapsed + POLL_INTERVAL))+done+if ! kill -0 "$UI_PORT_FWD_PID" 2>/dev/null ||+ ! curl -fsS --max-time 2 "${ui_base_url}/" >/dev/null 2>&1; then+ fail "Scoped OAuth UI Service did not become reachable through its port-forward"+ exit 1+fi+ok "Scoped OAuth UI Service serves its visible route"+# ─── Phase 7: UI lifecycle assets serve correctly ────────────────────header "Phase 7 — index.html + app.js exercise the full OAuth lifecycle"pod_name=$(kctl get pods -n "$SANDBOX_UI_NS" \- -l "clerum.io/workload-id=${WORKLOAD_ID}" \+ -l "clerum.io/recipe=${RECIPE_NAME},clerum.io/workload-id=${WORKLOAD_ID}" \-o jsonpath='{.items[0].metadata.name}' 2>/dev/null || echo "")if [ -z "$pod_name" ]; then- pod_name=$(kctl get pods -n "$SANDBOX_UI_NS" -l "app=${WORKLOAD_ID}" \+ pod_name=$(kctl get pods -n "$SANDBOX_UI_NS" -l "app=${UI_DEPLOYMENT}" \-o jsonpath='{.items[0].metadata.name}' 2>/dev/null || echo "")fi-if [ -n "$pod_name" ]; then- html=$(kctl exec "$pod_name" -n "$SANDBOX_UI_NS" -- \- sh -c 'wget -qO- http://localhost:8080/' 2>/dev/null || echo "")- if echo "$html" | grep -q '<script src="app.js">'; then- ok "index.html loads app.js as an external script (CSP-compliant)"- else- fail "index.html does not load an external app.js — inline script would be blocked by rpc-proxy CSP"- fi+if [ -z "$pod_name" ]; then+ fail "Could not locate the scoped UI pod"+ exit 1+fi- # nginx must serve .js with application/javascript; default_type- # would make Chromium refuse the script under CSP.- ctype=$(kctl exec "$pod_name" -n "$SANDBOX_UI_NS" -- \- sh -c 'wget -qS -O /dev/null http://localhost:8080/app.js 2>&1 | grep -i "Content-Type"' 2>/dev/null || echo "")- if echo "$ctype" | grep -qi 'application/javascript'; then- ok "app.js is served with Content-Type: application/javascript"- else- fail "app.js Content-Type is not application/javascript (got '${ctype}')"- fi+html=$(curl -fsS --max-time 5 "${ui_base_url}/" 2>/dev/null || echo "")+if echo "$html" | grep -q '<script src="app.js">'; then+ ok "index.html loads app.js as an external script (CSP-compliant)"+else+ fail "index.html does not load an external app.js — inline script would be blocked by rpc-proxy CSP"+fi- app_js=$(kctl exec "$pod_name" -n "$SANDBOX_UI_NS" -- \- sh -c 'wget -qO- http://localhost:8080/app.js' 2>/dev/null || echo "")- if echo "$app_js" | grep -q 'clerum://oauth?clientId='; then- ok "app.js renders the clerum:// connect href"- else- fail "app.js is missing the clerum:// connect href"- fi- if echo "$app_js" | grep -q "/oauth/token"; then- ok "app.js probes /oauth/token on load"- else- fail "app.js is missing the /oauth/token probe call"- fi- if echo "$app_js" | grep -q "/oauth/grant"; then- ok "app.js calls /oauth/grant for the Disconnect button"- else- fail "app.js is missing the /oauth/grant DELETE call"- fi- if echo "$app_js" | grep -q 'clerum.onOauthCompleted'; then- ok "app.js subscribes to clerum.onOauthCompleted"- else- fail "app.js is missing the clerum.onOauthCompleted subscription"- fi+# nginx must serve .js with application/javascript; default_type+# would make Chromium refuse the script under CSP.+ctype=$(curl -sS --max-time 5 -D - -o /dev/null "${ui_base_url}/app.js" 2>/dev/null |+ grep -i '^content-type:' || true)+if echo "$ctype" | grep -qi 'application/javascript'; then+ ok "app.js is served with Content-Type: application/javascript"else- warn "Could not locate UI pod — skipping HTML / app.js content checks"+ fail "app.js Content-Type is not application/javascript (got '${ctype}')"fi+app_js=$(curl -fsS --max-time 5 "${ui_base_url}/app.js" 2>/dev/null || echo "")+if echo "$app_js" | grep -q 'clerum://oauth?clientId='; then+ ok "app.js renders the clerum:// connect href"+else+ fail "app.js is missing the clerum:// connect href"+fi+if echo "$app_js" | grep -q "/oauth/token"; then+ ok "app.js probes /oauth/token on load"+else+ fail "app.js is missing the /oauth/token probe call"+fi+if echo "$app_js" | grep -q "/oauth/grant"; then+ ok "app.js calls /oauth/grant for the Disconnect button"+else+ fail "app.js is missing the /oauth/grant DELETE call"+fi+if echo "$app_js" | grep -q 'clerum.onOauthCompleted'; then+ ok "app.js subscribes to clerum.onOauthCompleted"+else+ fail "app.js is missing the clerum.onOauthCompleted subscription"+fi# ─── Phase 8: Pod runs as non-root ───────────────────────────────────header "Phase 8 — UI pod runs as non-root"-if [ -n "$pod_name" ]; then- run_as_user=$(kctl get pod "$pod_name" -n "$SANDBOX_UI_NS" \- -o jsonpath='{.spec.containers[0].securityContext.runAsUser}' 2>/dev/null || echo "")- run_as_non_root=$(kctl get pod "$pod_name" -n "$SANDBOX_UI_NS" \- -o jsonpath='{.spec.containers[0].securityContext.runAsNonRoot}' 2>/dev/null || echo "")- if [ "$run_as_user" != "0" ] && [ "$run_as_user" != "" ]; then- ok "Pod '${pod_name}' container runAsUser=${run_as_user} (non-zero)"- elif [ "$run_as_non_root" = "true" ]; then- ok "Pod '${pod_name}' container runAsNonRoot=true"- else- fail "Pod '${pod_name}' may be running as root (runAsUser='${run_as_user}', runAsNonRoot='${run_as_non_root}')"- fi+runtime_uid=$(kctl exec "$pod_name" -n "$SANDBOX_UI_NS" -- id -u 2>/dev/null || echo "")+if [[ "$runtime_uid" =~ ^[0-9]+$ ]] && [ "$runtime_uid" -ne 0 ]; then+ ok "Pod '${pod_name}' runs as effective UID ${runtime_uid}"else- warn "Could not locate UI pod by workload-id or app label — skipping non-root check"+ fail "Pod '${pod_name}' effective UID is '${runtime_uid:-unknown}' (expected non-root)"fi# ─── Summary ─────────────────────────────────────────────────────────header "Summary"+# shellcheck disable=SC2154echo -e " ${GREEN}Passed:${NC} $e2e_pass"+# shellcheck disable=SC2154echo -e " ${RED}Failed:${NC} $e2e_fail"+# shellcheck disable=SC2154echo -e " ${BOLD}Total:${NC} $e2e_total"if [ "$e2e_fail" -gt 0 ]; thendiff --git a/scripts/e2e/e2e-webhooks-basic.sh b/scripts/e2e/e2e-webhooks-basic.shindex 87dcfadeb..08e9ff3d4 100755--- a/scripts/e2e/e2e-webhooks-basic.sh+++ b/scripts/e2e/e2e-webhooks-basic.sh@@ -27,7 +27,10 @@set -euo pipefailSCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"+# shellcheck disable=SC1091source "${SCRIPT_DIR}/e2e-lib.sh"+# shellcheck disable=SC1091+source "${SCRIPT_DIR}/_lib/wrc-networkpolicy-convergence.sh"require_safe_kube_context@@ -43,17 +46,55 @@ GATEWAY_NS="sandbox-recipes"PROXY_NS="webhook-ingress"PROXY_DEPLOYMENT="webhook-proxy"PROXY_PORT=8095+STABILITY_SECONDS="${E2E_NP_STABILITY_SECONDS:-20}"++PROXY_INGRESS_POLICY="allow-webhook-proxy-ingress-wf-${RECIPE_NAME}"+HANDLER_EGRESS_POLICY="allow-gateway-egress-to-handler-wf-${RECIPE_NAME}"+HANDLER_INGRESS_POLICY="allow-gateway-ingress-to-handler-wf-${RECIPE_NAME}"PORT_FWD_PORT=18095PORT_FWD_PID=""+wait_for_workload_instance() {+ local workload_id=$1 timeout=${2:-120} elapsed=0 instance+ while [ "$elapsed" -lt "$timeout" ]; do+ instance="$(kctl get workflowrecipe "$RECIPE_NAME" -n "$GATEWAY_NS" \+ -o "jsonpath={.status.workloadInstances.${workload_id}}" 2>/dev/null || true)"+ if [ -n "$instance" ]; then+ printf '%s\n' "$instance"+ return 0+ fi+ sleep "$POLL_INTERVAL"+ elapsed=$((elapsed + POLL_INTERVAL))+ done+ return 1+}++wait_for_recipe_active() {+ local timeout=${1:-120} elapsed=0 phase+ while [ "$elapsed" -lt "$timeout" ]; do+ phase="$(kctl get workflowrecipe "$RECIPE_NAME" -n "$GATEWAY_NS" \+ -o jsonpath='{.status.phase}' 2>/dev/null || true)"+ if [ "$phase" = "active" ]; then+ return 0+ fi+ case "$phase" in+ failed|rollback-failed|deprecated) return 1 ;;+ esac+ sleep "$POLL_INTERVAL"+ elapsed=$((elapsed + POLL_INTERVAL))+ done+ return 1+}++# shellcheck disable=SC2329cleanup() {local rc=$?set +e[ -n "$PORT_FWD_PID" ] && kill "$PORT_FWD_PID" 2>/dev/nullkctl -n "$GATEWAY_NS" delete -f "${SCRIPT_DIR}/../../${RECIPE_FILE}" --ignore-not-found --wait=false >/dev/null 2>&1kctl -n "$GATEWAY_NS" delete secret "$SECRET_NAME" --ignore-not-found >/dev/null 2>&1- exit $rc+ exit "$rc"}trap cleanup EXIT INT TERM@@ -68,6 +109,8 @@ log "leftover state cleared"header "Phase 2 — provision signing-secret Secret"if kctl -n "$GATEWAY_NS" create secret generic "$SECRET_NAME" \--from-literal="${SECRET_KEY}=${SECRET_VALUE}" >/dev/null 2>&1; then+ kctl -n "$GATEWAY_NS" label secret "$SECRET_NAME" \+ "clerum.io/owner-recipe=${RECIPE_NAME}" --overwrite >/dev/nullok "Secret $SECRET_NAME/$SECRET_KEY created in $GATEWAY_NS"elsefail "Secret create failed"@@ -94,7 +137,12 @@ elsefi# Also wait for the handler workload (nginx).-if wait_for_deployment "$GATEWAY_NS" "handler" 60; then+HANDLER_DEPLOYMENT="$(wait_for_workload_instance handler 120)"+[ -n "$HANDLER_DEPLOYMENT" ] || {+ fail "Handler workload instance was not assigned"+ exit 1+}+if wait_for_deployment "$GATEWAY_NS" "$HANDLER_DEPLOYMENT" 60; thenok "Handler Deployment is Ready"elsefail "Handler Deployment never became Ready"@@ -106,8 +154,9 @@ header "Phase 5 — verify supporting resources"for kind_name in \"service ${GATEWAY_NAME}" \"configmap wf-${RECIPE_NAME}-webhook-gateway-config" \- "networkpolicy allow-webhook-proxy-ingress-wf-${RECIPE_NAME}" \- "networkpolicy allow-gateway-egress-to-handler-wf-${RECIPE_NAME}"; do+ "networkpolicy ${PROXY_INGRESS_POLICY}" \+ "networkpolicy ${HANDLER_EGRESS_POLICY}" \+ "networkpolicy ${HANDLER_INGRESS_POLICY}"; dokind="${kind_name%% *}"name="${kind_name##* }"if kctl -n "$GATEWAY_NS" get "$kind" "$name" >/dev/null 2>&1; then@@ -119,11 +168,12 @@ for kind_name in \done# Status condition assertions.-phase=$(kctl -n "$GATEWAY_NS" get workflowrecipe "$RECIPE_NAME" -o jsonpath='{.status.phase}' 2>/dev/null || echo "")-if [ "$phase" = "active" ]; then+if wait_for_recipe_active 120; thenok "WorkflowRecipe status.phase == active"else- warn "WorkflowRecipe status.phase == ${phase:-<empty>} (allowed: degraded → active on next reconcile)"+ phase=$(kctl -n "$GATEWAY_NS" get workflowrecipe "$RECIPE_NAME" -o jsonpath='{.status.phase}' 2>/dev/null || echo "")+ fail "WorkflowRecipe status.phase == ${phase:-<empty>} (expected active)"+ exit 1fi# ─── Phase 6: POST a signed payload via webhook-proxy ───────────────@@ -131,11 +181,16 @@ header "Phase 6 — port-forward webhook-proxy and POST signed payload"kctl -n "$PROXY_NS" port-forward "deploy/${PROXY_DEPLOYMENT}" "${PORT_FWD_PORT}:${PROXY_PORT}" \>/dev/null 2>&1 &PORT_FWD_PID=$!-# Give port-forward time to settle.-sleep 4--# /healthz smoke check on the proxy.-if curl -sf "http://127.0.0.1:${PORT_FWD_PORT}/healthz" >/dev/null; then+proxy_ready=0+for _ in $(seq 1 30); do+ kill -0 "$PORT_FWD_PID" 2>/dev/null || break+ if curl -sf --max-time 2 "http://127.0.0.1:${PORT_FWD_PORT}/healthz" >/dev/null; then+ proxy_ready=1+ break+ fi+ sleep 1+done+if [ "$proxy_ready" = "1" ]; thenok "webhook-proxy /healthz reachable via port-forward"elsefail "webhook-proxy /healthz unreachable"@@ -163,6 +218,20 @@ http_status() {curl "${args[@]}"}+wait_for_policy_owner_uid() {+ local name=$1 expected=$2 timeout=${3:-120} elapsed=0 actual+ while [ "$elapsed" -lt "$timeout" ]; do+ actual="$(kctl get networkpolicy "$name" -n "$GATEWAY_NS" -o jsonpath='{.metadata.ownerReferences[0].uid}' 2>/dev/null || true)"+ if [ "$actual" = "$expected" ]; then+ return 0+ fi+ sleep "$POLL_INTERVAL"+ elapsed=$((elapsed + POLL_INTERVAL))+ done+ fail "NetworkPolicy ${GATEWAY_NS}/${name} did not converge to owner UID"+ return 1+}+status=$(http_status POST "$PUBLIC_PATH" "$SIG" "$PAYLOAD")if [ "$status" = "200" ]; thenok "POST with valid signature → 200"@@ -184,13 +253,13 @@ elsefail "POST with forged signature → ${status} (expected 401)"fi-# 7.2 Oversize body via Content-Length-big=$(head -c 2000000 </dev/zero | tr '\0' 'x')-status=$(curl -s -o /dev/null -w '%{http_code}' \+# 7.2 Oversize body via Content-Length. Stream it so the fixture never places a+# multi-megabyte value in argv (which exceeds ARG_MAX on macOS/Linux runners).+status=$(head -c 2000000 </dev/zero | tr '\0' 'x' | curl -s -o /dev/null -w '%{http_code}' \-X POST "http://127.0.0.1:${PORT_FWD_PORT}${PUBLIC_PATH}" \-H "content-type: application/json" \-H "content-length: 2000000" \- --data "$big")+ --data-binary @-)if [ "$status" = "413" ]; thenok "POST with oversize body → 413 body_too_large"else@@ -229,9 +298,48 @@ elsefail "PUT method → ${status} (expected 405)"fi+# ─── Phase 8: live convergence + owner repair ──────────────────────+header "Phase 8 — live drift and owner repair"+recipe_uid="$(kctl get workflowrecipe "$RECIPE_NAME" -n "$GATEWAY_NS" -o jsonpath='{.metadata.uid}')"+[ -n "$recipe_uid" ] || {+ fail "WorkflowRecipe UID is missing"+ exit 1+}++proxy_spec_hash="$(wrc_np_spec_hash "$GATEWAY_NS" "$PROXY_INGRESS_POLICY")"+wrc_inject_selector_drift "$GATEWAY_NS" "$PROXY_INGRESS_POLICY"+kctl patch networkpolicy "$HANDLER_EGRESS_POLICY" -n "$GATEWAY_NS" --type=json -p='[{"op":"replace","path":"/metadata/ownerReferences/0/uid","value":"00000000-0000-0000-0000-000000000580"}]' >/dev/null+kctl patch networkpolicy "$HANDLER_INGRESS_POLICY" -n "$GATEWAY_NS" --type=json -p='[{"op":"remove","path":"/metadata/ownerReferences"}]' >/dev/null+wrc_trigger_recipe_reconcile "$GATEWAY_NS" "$RECIPE_NAME" 120++wrc_wait_for_np_spec_hash "$GATEWAY_NS" "$PROXY_INGRESS_POLICY" "$proxy_spec_hash" 120+wait_for_policy_owner_uid "$PROXY_INGRESS_POLICY" "$recipe_uid" 120+wait_for_policy_owner_uid "$HANDLER_EGRESS_POLICY" "$recipe_uid" 120+wait_for_policy_owner_uid "$HANDLER_INGRESS_POLICY" "$recipe_uid" 120+ok "Webhook gateway policies repaired spec drift, stale owner and missing owner"++status=$(http_status POST "$PUBLIC_PATH" "$SIG" "$PAYLOAD")+if [ "$status" = "200" ]; then+ ok "Signed webhook route recovered after policy repair"+else+ fail "Signed webhook route returned ${status} after policy repair"+fi++proxy_rv="$(wrc_np_resource_version "$GATEWAY_NS" "$PROXY_INGRESS_POLICY")"+handler_egress_rv="$(wrc_np_resource_version "$GATEWAY_NS" "$HANDLER_EGRESS_POLICY")"+handler_ingress_rv="$(wrc_np_resource_version "$GATEWAY_NS" "$HANDLER_INGRESS_POLICY")"+wrc_trigger_recipe_reconcile "$GATEWAY_NS" "$RECIPE_NAME" 120+sleep "$STABILITY_SECONDS"+[ "$(wrc_np_resource_version "$GATEWAY_NS" "$PROXY_INGRESS_POLICY")" = "$proxy_rv" ] || fail "${PROXY_INGRESS_POLICY} churned"+[ "$(wrc_np_resource_version "$GATEWAY_NS" "$HANDLER_EGRESS_POLICY")" = "$handler_egress_rv" ] || fail "${HANDLER_EGRESS_POLICY} churned"+[ "$(wrc_np_resource_version "$GATEWAY_NS" "$HANDLER_INGRESS_POLICY")" = "$handler_ingress_rv" ] || fail "${HANDLER_INGRESS_POLICY} churned"+ok "All three webhook gateway policies stayed resourceVersion-stable"+# ─── Summary ────────────────────────────────────────────────────────header "Summary"+# shellcheck disable=SC2154echo " passed: ${e2e_pass}/${e2e_total}"+# shellcheck disable=SC2154echo " failed: ${e2e_fail}"if [ "$e2e_fail" -gt 0 ]; thendiff --git a/scripts/e2e/e2e-wrc-internal-dependency-networkpolicy.sh b/scripts/e2e/e2e-wrc-internal-dependency-networkpolicy.shindex f72cbca00..03e97b99c 100755--- a/scripts/e2e/e2e-wrc-internal-dependency-networkpolicy.sh+++ b/scripts/e2e/e2e-wrc-internal-dependency-networkpolicy.sh@@ -5,7 +5,10 @@set -euo pipefailSCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"+# shellcheck disable=SC1091source "${SCRIPT_DIR}/e2e-lib.sh"+# shellcheck disable=SC1091+source "${SCRIPT_DIR}/_lib/wrc-networkpolicy-convergence.sh"raw_run_id="${E2E_RUN_ID:-$(date +%H%M%S)-$$}"RUN_ID="$(printf "%s" "$raw_run_id" | tr '[:upper:]' '[:lower:]' \@@ -18,6 +21,7 @@ BACKEND_ID="${E2E_BACKEND_ID:-be-${RUN_ID}}"DENIED_POD="${E2E_DENIED_POD:-deny-${RUN_ID}}"BACKEND_PORT="${E2E_BACKEND_PORT:-8080}"CONNECT_TIMEOUT="${E2E_CONNECT_TIMEOUT:-6}"+STABILITY_SECONDS="${E2E_NP_STABILITY_SECONDS:-20}"SOURCE_DEPLOYMENT="$SOURCE_ID"BACKEND_DEPLOYMENT="$BACKEND_ID"CREATED=0@@ -265,6 +269,7 @@ assert_policy "$egress_ref" "egress" "$SOURCE_ID" "$BACKEND_ID"assert_policy "$ingress_ref" "ingress" "$BACKEND_ID" "$SOURCE_ID"header "Phase 4 - Positive packet flow"+# shellcheck disable=SC2016positive_output="$(kctl exec "deploy/${SOURCE_DEPLOYMENT}" -n "$SANDBOX_NS" -- \sh -c 'wget -qO- --timeout='"$CONNECT_TIMEOUT"' --tries=1 "$TARGET_URL"' 2>/dev/null || true)"printf "%s" "$positive_output" | grep -Fq "issue485-ok" && \@@ -273,7 +278,44 @@ printf "%s" "$positive_output" | grep -Fq "issue485-ok" && \exit 1}-header "Phase 5 - Negative packet flow"+header "Phase 5 - Live drift repair and steady no-churn"+egress_ns="${egress_ref%%/*}"+egress_name="${egress_ref#*/}"+ingress_ns="${ingress_ref%%/*}"+ingress_name="${ingress_ref#*/}"+egress_hash="$(wrc_np_spec_hash "$egress_ns" "$egress_name")"+ingress_hash="$(wrc_np_spec_hash "$ingress_ns" "$ingress_name")"++wrc_inject_selector_drift "$egress_ns" "$egress_name"+wrc_inject_selector_drift "$ingress_ns" "$ingress_name"+wrc_trigger_recipe_reconcile "$WORKFLOW_RECIPE_NS" "$RECIPE_NAME" 120+wrc_wait_for_np_spec_hash "$egress_ns" "$egress_name" "$egress_hash" 120+wrc_wait_for_np_spec_hash "$ingress_ns" "$ingress_name" "$ingress_hash" 120++# shellcheck disable=SC2016+repaired_output="$(kctl exec "deploy/${SOURCE_DEPLOYMENT}" -n "$SANDBOX_NS" -- \+ sh -c 'wget -qO- --timeout='"$CONNECT_TIMEOUT"' --tries=1 "$TARGET_URL"' 2>/dev/null || true)"+printf "%s" "$repaired_output" | grep -Fq "issue485-ok" && \+ ok "Internal dependency traffic recovered after live policy repair" || {+ fail "Internal dependency traffic did not recover after policy repair"+ exit 1+ }++egress_rv="$(wrc_np_resource_version "$egress_ns" "$egress_name")"+ingress_rv="$(wrc_np_resource_version "$ingress_ns" "$ingress_name")"+wrc_trigger_recipe_reconcile "$WORKFLOW_RECIPE_NS" "$RECIPE_NAME" 120+sleep "$STABILITY_SECONDS"+[ "$(wrc_np_resource_version "$egress_ns" "$egress_name")" = "$egress_rv" ] || {+ fail "${egress_ref} churned after convergence"+ exit 1+}+[ "$(wrc_np_resource_version "$ingress_ns" "$ingress_name")" = "$ingress_rv" ] || {+ fail "${ingress_ref} churned after convergence"+ exit 1+}+ok "Both internal-dependency policies stayed resourceVersion-stable"++header "Phase 6 - Negative packet flow"kctl delete pod "$DENIED_POD" -n "$SANDBOX_NS" --ignore-not-found --wait=false >/dev/null 2>&1 || truecat <<YAML | kctl apply -f - >/dev/nullapiVersion: v1@@ -313,7 +355,7 @@ if kctl exec "$DENIED_POD" -n "$SANDBOX_NS" -- wget -qO- \fiok "Unlabeled pod cannot reach backend"-header "Phase 6 - Cleanup"+header "Phase 7 - Cleanup"cleanupCREATED=0kctl get workflowrecipe "$RECIPE_NAME" -n "$WORKFLOW_RECIPE_NS" >/dev/null 2>&1 \diff --git a/scripts/e2e/e2e-wrc-networkpolicy-live-convergence.sh b/scripts/e2e/e2e-wrc-networkpolicy-live-convergence.shnew file mode 100755index 000000000..73e8248bf--- /dev/null+++ b/scripts/e2e/e2e-wrc-networkpolicy-live-convergence.sh@@ -0,0 +1,33 @@+#!/usr/bin/env bash+# Aggregate PR #580 gate. Every WRC NetworkPolicy family must execute; a missing+# script or any non-zero child result fails the aggregate.++set -euo pipefail++SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"+: "${KUBECONTEXT:?KUBECONTEXT is required for WRC NetworkPolicy E2E}"++suites=(+ e2e-wrc-networkpolicy-service-routes.sh+ e2e-wrc-internal-dependency-networkpolicy.sh+ e2e-sandbox-ui-oauth.sh+ e2e-webhooks-basic.sh+)++executed=0+for suite in "${suites[@]}"; do+ path="${SCRIPT_DIR}/${suite}"+ [ -f "$path" ] || {+ printf 'FAIL: required WRC NetworkPolicy E2E suite is missing: %s\n' "$suite" >&2+ exit 1+ }+ printf '\n[WRC-NP-E2E] running %s\n' "$suite"+ KUBECONTEXT="$KUBECONTEXT" bash "$path"+ executed=$((executed + 1))+done++[ "$executed" -eq "${#suites[@]}" ] || {+ printf 'FAIL: WRC NetworkPolicy E2E executed %s/%s suites\n' "$executed" "${#suites[@]}" >&2+ exit 1+}+printf 'WRC_NETWORKPOLICY_E2E_PASS suites=%s\n' "$executed"diff --git a/scripts/e2e/e2e-wrc-networkpolicy-service-routes.sh b/scripts/e2e/e2e-wrc-networkpolicy-service-routes.shnew file mode 100755index 000000000..f032362bc--- /dev/null+++ b/scripts/e2e/e2e-wrc-networkpolicy-service-routes.sh@@ -0,0 +1,291 @@+#!/usr/bin/env bash+# PR #580 E2E for correctly configured WRC NetworkPolicy service routes.++set -euo pipefail++SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"+# shellcheck disable=SC1091+source "${SCRIPT_DIR}/e2e-lib.sh"+# shellcheck disable=SC1091+source "${SCRIPT_DIR}/_lib/wrc-networkpolicy-convergence.sh"++raw_run_id="${E2E_RUN_ID:-$(date +%H%M%S)-$$}"+RUN_ID="$(printf '%s' "$raw_run_id" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9-]+/-/g; s/^-+//; s/-+$//; s/-+/-/g' | cut -c1-16)"+[ -n "$RUN_ID" ] || RUN_ID="run-$$"++RECIPE_NAME="${E2E_RECIPE_NAME:-e2e-wrc-routes-${RUN_ID}}"+SANDBOX_UI_NS="${SANDBOX_UI_NS:-sandbox-ui}"+UI_ID="ui"+API_ID="api"+DB_ID="db"+DB_PORT=8081+CONNECT_TIMEOUT="${E2E_CONNECT_TIMEOUT:-6}"+STABILITY_SECONDS="${E2E_NP_STABILITY_SECONDS:-20}"+ROGUE_UI_POD="${RECIPE_NAME}-rogue-ui"+ROGUE_WORKLOAD_POD="${RECIPE_NAME}-rogue-wl"+CREATED=0++UI_DEPLOYMENT=""+API_DEPLOYMENT=""+DB_DEPLOYMENT=""++UI_INGRESS_POLICY="ui-ingress-${RECIPE_NAME}-${API_ID}"+WL_EGRESS_POLICY="wl-egress-${RECIPE_NAME}-${API_ID}"+WL_INGRESS_POLICY="wl-ingress-${RECIPE_NAME}-${DB_ID}"++cleanup() {+ local status=0 namespace+ kctl delete pod "$ROGUE_UI_POD" -n "$SANDBOX_UI_NS" --ignore-not-found --wait=false >/dev/null 2>&1 || status=1+ kctl delete pod "$ROGUE_WORKLOAD_POD" -n "$SANDBOX_NS" --ignore-not-found --wait=false >/dev/null 2>&1 || status=1+ kctl delete workflowrecipe "$RECIPE_NAME" -n "$WORKFLOW_RECIPE_NS" --ignore-not-found --wait=false >/dev/null 2>&1 || status=1+ wait_for_workflowrecipe_deleted "$WORKFLOW_RECIPE_NS" "$RECIPE_NAME" "$TIMEOUT_DELETE" >/dev/null 2>&1 || status=1+ for namespace in "$SANDBOX_NS" "$SANDBOX_UI_NS"; do+ kctl delete networkpolicy -n "$namespace" -l "clerum.io/recipe=${RECIPE_NAME}" --ignore-not-found >/dev/null 2>&1 || status=1+ done+ return "$status"+}++on_exit() {+ local status=$?+ if [ "$CREATED" = "1" ] && [ "${E2E_KEEP_RESOURCES:-0}" != "1" ]; then+ cleanup >/dev/null 2>&1 || {+ [ "$status" -ne 0 ] && warn "WRC service-route E2E cleanup left resources behind"+ [ "$status" -eq 0 ] && fail "WRC service-route E2E cleanup left resources behind" && status=1+ }+ fi+ exit "$status"+}+trap on_exit EXIT++wait_for_workload_instance() {+ local workload_id=$1 timeout=${2:-$TIMEOUT_POD} elapsed=0 instance+ while [ "$elapsed" -lt "$timeout" ]; do+ instance="$(kctl get workflowrecipe "$RECIPE_NAME" -n "$WORKFLOW_RECIPE_NS" -o "jsonpath={.status.workloadInstances.${workload_id}}" 2>/dev/null || true)"+ if [ -n "$instance" ]; then+ printf '%s\n' "$instance"+ return 0+ fi+ sleep "$POLL_INTERVAL"+ elapsed=$((elapsed + POLL_INTERVAL))+ done+ return 1+}++wait_for_recipe_active() {+ local timeout=${1:-180} elapsed=0 phase+ while [ "$elapsed" -lt "$timeout" ]; do+ phase="$(kctl get workflowrecipe "$RECIPE_NAME" -n "$WORKFLOW_RECIPE_NS" -o jsonpath='{.status.phase}' 2>/dev/null || true)"+ case "$phase" in+ active) return 0 ;;+ failed|rollback-failed|deprecated)+ fail "WorkflowRecipe entered terminal phase ${phase}"+ return 1+ ;;+ esac+ sleep "$POLL_INTERVAL"+ elapsed=$((elapsed + POLL_INTERVAL))+ done+ fail "WorkflowRecipe did not reach active"+ return 1+}++assert_http_body() {+ local description=$1 namespace=$2 deployment=$3 host=$4 port=$5 expected=$6 body+ # shellcheck disable=SC2016+ body="$(kctl exec "deploy/${deployment}" -n "$namespace" -- sh -c 'printf "GET / HTTP/1.0\r\nHost: e2e\r\nConnection: close\r\n\r\n" | nc -w "$1" "$2" "$3"' -- "$CONNECT_TIMEOUT" "$host" "$port" 2>/dev/null || true)"+ if printf '%s' "$body" | grep -Fq "$expected"; then+ ok "$description"+ return 0+ fi+ fail "${description} (unexpected response)"+ return 1+}++assert_pod_blocked() {+ local description=$1 namespace=$2 pod=$3 host=$4 port=$5+ # shellcheck disable=SC2016+ if kctl exec "$pod" -n "$namespace" -- sh -c 'printf "GET / HTTP/1.0\r\n\r\n" | nc -w "$1" "$2" "$3"' -- "$CONNECT_TIMEOUT" "$host" "$port" >/dev/null 2>&1; then+ fail "${description}: unexpected connection succeeded"+ return 1+ fi+ ok "$description"+}++apply_rogue_pod() {+ local namespace=$1 name=$2+ cat <<YAML | kctl apply -f - >/dev/null+apiVersion: v1+kind: Pod+metadata:+ name: ${name}+ namespace: ${namespace}+ labels:+ e2e.clerum.io/suite: wrc-networkpolicy-service-routes+ e2e.clerum.io/probe: ${name}+spec:+ restartPolicy: Never+ securityContext:+ runAsNonRoot: true+ runAsUser: 65532+ runAsGroup: 65532+ seccompProfile:+ type: RuntimeDefault+ containers:+ - name: probe+ image: busybox:1.36.1+ command: ["sh", "-c", "trap 'exit 0' TERM INT; while true; do sleep 3600; done"]+ securityContext:+ allowPrivilegeEscalation: false+ capabilities:+ drop: ["ALL"]+YAML+ wait_for_pod "$namespace" "e2e.clerum.io/probe=${name}" 60+}++assert_all_stable() {+ local ui_before wl_egress_before wl_ingress_before+ local ui_after wl_egress_after wl_ingress_after+ ui_before="$(wrc_np_resource_version "$SANDBOX_NS" "$UI_INGRESS_POLICY")"+ wl_egress_before="$(wrc_np_resource_version "$SANDBOX_NS" "$WL_EGRESS_POLICY")"+ wl_ingress_before="$(wrc_np_resource_version "$SANDBOX_NS" "$WL_INGRESS_POLICY")"++ # Intentional no-churn observation window after all readiness assertions.+ sleep "$STABILITY_SECONDS"++ ui_after="$(wrc_np_resource_version "$SANDBOX_NS" "$UI_INGRESS_POLICY")"+ wl_egress_after="$(wrc_np_resource_version "$SANDBOX_NS" "$WL_EGRESS_POLICY")"+ wl_ingress_after="$(wrc_np_resource_version "$SANDBOX_NS" "$WL_INGRESS_POLICY")"++ [ "$ui_after" = "$ui_before" ] || fail "${UI_INGRESS_POLICY} churned"+ [ "$wl_egress_after" = "$wl_egress_before" ] || fail "${WL_EGRESS_POLICY} churned"+ [ "$wl_ingress_after" = "$wl_ingress_before" ] || fail "${WL_INGRESS_POLICY} churned"+ ok "All three converged NetworkPolicies stayed resourceVersion-stable"+}++header "WRC NetworkPolicy correctly-configured service routes"+require_safe_kube_context+kctl cluster-info >/dev/null 2>&1 || {+ fail "Kubernetes cluster is not reachable"+ exit 1+}+kctl -n "$CONTROL_NS" rollout status deploy/workflow-recipes --timeout=120s >/dev/null++header "Phase 1 — isolated fixture"+cleanup >/dev/null 2>&1 || true+cat <<YAML | kctl apply -f - >/dev/null+apiVersion: clerum.io/v1alpha1+kind: WorkflowRecipe+metadata:+ name: ${RECIPE_NAME}+ namespace: ${WORKFLOW_RECIPE_NS}+ labels:+ e2e.clerum.io/suite: wrc-networkpolicy-service-routes+spec:+ description: "PR 580 service-route and live-convergence fixture."+ workloads:+ - id: ${UI_ID}+ type: deployment+ image: busybox:1.36.1+ port: 8080+ command: ["sh", "-c"]+ args:+ - "mkdir -p /www && printf 'ui-ok\n' > /www/index.html && exec httpd -f -p 8080 -h /www"+ - id: ${API_ID}+ type: deployment+ image: busybox:1.36.1+ port: 8080+ command: ["sh", "-c"]+ args:+ - "mkdir -p /www && printf 'api-ok\n' > /www/index.html && exec httpd -f -p 8080 -h /www"+ egressBindings:+ - dns: "${DB_ID}.${SANDBOX_NS}.svc.cluster.local"+ port: ${DB_PORT}+ protocol: TCP+ - id: ${DB_ID}+ type: deployment+ image: busybox:1.36.1+ port: ${DB_PORT}+ command: ["sh", "-c"]+ args:+ - "mkdir -p /www && printf 'db-ok\n' > /www/index.html && exec httpd -f -p ${DB_PORT} -h /www"+ ui:+ workloadRef: ${UI_ID}+ port: 8080+ title: "NetworkPolicy route fixture"+ defaultPath: "/"+ egress:+ internal:+ - workloadRef: ${API_ID}+ port: 8080+YAML+CREATED=1+wait_for_recipe_active 180++UI_DEPLOYMENT="$(wait_for_workload_instance "$UI_ID" 120)"+API_DEPLOYMENT="$(wait_for_workload_instance "$API_ID" 120)"+DB_DEPLOYMENT="$(wait_for_workload_instance "$DB_ID" 120)"+[ -n "$UI_DEPLOYMENT" ] && [ -n "$API_DEPLOYMENT" ] && [ -n "$DB_DEPLOYMENT" ] || {+ fail "One or more workload instance names are missing"+ exit 1+}++wait_for_deployment "$SANDBOX_UI_NS" "$UI_DEPLOYMENT" 180+wait_for_deployment "$SANDBOX_NS" "$API_DEPLOYMENT" 180+wait_for_deployment "$SANDBOX_NS" "$DB_DEPLOYMENT" 180++for policy in "$UI_INGRESS_POLICY" "$WL_EGRESS_POLICY" "$WL_INGRESS_POLICY"; do+ wrc_wait_for_np "$SANDBOX_NS" "$policy" 120+done+ok "ui-ingress, workload-egress and workload-ingress materialized"++API_CLUSTER_IP="$(kctl get service "$API_DEPLOYMENT" -n "$SANDBOX_NS" -o jsonpath='{.spec.clusterIP}')"+DB_CLUSTER_IP="$(kctl get service "$DB_DEPLOYMENT" -n "$SANDBOX_NS" -o jsonpath='{.spec.clusterIP}')"+[ -n "$API_CLUSTER_IP" ] && [ -n "$DB_CLUSTER_IP" ] || {+ fail "Fixture Service ClusterIP discovery failed"+ exit 1+}++header "Phase 2 — correctly configured positive routes"+assert_http_body "sandbox UI reaches declared API backend" "$SANDBOX_UI_NS" "$UI_DEPLOYMENT" "$API_CLUSTER_IP" 8080 "api-ok"+assert_http_body "API workload reaches declared sibling DB" "$SANDBOX_NS" "$API_DEPLOYMENT" "$DB_CLUSTER_IP" "$DB_PORT" "db-ok"++header "Phase 3 — negative controls"+apply_rogue_pod "$SANDBOX_UI_NS" "$ROGUE_UI_POD"+apply_rogue_pod "$SANDBOX_NS" "$ROGUE_WORKLOAD_POD"+assert_pod_blocked "unlabelled sandbox-ui pod cannot reach recipe API" "$SANDBOX_UI_NS" "$ROGUE_UI_POD" "$API_CLUSTER_IP" 8080+assert_pod_blocked "unlabelled sandbox workload cannot reach recipe DB" "$SANDBOX_NS" "$ROGUE_WORKLOAD_POD" "$DB_CLUSTER_IP" "$DB_PORT"++header "Phase 4 — live drift repair"+ui_hash="$(wrc_np_spec_hash "$SANDBOX_NS" "$UI_INGRESS_POLICY")"+wl_egress_hash="$(wrc_np_spec_hash "$SANDBOX_NS" "$WL_EGRESS_POLICY")"+wl_ingress_hash="$(wrc_np_spec_hash "$SANDBOX_NS" "$WL_INGRESS_POLICY")"++wrc_inject_selector_drift "$SANDBOX_NS" "$UI_INGRESS_POLICY"+wrc_inject_selector_drift "$SANDBOX_NS" "$WL_EGRESS_POLICY"+wrc_inject_selector_drift "$SANDBOX_NS" "$WL_INGRESS_POLICY"+wrc_trigger_recipe_reconcile "$WORKFLOW_RECIPE_NS" "$RECIPE_NAME" 120++wrc_wait_for_np_spec_hash "$SANDBOX_NS" "$UI_INGRESS_POLICY" "$ui_hash" 120+wrc_wait_for_np_spec_hash "$SANDBOX_NS" "$WL_EGRESS_POLICY" "$wl_egress_hash" 120+wrc_wait_for_np_spec_hash "$SANDBOX_NS" "$WL_INGRESS_POLICY" "$wl_ingress_hash" 120+ok "WRC repaired live spec drift for all three families"++assert_http_body "sandbox UI route recovered after NetworkPolicy repair" "$SANDBOX_UI_NS" "$UI_DEPLOYMENT" "$API_CLUSTER_IP" 8080 "api-ok"+assert_http_body "workload sibling route recovered after NetworkPolicy repair" "$SANDBOX_NS" "$API_DEPLOYMENT" "$DB_CLUSTER_IP" "$DB_PORT" "db-ok"++header "Phase 5 — steady-state no-churn"+wrc_trigger_recipe_reconcile "$WORKFLOW_RECIPE_NS" "$RECIPE_NAME" 120+assert_all_stable++header "Phase 6 — cleanup"+cleanup+CREATED=0+for policy in "$UI_INGRESS_POLICY" "$WL_EGRESS_POLICY" "$WL_INGRESS_POLICY"; do+ if kctl get networkpolicy "$policy" -n "$SANDBOX_NS" >/dev/null 2>&1; then+ fail "NetworkPolicy ${SANDBOX_NS}/${policy} survived cleanup"+ exit 1+ fi+done+ok "WorkflowRecipe and WRC NetworkPolicies were removed"++print_resultsdiff --git a/scripts/tests/test-wrc-networkpolicy-live-convergence-e2e.sh b/scripts/tests/test-wrc-networkpolicy-live-convergence-e2e.shnew file mode 100755index 000000000..95c5e9f48--- /dev/null+++ b/scripts/tests/test-wrc-networkpolicy-live-convergence-e2e.sh@@ -0,0 +1,106 @@+#!/usr/bin/env bash+set -u++ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"+AGGREGATE="${ROOT}/scripts/e2e/e2e-wrc-networkpolicy-live-convergence.sh"+ROUTES="${ROOT}/scripts/e2e/e2e-wrc-networkpolicy-service-routes.sh"+INTDEP="${ROOT}/scripts/e2e/e2e-wrc-internal-dependency-networkpolicy.sh"+OAUTH="${ROOT}/scripts/e2e/e2e-sandbox-ui-oauth.sh"+WEBHOOK="${ROOT}/scripts/e2e/e2e-webhooks-basic.sh"+HELPER="${ROOT}/scripts/e2e/_lib/wrc-networkpolicy-convergence.sh"+FAIL=0++pass() { printf 'PASS: %s\n' "$1"; }+fail() { printf 'FAIL: %s\n' "$1"; FAIL=1; }++for script in "$AGGREGATE" "$ROUTES" "$INTDEP" "$OAUTH" "$WEBHOOK" "$HELPER"; do+ if bash -n "$script"; then+ pass "$(basename "$script") has valid bash syntax"+ else+ fail "$(basename "$script") has invalid bash syntax"+ fi+done++for suite in \+ e2e-wrc-networkpolicy-service-routes.sh \+ e2e-wrc-internal-dependency-networkpolicy.sh \+ e2e-sandbox-ui-oauth.sh \+ e2e-webhooks-basic.sh; do+ grep -Fq "$suite" "$AGGREGATE" || fail "aggregate omits $suite"+done+if grep -Fq 'WRC_NETWORKPOLICY_E2E_PASS' "$AGGREGATE" &&+ grep -Fq 'set -euo pipefail' "$AGGREGATE"; then+ pass "aggregate is fail-loud and emits a terminal suite count"+else+ fail "aggregate can pass without executing every suite"+fi++if grep -Fq 'e2e-wrc-networkpolicy-live-convergence.sh' "${ROOT}/Makefile"; then+ pass "canonical Make E2E aggregate includes the WRC NetworkPolicy gate"+else+ fail "canonical Make E2E aggregate omits the WRC NetworkPolicy gate"+fi++if grep -Fq 'patch workflowrecipe' "$HELPER" &&+ grep -Fq 'metadata.generation' "$HELPER" &&+ grep -Fq 'deployment/${controller_deployment}' "$HELPER"; then+ pass "reconcile trigger advances the parent spec and observes the real WRC pass"+else+ fail "reconcile trigger does not prove a parent recipe reconcile"+fi++for entry in \+ "$ROUTES:service-route" \+ "$INTDEP:internal-dependency" \+ "$OAUTH:OAuth broker" \+ "$WEBHOOK:webhook"; do+ script=${entry%%:*}+ label=${entry#*:}+ trigger_count=$(grep -Fc 'wrc_trigger_recipe_reconcile' "$script" || true)+ if [ "$trigger_count" -ge 2 ]; then+ pass "${label} E2E drives both repair and equivalent no-op reconciles"+ else+ fail "${label} E2E does not drive both required reconciles"+ fi+done++for family in UI_INGRESS_POLICY WL_EGRESS_POLICY WL_INGRESS_POLICY; do+ grep -Fq "$family" "$ROUTES" || fail "service-route E2E omits $family"+done+if grep -Fq 'correctly configured positive routes' "$ROUTES" &&+ grep -Fq 'negative controls' "$ROUTES" &&+ grep -Fq 'live drift repair' "$ROUTES" &&+ grep -Fq 'steady-state no-churn' "$ROUTES"; then+ pass "UI/workload route E2E proves positive, negative, repair, and no-churn signals"+else+ fail "UI/workload route E2E is missing a required signal"+fi++if grep -Fq 'Live drift repair and steady no-churn' "$INTDEP" &&+ grep -Fq 'Internal dependency traffic recovered' "$INTDEP"; then+ pass "internal-dependency E2E proves live repair and restored traffic"+else+ fail "internal-dependency E2E lacks repair or traffic evidence"+fi++if grep -Fq 'BACKGROUND_POLICY_NAME' "$OAUTH" &&+ grep -Fq 'Opted-in background workload reaches' "$OAUTH" &&+ grep -Fq 'Unlabelled sandbox workload cannot use' "$OAUTH" &&+ grep -Fq 'OAuth broker route recovered' "$OAUTH"; then+ pass "OAuth broker E2E proves allow, deny, repair, and no-churn behavior"+else+ fail "OAuth broker E2E lacks a required dataplane signal"+fi++for policy in PROXY_INGRESS_POLICY HANDLER_EGRESS_POLICY HANDLER_INGRESS_POLICY; do+ grep -Fq "$policy" "$WEBHOOK" || fail "webhook E2E omits $policy"+done+if grep -Fq 'live drift and owner repair' "$WEBHOOK" &&+ grep -Fq 'Signed webhook route recovered' "$WEBHOOK" &&+ grep -Fq 'stayed resourceVersion-stable' "$WEBHOOK"; then+ pass "webhook E2E proves all three policies, owner repair, route recovery, and no churn"+else+ fail "webhook E2E lacks a required convergence signal"+fi++exit "$FAIL"diff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.jsonindex e63ee916f..543d4a0a6 100644--- a/workflow-recipes/package-lock.json+++ b/workflow-recipes/package-lock.json@@ -1,12 +1,12 @@{"name": "workload-recipes-controller",- "version": "0.1.343",+ "version": "0.1.344","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "workload-recipes-controller",- "version": "0.1.343",+ "version": "0.1.344","license": "SEE LICENSE IN LICENSE","dependencies": {"@aws-sdk/client-s3": "^3.1009.0",diff --git a/workflow-recipes/package.json b/workflow-recipes/package.jsonindex 18fc8a122..e2b3242cc 100644--- a/workflow-recipes/package.json+++ b/workflow-recipes/package.json@@ -1,6 +1,6 @@{"name": "workload-recipes-controller",- "version": "0.1.343",+ "version": "0.1.344","description": "Workload Recipes Controller (WRC) - WorkloadRecipe lifecycle management and MCP server interface","main": "dist/main.js","engines": {diff --git a/workflow-recipes/samples/webhook-hello.yaml b/workflow-recipes/samples/webhook-hello.yamlindex f9e72a3a7..41ee514ff 100644--- a/workflow-recipes/samples/webhook-hello.yaml+++ b/workflow-recipes/samples/webhook-hello.yaml@@ -7,15 +7,36 @@ spec:description: >-Smallest possible recipe with spec.webhooks[]. Used byscripts/e2e/e2e-webhooks-basic.sh to gate the webhook stack on a- real cluster. The handler is nginxinc/nginx-unprivileged on its- default config — a 200 response from the default welcome page is- enough to prove the verify+forward pipeline. Headers sent by the- gateway show up in the nginx access log.+ real cluster. The handler is nginxinc/nginx-unprivileged with a+ minimal endpoint that accepts POST and returns 200, proving the+ verify+forward pipeline. Headers sent by the gateway show up in+ the nginx access log.workloads:- id: handlertype: deploymentimage: nginxinc/nginx-unprivileged:1.27-alpineport: 8080+ command: ['/bin/sh', '-c']+ args:+ - |+ set -e+ cat > /tmp/nginx.conf <<'EOF'+ worker_processes 1;+ pid /tmp/nginx.pid;+ error_log /dev/stderr;+ events {}+ http {+ access_log /dev/stdout;+ server {+ listen 8080;+ location / {+ default_type text/plain;+ return 200 'webhook-ok\n';+ }+ }+ }+ EOF+ exec nginx -c /tmp/nginx.conf -g 'daemon off;'webhooks:- id: helloworkloadRef: handlerdiff --git a/workflow-recipes/src/reconciler/networkPolicyConvergence.test.ts b/workflow-recipes/src/reconciler/networkPolicyConvergence.test.tsindex 7997a107a..e708077f9 100644--- a/workflow-recipes/src/reconciler/networkPolicyConvergence.test.ts+++ b/workflow-recipes/src/reconciler/networkPolicyConvergence.test.ts@@ -175,6 +175,21 @@ describe('NetworkPolicy live convergence', () => {})})+ it('does not repair a stale gateway owner when the WRC recipe identity labels drifted', () => {+ const desired = gatewayPolicy('uid-new')+ const wrongRecipe = gatewayPolicy('uid-old')+ wrongRecipe.metadata!.labels!['clerum.io/recipe-name'] = 'another-recipe'++ expect(classifyNetworkPolicyOwnership('webhook-gateway', desired, wrongRecipe)).toEqual({+ kind: 'conflict',+ reason: 'identity-label-mismatch',+ })+ expect(decideNetworkPolicyConvergence('webhook-gateway', desired, wrongRecipe)).toEqual({+ action: 'conflict',+ reason: 'identity-label-mismatch',+ })+ })+it('refuses a gateway policy controlled by a different owner', () => {const desired = gatewayPolicy('uid-new')const foreign = gatewayPolicy('uid-new')diff --git a/workflow-recipes/src/reconciler/reconciler.test.ts b/workflow-recipes/src/reconciler/reconciler.test.tsindex bc891e54f..27e5d7c40 100644--- a/workflow-recipes/src/reconciler/reconciler.test.ts+++ b/workflow-recipes/src/reconciler/reconciler.test.ts@@ -1164,6 +1164,57 @@ describe('WorkflowRecipeReconciler', () => {expect(mockNetworkingApi.replaceNamespacedNetworkPolicy).not.toHaveBeenCalled()})+ it('creates after a transient first read is followed by a confirmed 404', async () => {+ const desired = plainPolicy()+ mockNetworkingApi.readNamespacedNetworkPolicy+ .mockRejectedValueOnce({ code: 500 })+ .mockRejectedValueOnce({ code: 404 })++ await apply(desired)++ expect(mockNetworkingApi.readNamespacedNetworkPolicy).toHaveBeenCalledTimes(2)+ expect(mockNetworkingApi.createNamespacedNetworkPolicy).toHaveBeenCalledTimes(1)+ expect(mockNetworkingApi.replaceNamespacedNetworkPolicy).not.toHaveBeenCalled()+ })++ it('uses a supplied absent workload-egress snapshot without issuing another read', async () => {+ const desired = plainPolicy()+ desired.metadata!.name = 'wl-egress-r-w'++ await apply(desired, 'workload-egress', null)++ expect(mockNetworkingApi.readNamespacedNetworkPolicy).not.toHaveBeenCalled()+ expect(mockNetworkingApi.createNamespacedNetworkPolicy).toHaveBeenCalledTimes(1)+ })++ it('retries when a create-conflict winner is absent on the bounded re-read', async () => {+ const desired = plainPolicy()+ mockNetworkingApi.readNamespacedNetworkPolicy.mockRejectedValue({ code: 404 })+ mockNetworkingApi.createNamespacedNetworkPolicy.mockRejectedValueOnce({ code: 409 })++ await expect(apply(desired)).rejects.toMatchObject({+ name: 'RetryableReconcileError',+ cause: { code: 409 },+ })+ expect(mockNetworkingApi.readNamespacedNetworkPolicy).toHaveBeenCalledTimes(2)+ expect(mockNetworkingApi.createNamespacedNetworkPolicy).toHaveBeenCalledTimes(1)+ expect(mockNetworkingApi.replaceNamespacedNetworkPolicy).not.toHaveBeenCalled()+ })++ it('retries instead of blind replacing a drifted live policy without resourceVersion', async () => {+ const desired = plainPolicy()+ const live = livePolicy(desired)+ delete live.metadata!.resourceVersion+ live.spec!.podSelector = {}+ mockNetworkingApi.readNamespacedNetworkPolicy.mockResolvedValue(live)++ await expect(apply(desired)).rejects.toMatchObject({+ name: 'RetryableReconcileError',+ message: expect.stringMatching(/has no resourceVersion/),+ })+ expect(mockNetworkingApi.replaceNamespacedNetworkPolicy).not.toHaveBeenCalled()+ })+it.each([404, 409])('classifies replace race status %s as retryable', async code => {const desired = plainPolicy()const live = livePolicy(desired)@@ -1177,6 +1228,55 @@ describe('WorkflowRecipeReconciler', () => {})})+ it.each([500, 'ETIMEDOUT'])('preserves replace infrastructure failure %s', async code => {+ const desired = plainPolicy()+ const live = livePolicy(desired)+ live.spec!.podSelector = {}+ mockNetworkingApi.readNamespacedNetworkPolicy.mockResolvedValue(live)+ const apiError = Object.assign(new Error(`replace failed: ${code}`), { code })+ mockNetworkingApi.replaceNamespacedNetworkPolicy.mockRejectedValueOnce(apiError)++ await expect(apply(desired)).rejects.toMatchObject({+ name: 'NetworkPolicyInfraError',+ code,+ cause: apiError,+ })+ })++ it('propagates a permanent replace rejection without reclassifying it as transient', async () => {+ const desired = plainPolicy()+ const live = livePolicy(desired)+ live.spec!.podSelector = {}+ mockNetworkingApi.readNamespacedNetworkPolicy.mockResolvedValue(live)+ const permanent = { code: 422, reason: 'Invalid' }+ mockNetworkingApi.replaceNamespacedNetworkPolicy.mockRejectedValueOnce(permanent)++ await expect(apply(desired)).rejects.toBe(permanent)+ })++ it('propagates a permanent create rejection without attempting a replace', async () => {+ const desired = plainPolicy()+ const permanent = { code: 422, reason: 'Invalid' }+ mockNetworkingApi.readNamespacedNetworkPolicy.mockRejectedValueOnce({ code: 404 })+ mockNetworkingApi.createNamespacedNetworkPolicy.mockRejectedValueOnce(permanent)++ await expect(apply(desired)).rejects.toBe(permanent)+ expect(mockNetworkingApi.replaceNamespacedNetworkPolicy).not.toHaveBeenCalled()+ })++ it('propagates a permanent second-read rejection after the bounded retry', async () => {+ const desired = plainPolicy()+ const permanent = { code: 422, reason: 'Invalid' }+ mockNetworkingApi.readNamespacedNetworkPolicy+ .mockRejectedValueOnce({ code: 500 })+ .mockRejectedValueOnce(permanent)++ await expect(apply(desired)).rejects.toBe(permanent)+ expect(mockNetworkingApi.readNamespacedNetworkPolicy).toHaveBeenCalledTimes(2)+ expect(mockNetworkingApi.createNamespacedNetworkPolicy).not.toHaveBeenCalled()+ expect(mockNetworkingApi.replaceNamespacedNetworkPolicy).not.toHaveBeenCalled()+ })+it('refuses to create a gateway policy without a complete desired owner', async () => {const desired = gatewayPolicy('')@@ -1186,6 +1286,32 @@ describe('WorkflowRecipeReconciler', () => {expect(mockNetworkingApi.readNamespacedNetworkPolicy).not.toHaveBeenCalled()expect(mockNetworkingApi.createNamespacedNetworkPolicy).not.toHaveBeenCalled()})++ it('refuses a desired gateway policy with multiple controller owners before I/O', async () => {+ const desired = gatewayPolicy()+ desired.metadata!.ownerReferences!.push({+ apiVersion: 'apps/v1',+ kind: 'Deployment',+ name: 'second-controller',+ uid: 'second-controller-uid',+ controller: true,+ })++ await expect(apply(desired, 'webhook-gateway')).rejects.toMatchObject({+ name: 'NetworkPolicyOwnershipConflictError',+ })+ expect(mockNetworkingApi.readNamespacedNetworkPolicy).not.toHaveBeenCalled()+ expect(mockNetworkingApi.createNamespacedNetworkPolicy).not.toHaveBeenCalled()+ })++ it('refuses a desired policy without metadata.name before I/O', async () => {+ const desired = plainPolicy()+ delete desired.metadata!.name++ await expect(apply(desired)).rejects.toThrow(/without metadata\.name/)+ expect(mockNetworkingApi.readNamespacedNetworkPolicy).not.toHaveBeenCalled()+ expect(mockNetworkingApi.createNamespacedNetworkPolicy).not.toHaveBeenCalled()+ })})describe('idempotent apply (stops generation churn)', () => {