Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(egress): address zach88 round-2 review findings for #299
Alfredo Lopezfeaa579e8d9d
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.jsonindex 2c0eaeb04..770f7c707 100644--- a/host-context-controller/package-lock.json+++ b/host-context-controller/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-host-context-controller",- "version": "0.1.168",+ "version": "0.1.169","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-host-context-controller",- "version": "0.1.168",+ "version": "0.1.169","license": "SEE LICENSE IN LICENSE","dependencies": {"@clerum/image-policy": "file:../packages/image-policy",diff --git a/host-context-controller/package.json b/host-context-controller/package.jsonindex 5ed40074a..04b826ebf 100644--- a/host-context-controller/package.json+++ b/host-context-controller/package.json@@ -1,6 +1,6 @@{"name": "clerum-host-context-controller",- "version": "0.1.168",+ "version": "0.1.169","description": "Host Context Controller - provides McpServer CRDs to mcp-host via REST API","main": "dist/main.js","engines": {diff --git a/host-context-controller/src/config.externalEgressResync.test.ts b/host-context-controller/src/config.externalEgressResync.test.tsindex a0ed234ce..ecefa3a3c 100644--- a/host-context-controller/src/config.externalEgressResync.test.ts+++ b/host-context-controller/src/config.externalEgressResync.test.ts@@ -23,10 +23,11 @@ afterEach(() => {})describe('external egress sliding-window config (issue #299)', () => {- it('applies plan defaults: interval below overlap, floor 5, cap 128', async () => {+ it('applies plan defaults: interval <= overlap/2, floor 5, cap 128', async () => {const { config } = await loadConfig({})- // Default resync MUST sit below the overlap so entries never expire between- // refreshes (the #299 gap). It is lowered from the legacy 300 to 60.+ // Default resync MUST sit at or below half the overlap so entries never+ // expire between refreshes (the #299 gap). It is lowered from the legacy+ // 300 to 60.expect(config.externalEgressResyncIntervalSec).toBe(60)expect(config.externalEgressOverlapSec).toBe(300)expect(config.externalEgressRefreshFloorSec).toBe(5)diff --git a/packages/network-policy-core/index.cjs b/packages/network-policy-core/index.cjsindex 0244b87ce..a4b8f20bb 100644--- a/packages/network-policy-core/index.cjs+++ b/packages/network-policy-core/index.cjs@@ -231,10 +231,15 @@ function reconcileEgressState(previous, observations, now, config) {// Per-entry contribution to BOTH annotations (R1-M1): the STATE array element// and the TARGETS `fqdn=ip/32` fragment. serializeState (below) is the source// of truth for both shapes.+ // Charge UTF-8 BYTES, not UTF-16 code units: the apiserver caps total+ // annotation size by Go len() (bytes), and MAX_ANNOTATION_BYTES is a byte+ // budget. A multi-byte FQDN (e.g. 'ü' = 1 code unit, 2 bytes) would make a+ // .length meter under-count and clear a policy the apiserver then 422s.const sizeOf = new Map(entries.map(e => [e,- JSON.stringify(stateEntryView(e)).length + `${e.fqdn}=${e.ip}/32`.length,+ Buffer.byteLength(JSON.stringify(stateEntryView(e)), 'utf8') ++ Buffer.byteLength(`${e.fqdn}=${e.ip}/32`, 'utf8'),]))const byNewest = [...entries].sort(diff --git a/packages/network-policy-core/index.test.cjs b/packages/network-policy-core/index.test.cjsindex 0ddc14cdd..0dea8e1f3 100644--- a/packages/network-policy-core/index.test.cjs+++ b/packages/network-policy-core/index.test.cjs@@ -429,9 +429,34 @@ test('R1-M1 byte cap: STATE + TARGETS together never exceed the 256KB apiserverconst ips = Array.from({ length: 900 }, (_, i) => `10.${Math.floor(i / 256)}.${i % 256}.1`)const out = core.reconcileEgressState(core.emptyState(), [obsOk(longFqdn, ips, TTL, 443)], 1000, bigCfg)const ann = core.serializeState(out.state)- const total = ann[core.STATE_ANNOTATION].length + ann[core.TARGETS_ANNOTATION].length+ // The apiserver caps total annotation size by UTF-8 BYTES (Go len()), so the+ // budget and this assertion must both measure bytes, never UTF-16 .length.+ const total =+ Buffer.byteLength(ann[core.STATE_ANNOTATION], 'utf8') ++ Buffer.byteLength(ann[core.TARGETS_ANNOTATION], 'utf8')assert.ok(total <= 262144, `STATE+TARGETS = ${total} bytes, must be <= 262144 (256KB)`)assert.ok(out.entries.length > 0, 'not everything was evicted')assert.ok(out.entries.length < 900, 'byte-budget eviction dropped the overflow')assert.equal(out.overCap, true, 'overCap flags the eviction for the alarm/metric')})++// R2-M1 (zach88 round-2): the byte budget must charge UTF-8 bytes, not UTF-16+// code units. A multi-byte FQDN ('ü' = 1 code unit but 2 UTF-8 bytes) makes a+// .length-based meter under-count, so serializeState can emit an annotation that+// clears the flawed budget yet exceeds the apiserver's real 256KB byte cap —+// the exact 422 reconcile loop the guard exists to prevent. Fails red on a+// .length meter; green once sizeOf measures Buffer.byteLength(...,'utf8').+test('R2-M1 byte cap: multi-byte FQDN is bounded by UTF-8 bytes, not UTF-16 length', () => {+ const longFqdn = `${'ü'.repeat(120)}.example.com` // .length ~132, utf8 ~252 bytes+ const bigCfg = { overlapMs: 300_000, maxEntries: 4096 } // count cap won't bite first+ const ips = Array.from({ length: 900 }, (_, i) => `10.${Math.floor(i / 256)}.${i % 256}.1`)+ const out = core.reconcileEgressState(core.emptyState(), [obsOk(longFqdn, ips, TTL, 443)], 1000, bigCfg)+ const ann = core.serializeState(out.state)+ const total =+ Buffer.byteLength(ann[core.STATE_ANNOTATION], 'utf8') ++ Buffer.byteLength(ann[core.TARGETS_ANNOTATION], 'utf8')+ assert.ok(total <= 262144, `STATE+TARGETS = ${total} utf8 bytes, must be <= 262144 (256KB)`)+ assert.ok(out.entries.length > 0, 'not everything was evicted')+ assert.ok(out.entries.length < 900, 'byte-budget eviction dropped the overflow')+ assert.equal(out.overCap, true, 'overCap flags the eviction for the alarm/metric')+})diff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.jsonindex f49b92a4b..6bbe6e013 100644--- a/workflow-recipes/package-lock.json+++ b/workflow-recipes/package-lock.json@@ -1,12 +1,12 @@{"name": "workload-recipes-controller",- "version": "0.1.285",+ "version": "0.1.286","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "workload-recipes-controller",- "version": "0.1.285",+ "version": "0.1.286","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 69f955e5e..67b8d7c50 100644--- a/workflow-recipes/package.json+++ b/workflow-recipes/package.json@@ -1,6 +1,6 @@{"name": "workload-recipes-controller",- "version": "0.1.285",+ "version": "0.1.286","description": "Workload Recipes Controller (WRC) - WorkloadRecipe lifecycle management and MCP server interface","main": "dist/main.js","engines": {diff --git a/workflow-recipes/src/reconciler/reconciler.test.ts b/workflow-recipes/src/reconciler/reconciler.test.tsindex 6fa9a31ab..a8a8c3dfa 100644--- a/workflow-recipes/src/reconciler/reconciler.test.ts+++ b/workflow-recipes/src/reconciler/reconciler.test.ts@@ -3946,9 +3946,13 @@ describe('WorkflowRecipeReconciler', () => {})// R1-M3 (zach88): the no-op gate must hold when the LIVE policy is apiserver-- // shaped — keys reordered ({ports,to} not {to,ports}) and protocol defaulted to- // TCP — which is exactly what the canonicalize/egressSignature fix motivates but- // R.8.24 (which feeds the builder's own output back) never exercised.+ // shaped — each rule's keys reordered ({ports,to} not {to,ports}) and each+ // port's keys reordered ({protocol,port} not {port,protocol}) — which is+ // exactly what the canonicalize/egressSignature fix motivates but R.8.24+ // (which feeds the builder's own output back verbatim) never exercised. The+ // builder already emits protocol:'TCP' on every port, so this exercises key+ // ORDER only; egressSignature deliberately treats an absent protocol as+ // distinct from 'TCP', a shape that cannot arise for builder-written policies.it('R1-M3: external egress is a no-op against an apiserver-normalized live policy', async () => {const kc = new k8s.KubeConfig()const rec = new WorkflowRecipeReconciler(kc, undefined, {@@ -3970,12 +3974,14 @@ describe('WorkflowRecipeReconciler', () => {.find(b => b?.metadata?.name === 'ui-egress-test-recipe')expect(p1).toBeTruthy()- // Reshape p1 the way the apiserver returns it: reorder each rule's keys and- // inject protocol:'TCP' on ports. The state annotation is preserved.+ // Reshape p1 the way the apiserver returns it: reorder each rule's keys+ // ({ports,to}) and each port's keys ({protocol,port}). The builder already+ // set protocol:'TCP', so this preserves the value and only changes key+ // order. The state annotation is preserved.const live = JSON.parse(JSON.stringify(p1))live.spec.egress = (live.spec.egress ?? []).map((rule: Record<string, unknown>) => ({ports: ((rule.ports as Array<Record<string, unknown>>) ?? []).map(pt => ({- protocol: pt.protocol ?? 'TCP',+ protocol: pt.protocol,port: pt.port,})),to: (rule.to as Array<Record<string, unknown>>) ?? [],