Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(hcc): preserve default policy ownership
Alfredo Lopez206c25e7365a
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.jsonindex d3d8ef71e..441afbfd3 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.177",+ "version": "0.1.178","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-host-context-controller",- "version": "0.1.177",+ "version": "0.1.178","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 fdff33b31..2bbb79f5c 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.177",+ "version": "0.1.178","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/networkPolicyReconciler.test.ts b/host-context-controller/src/networkPolicyReconciler.test.tsindex 49f429bf2..aa08532fd 100644--- a/host-context-controller/src/networkPolicyReconciler.test.ts+++ b/host-context-controller/src/networkPolicyReconciler.test.ts@@ -507,6 +507,63 @@ describe('NetworkPolicyReconciler', () => {// ─── L1: Allow API ─────────────────────────────────────────────────describe('L1 — ensureAllowContextMapperApi', () => {+ it('updates the existing HCC-owned allow-api policy without requiring Context owner labels', async () => {+ mockApi.createNamespacedNetworkPolicy.mockImplementation(+ async ({ body }: { body: k8s.V1NetworkPolicy }) => {+ if (body.metadata?.name === 'allow-host-context-controller-api') {+ throw Object.assign(new Error('already exists'), { code: 409 })+ }+ return {}+ }+ )+ mockApi.readNamespacedNetworkPolicy.mockImplementation(async ({ name, namespace }) => ({+ metadata: {+ name,+ namespace,+ uid: 'existing-default-policy-uid',+ resourceVersion: '7',+ labels: {+ 'clerum.io/managed-by': 'host-context-controller',+ 'clerum.io/policy-type': 'allow-api',+ },+ },+ }))++ await expect(reconciler.ensureDefaultPolicies()).resolves.toBeUndefined()+ expect(mockApi.replaceNamespacedNetworkPolicy).toHaveBeenCalledWith(+ expect.objectContaining({+ name: 'allow-host-context-controller-api',+ namespace: 'mcp-server',+ })+ )+ })++ it('refuses to adopt a foreign policy that collides with the allow-api policy name', async () => {+ mockApi.createNamespacedNetworkPolicy.mockImplementation(+ async ({ body }: { body: k8s.V1NetworkPolicy }) => {+ if (body.metadata?.name === 'allow-host-context-controller-api') {+ throw Object.assign(new Error('already exists'), { code: 409 })+ }+ return {}+ }+ )+ mockApi.readNamespacedNetworkPolicy.mockResolvedValue({+ metadata: {+ name: 'allow-host-context-controller-api',+ namespace: 'mcp-server',+ uid: 'foreign-default-policy-uid',+ resourceVersion: '7',+ labels: {+ 'clerum.io/managed-by': 'foreign-controller',+ 'clerum.io/policy-type': 'allow-api',+ },+ },+ })++ await expect(reconciler.ensureDefaultPolicies()).rejects.toThrow(/ownership/i)+ expect(mockApi.replaceNamespacedNetworkPolicy).not.toHaveBeenCalled()+ })+it('creates allow-api ingress policy using _from (K8s client convention)', async () => {await reconciler.ensureDefaultPolicies()diff --git a/host-context-controller/src/networkPolicyReconciler.ts b/host-context-controller/src/networkPolicyReconciler.tsindex b199502cd..f3086d3c8 100644--- a/host-context-controller/src/networkPolicyReconciler.ts+++ b/host-context-controller/src/networkPolicyReconciler.ts@@ -610,7 +610,21 @@ export class NetworkPolicyReconciler {},}- await this.applyPolicy(name, policy)+ await applyNetworkPolicy(+ this.networkingApi,+ name,+ config.namespace,+ policy,+ '[NetPol]',+ undefined,+ existing => {+ if (!hasExpectedPolicyOwnership(existing, 'allow-api')) {+ throw new Error(+ `NetworkPolicy "${name}" has conflicting ownership for the allow-api lane`+ )+ }+ }+ )}// ─── Context-Based Policies ──────────────────────────────────────────@@ -783,7 +797,7 @@ export class NetworkPolicyReconciler {const desired = this.buildContextAllowPolicies(context, server)const ingressName = desired.ingress.metadata!.name!- await this.applyPolicy(ingressName, desired.ingress, isCurrent)+ await this.applyContextIngressPolicy(ingressName, desired.ingress, isCurrent)if (!isCurrent()) returnconst hostEgressName = desired.hostEgress.metadata!.name!@@ -2277,7 +2291,7 @@ export class NetworkPolicyReconciler {}/** Create or update a NetworkPolicy. */- private async applyPolicy(+ private async applyContextIngressPolicy(name: string,policy: k8s.V1NetworkPolicy,isCurrent?: () => booleandiff --git a/scripts/tests/test-hcc-api-gateway-readiness.sh b/scripts/tests/test-hcc-api-gateway-readiness.shold mode 100644new mode 100755