Skip to content

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.json
index 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.json
index 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.ts
index 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.ts
index 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()) return
const 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?: () => boolean
diff --git a/scripts/tests/test-hcc-api-gateway-readiness.sh b/scripts/tests/test-hcc-api-gateway-readiness.sh
old mode 100644
new mode 100755