Skip to content

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

TypeScript

fix(hcc): count typed repairable orphans without managed-by

Alfredo Lopez26f4b74b09d2
diff --git a/scripts/ops/hcc-netpol-orphan-census.sh b/scripts/ops/hcc-netpol-orphan-census.sh
index 2e3b81632..b7de79a90 100755
--- a/scripts/ops/hcc-netpol-orphan-census.sh
+++ b/scripts/ops/hcc-netpol-orphan-census.sh
@@ -3,11 +3,12 @@
#
# get/list only — never create, patch, replace, or delete.
# Classifies by clerum.io/policy-type in {context-allow, rpc-proxy-egress,
-# external-egress}, plus the controller's `repairable` class: managed-by
-# present, policy-type absent, reserved name (ctx-/rpc-egress-/ext-egress-).
-# That last set is what a policy-type-strip corruption looks like; omitting
-# it can print VERDICT=CLEAN while the controller counts those objects and
-# may trip the cap. This is not the full four-lane classifier (reserved
+# external-egress} when managed-by is absent or host-context-controller
+# (#484: exclude only present-and-foreign), plus both controller
+# `repairable` one-marker arms: (1) managed-by present, policy-type absent,
+# reserved name; (2) policy-type present, managed-by absent. Omitting either
+# can print VERDICT=CLEAN while the controller still counts those objects
+# and may trip the cap. This is not the full four-lane classifier (reserved
# names without owner labels can over-count vs the controller).
#
# CONTEXT_MAPPER_* knobs are read from the live host-context-controller
@@ -35,8 +36,10 @@
# host-context-controller/src/networkPolicyReconciler.ts and the compiled
# defaults in host-context-controller/src/config.ts (absolute 10, percent
# 20, rpc-proxy namespace). If you change either side, change this script.
-# Typed membership requires clerum.io/managed-by=host-context-controller
-# so a foreign-owned typed policy cannot inflate listed/orphans (#484).
+# Typed membership excludes clerum.io/managed-by when it is present and
+# not host-context-controller so a foreign-owned typed policy cannot
+# inflate listed/orphans (#484). A typed policy with managed-by absent
+# stays eligible — that is the controller's other repairable arm.
#
# Double-samples 90s apart. Adjudicates only when the desired Context +
# McpServer identity set is identical across samples; otherwise
@@ -126,17 +129,19 @@ require_namespace "${MAPPER_NS}"
require_namespace "${HOST_NS}"
require_namespace "${RPC_NS}"
-# Typed policy-type membership, plus the reserved-name repairable class
-# (managed-by present, policy-type absent). Shared by listed + orphan filters.
+# Typed membership (type in set and managed-by null-or-HCC) plus the
+# reserved-name untyped repairable class (managed-by present, type absent).
+# Shared by listed + orphan filters.
CENSUS_MANAGED_JQ='
def policy_type: .metadata.labels["clerum.io/policy-type"];
+ def managed_by: .metadata.labels["clerum.io/managed-by"];
def is_typed:
- .metadata.labels["clerum.io/managed-by"] == "host-context-controller"
- and (
+ (
policy_type == "context-allow"
or policy_type == "rpc-proxy-egress"
or policy_type == "external-egress"
- );
+ )
+ and (managed_by == null or managed_by == "host-context-controller");
def is_untyped_repairable:
.metadata.labels["clerum.io/managed-by"] == "host-context-controller"
and (policy_type == null)
diff --git a/scripts/tests/test-hcc-netpol-orphan-census-verdicts.sh b/scripts/tests/test-hcc-netpol-orphan-census-verdicts.sh
index bc4fd58db..546451045 100755
--- a/scripts/tests/test-hcc-netpol-orphan-census-verdicts.sh
+++ b/scripts/tests/test-hcc-netpol-orphan-census-verdicts.sh
@@ -219,6 +219,39 @@ jq -n '
}
' >"${WORKDIR}/np-v5.json"
+# V7: member + typed reserved orphan without managed-by (controller
+# repairable arm: type present, managed-by absent, reserved + owner).
+# Pre-fix is_typed required managed-by and printed CLEAN (listed=1).
+jq -n '{
+ items: [
+ {
+ metadata: {
+ uid: "uid-member",
+ namespace: "mcp-server",
+ name: "ctx-alpha-allow",
+ labels: {
+ "clerum.io/managed-by": "host-context-controller",
+ "clerum.io/policy-type": "context-allow",
+ "clerum.io/context": "ctx-alpha",
+ "clerum.io/mcpserver": "srv-a"
+ }
+ }
+ },
+ {
+ metadata: {
+ uid: "uid-repairable-typed",
+ namespace: "mcp-server",
+ name: "ctx-gone-allow",
+ labels: {
+ "clerum.io/policy-type": "context-allow",
+ "clerum.io/context": "ctx-gone",
+ "clerum.io/mcpserver": "srv-gone"
+ }
+ }
+ }
+ ]
+}' >"${WORKDIR}/np-v7.json"
+
run_census() {
: >"$CASE_LOG"
rm -f "${WORKDIR}/call-count-contexts"
@@ -332,6 +365,24 @@ else
pass "SAMPLE_GAP_SEC is honored (no fixed 90s sleep)"
fi
+# V7
+run_census STUB_NP_MAPPER_FIXTURE="${WORKDIR}/np-v7.json"
+if [ "$RC" -ne 0 ]; then
+ fail "typed repairable without managed-by is counted — exit ${RC}; got: $(head -c 400 <<<"$OUT")"
+elif ! grep -Fq 'listed_managed=2' <<<"$OUT" ||
+ ! grep -Fq 'repairable_untyped=0' <<<"$OUT" ||
+ ! grep -Fq 'orphan_count=1' <<<"$OUT"; then
+ fail "typed repairable without managed-by is counted — counters mismatch; got: $(head -c 500 <<<"$OUT")"
+elif ! grep -Fq 'VERDICT=ORPHANS_PRESENT' <<<"$OUT"; then
+ fail "typed repairable without managed-by is counted — missing ORPHANS_PRESENT"
+elif grep -Fq 'VERDICT=CLEAN' <<<"$OUT"; then
+ fail "typed repairable without managed-by is counted — printed CLEAN"
+elif ! grep -Fq $'mcp-server\tctx-gone-allow\tcontext-allow' <<<"$OUT"; then
+ fail "typed repairable without managed-by is counted — TSV line missing; got: $(head -c 500 <<<"$OUT")"
+else
+ pass "typed reserved orphan without managed-by is listed and ORPHANS_PRESENT (RP-495-01)"
+fi
+
if grep -Eq '(^|[[:space:]])(set|delete|apply|patch|rollout|scale|create|replace|annotate|label|exec|drain|edit|expose)([[:space:]]|$)' "$ALL_LOG"; then
fail "census stayed read-only — mutating verb recorded"
else