Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(reconciler): fail closed when the inventory-authority fence is unconfigured [R4-G1]
Alfredo Lopez1091f543bbd9
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.jsonindex a79b69a2f..489633e33 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.214",+ "version": "0.1.215","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-host-context-controller",- "version": "0.1.214",+ "version": "0.1.215","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 41a7b6711..cefe713c5 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.214",+ "version": "0.1.215","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/__tests__/reconciler.credentialsRotation.test.ts b/host-context-controller/src/__tests__/reconciler.credentialsRotation.test.tsindex d7c268fd1..f4e15bf35 100644--- a/host-context-controller/src/__tests__/reconciler.credentialsRotation.test.ts+++ b/host-context-controller/src/__tests__/reconciler.credentialsRotation.test.ts@@ -119,6 +119,7 @@ describe('connector credentials revision (issue #223)', () => {data: { 'api-key': stored('old-key') },})reconciler = new McpServerReconciler({} as k8s.KubeConfig, {+ assumeInventoryAuthorityWhenUnconfigured: true,appsApi: asAppsApi(appsApi),coreApi: asCoreApi(coreApi),customApi: asCustomApi(customApi),@@ -220,6 +221,7 @@ describe('generation-aware rollout readiness (issue #223)', () => {vi.clearAllMocks()coreApi.readNamespacedSecret.mockResolvedValue({ data: { 'api-key': stored('old-key') } })reconciler = new McpServerReconciler({} as k8s.KubeConfig, {+ assumeInventoryAuthorityWhenUnconfigured: true,appsApi: asAppsApi(appsApi),coreApi: asCoreApi(coreApi),customApi: asCustomApi(customApi),@@ -322,6 +324,7 @@ describe('the readiness poll must publish its verdict on the CRD (issue #223)',vi.useFakeTimers()coreApi.readNamespacedSecret.mockResolvedValue({ data: { 'api-key': stored('old-key') } })reconciler = new McpServerReconciler({} as k8s.KubeConfig, {+ assumeInventoryAuthorityWhenUnconfigured: true,appsApi: asAppsApi(appsApi),coreApi: asCoreApi(coreApi),customApi: asCustomApi(customApi),@@ -580,6 +583,7 @@ describe('poll-window fence survives a superseding reconcile (F1, watch-recoverycurrentServer = makeServer()coreApi.readNamespacedSecret.mockResolvedValue({ data: { 'api-key': stored('old-key') } })reconciler = new McpServerReconciler({} as k8s.KubeConfig, {+ assumeInventoryAuthorityWhenUnconfigured: true,appsApi: asAppsApi(appsApi),coreApi: asCoreApi(coreApi),customApi: asCustomApi(customApi),diff --git a/host-context-controller/src/__tests__/reconciler.pod-hardening.test.ts b/host-context-controller/src/__tests__/reconciler.pod-hardening.test.tsindex a4b425ae7..fa30ec7a5 100644--- a/host-context-controller/src/__tests__/reconciler.pod-hardening.test.ts+++ b/host-context-controller/src/__tests__/reconciler.pod-hardening.test.ts@@ -89,6 +89,7 @@ describe('McpServer generated pod hardening', () => {beforeEach(() => {vi.clearAllMocks()reconciler = new McpServerReconciler({} as k8s.KubeConfig, {+ assumeInventoryAuthorityWhenUnconfigured: true,appsApi: asAppsApi(appsApi),coreApi: asCoreApi(coreApi),customApi: asCustomApi(customApi),diff --git a/host-context-controller/src/__tests__/reconciler.remote.test.ts b/host-context-controller/src/__tests__/reconciler.remote.test.tsindex a82539737..044452efd 100644--- a/host-context-controller/src/__tests__/reconciler.remote.test.ts+++ b/host-context-controller/src/__tests__/reconciler.remote.test.ts@@ -87,6 +87,7 @@ function buildReconciler(customApi: MockCustomApi): McpServerReconciler {return new McpServerReconciler({} as k8s.KubeConfig, {+ assumeInventoryAuthorityWhenUnconfigured: true,appsApi: asAppsApi(appsApi),coreApi: asCoreApi(coreApi),customApi: asCustomApi(customApi),diff --git a/host-context-controller/src/__tests__/reconciler.sanitize.test.ts b/host-context-controller/src/__tests__/reconciler.sanitize.test.tsindex 0ef68a1c8..38b7c571f 100644--- a/host-context-controller/src/__tests__/reconciler.sanitize.test.ts+++ b/host-context-controller/src/__tests__/reconciler.sanitize.test.ts@@ -91,6 +91,7 @@ describe('CRD Field Injection Prevention (sanitizeCrdSpec)', () => {beforeEach(() => {vi.clearAllMocks()reconciler = new McpServerReconciler({} as k8s.KubeConfig, {+ assumeInventoryAuthorityWhenUnconfigured: true,appsApi: asAppsApi(appsApi),coreApi: asCoreApi(coreApi),customApi: asCustomApi(customApi),diff --git a/host-context-controller/src/reconciler.test.ts b/host-context-controller/src/reconciler.test.tsindex 095983845..26a7f5ab0 100644--- a/host-context-controller/src/reconciler.test.ts+++ b/host-context-controller/src/reconciler.test.ts@@ -1,4 +1,4 @@-import { beforeEach, describe, expect, it, vi } from 'vitest'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import * as k8s from '@kubernetes/client-node'import {asAppsApi,@@ -76,6 +76,7 @@ describe('Reconciler managed:false guard (Risk 1.7)', () => {beforeEach(() => {vi.clearAllMocks()reconciler = new McpServerReconciler({} as k8s.KubeConfig, {+ assumeInventoryAuthorityWhenUnconfigured: true,appsApi: asAppsApi(appsApi),coreApi: asCoreApi(coreApi),customApi: asCustomApi(customApi),@@ -284,6 +285,7 @@ describe('PR-B B1 — validateSecret result shape', () => {beforeEach(() => {vi.clearAllMocks()reconciler = new McpServerReconciler({} as k8s.KubeConfig, {+ assumeInventoryAuthorityWhenUnconfigured: true,appsApi: asAppsApi(appsApi),coreApi: asCoreApi(coreApi),customApi: asCustomApi(customApi),@@ -481,6 +483,7 @@ describe('PR-B B1 — writeStatusCondition', () => {beforeEach(() => {vi.clearAllMocks()reconciler = new McpServerReconciler({} as k8s.KubeConfig, {+ assumeInventoryAuthorityWhenUnconfigured: true,appsApi: asAppsApi(appsApi),coreApi: asCoreApi(coreApi),customApi: asCustomApi(customApi),@@ -938,6 +941,7 @@ describe('restart-safe discovery status', () => {beforeEach(() => {vi.clearAllMocks()reconciler = new McpServerReconciler({} as k8s.KubeConfig, {+ assumeInventoryAuthorityWhenUnconfigured: true,appsApi: asAppsApi(appsApi),coreApi: asCoreApi(coreApi),customApi: asCustomApi(customApi),@@ -1101,6 +1105,7 @@ describe('ownership-safe fail-closed cleanup', () => {beforeEach(() => {vi.clearAllMocks()reconciler = new McpServerReconciler({} as k8s.KubeConfig, {+ assumeInventoryAuthorityWhenUnconfigured: true,appsApi: asAppsApi(appsApi),coreApi: asCoreApi(coreApi),customApi: asCustomApi(customApi),@@ -1215,6 +1220,7 @@ describe('full reconciliation inventory authority', () => {Object.assign(new Error('not found'), { code: 404 }))reconciler = new McpServerReconciler({} as k8s.KubeConfig, {+ assumeInventoryAuthorityWhenUnconfigured: true,appsApi: asAppsApi(appsApi),coreApi: asCoreApi(coreApi),customApi: asCustomApi(customApi),@@ -1685,6 +1691,7 @@ describe('updateStatusConditions', () => {beforeEach(() => {vi.clearAllMocks()reconciler = new McpServerReconciler({} as k8s.KubeConfig, {+ assumeInventoryAuthorityWhenUnconfigured: true,appsApi: asAppsApi(appsApi),coreApi: asCoreApi(coreApi),customApi: asCustomApi(customApi),@@ -1747,3 +1754,53 @@ describe('updateStatusConditions', () => {expect(types).toContain('DeploymentReady')})})++describe('unconfigured inventory authority fails closed (G1)', () => {+ const appsApi = createMockAppsApi()+ const coreApi = createMockCoreApi()+ const customApi = createMockCustomApi()+ let errorSpy: ReturnType<typeof vi.spyOn>++ // Deliberately NO assumeInventoryAuthorityWhenUnconfigured and NO+ // setInventoryAuthority/setResolveCurrentServer wiring: the fence must deny.+ function makeUnwiredReconciler(): McpServerReconciler {+ return new McpServerReconciler({} as k8s.KubeConfig, {+ appsApi: asAppsApi(appsApi),+ coreApi: asCoreApi(coreApi),+ customApi: asCustomApi(customApi),+ })+ }++ beforeEach(() => {+ vi.clearAllMocks()+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})+ })++ afterEach(() => {+ errorSpy.mockRestore()+ })++ it('T-G1a: reconcile() denies (no Deployment) and warns once when authority is unwired', async () => {+ const reconciler = makeUnwiredReconciler()+ await reconciler.reconcile(makeServer({ name: 'g1-mcp', managed: true }))+ expect(appsApi.createNamespacedDeployment).not.toHaveBeenCalled()+ expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining('fail closed'))+ })++ it('T-G1b: fullReconcile() denies when authority is unwired', async () => {+ const reconciler = makeUnwiredReconciler()+ await reconciler.fullReconcile([makeServer({ name: 'g1-mcp', managed: true })])+ expect(appsApi.createNamespacedDeployment).not.toHaveBeenCalled()+ })++ it('T-G1c: the explicit opt-in restores assume-current', async () => {+ const reconciler = new McpServerReconciler({} as k8s.KubeConfig, {+ appsApi: asAppsApi(appsApi),+ coreApi: asCoreApi(coreApi),+ customApi: asCustomApi(customApi),+ assumeInventoryAuthorityWhenUnconfigured: true,+ })+ await reconciler.reconcile(makeServer({ name: 'g1-mcp', managed: true }))+ expect(appsApi.createNamespacedDeployment).toHaveBeenCalled()+ })+})diff --git a/host-context-controller/src/reconciler.ts b/host-context-controller/src/reconciler.tsindex 96b47fbfe..4056c621c 100644--- a/host-context-controller/src/reconciler.ts+++ b/host-context-controller/src/reconciler.ts@@ -74,6 +74,14 @@ type McpServerReconcilerDeps = {coreApi?: k8s.CoreV1ApicustomApi?: k8s.CustomObjectsApinetworkingApi?: k8s.NetworkingV1Api+ /**+ * TEST-ONLY escape hatch. When the inventory-authority fence is not wired+ * (setInventoryAuthority / setResolveCurrentServer never called), mutation+ * fences fail CLOSED by default. Unit tests that exercise the reconciler+ * without a watcher opt in to the legacy assume-current behavior here.+ * Production construction (k8sClient) must never set this.+ */+ assumeInventoryAuthorityWhenUnconfigured?: boolean}export type McpServerInventoryAuthoritySnapshot = {@@ -251,6 +259,10 @@ export class McpServerReconciler {})private inventoryAuthorityConfigured = falseprivate resolveCurrentServer?: (name: string) => McpServerCRD | undefined+ /** See McpServerReconcilerDeps: test-only opt-in to assume-current when the+ * inventory-authority fence is unwired. Production leaves it false. */+ private readonly assumeInventoryAuthorityWhenUnconfigured: boolean+ private warnedUnconfiguredAuthority = false/** Tracks the deployment status of each managed McpServer. */private readonly statusMap: Map<string, McpServerStatus> = new Map()@@ -290,6 +302,8 @@ export class McpServerReconciler {this.networkingApi =deps?.networkingApi ??(typeof kc.makeApiClient === 'function' ? kc.makeApiClient(k8s.NetworkingV1Api) : undefined)+ this.assumeInventoryAuthorityWhenUnconfigured =+ deps?.assumeInventoryAuthorityWhenUnconfigured ?? false}/**@@ -312,6 +326,24 @@ export class McpServerReconciler {this.resolveCurrentServer = fn}+ /**+ * Verdict for a mutation fence evaluated while the inventory authority is NOT+ * wired. Fail closed (deny) unless a test explicitly opted in; deny loudly+ * once, because an unconfigured fence in a running controller is a+ * construction bug, never a runtime condition.+ */+ private currentWhenUnconfigured(): boolean {+ if (this.assumeInventoryAuthorityWhenUnconfigured) return true+ if (!this.warnedUnconfiguredAuthority) {+ this.warnedUnconfiguredAuthority = true+ console.error(+ '[Reconciler] inventory authority not configured — mutation fences fail closed. ' ++ 'Wire setInventoryAuthority() and setResolveCurrentServer() before reconciling.'+ )+ }+ return false+ }+// ─── Status ────────────────────────────────────────────────────────/**@@ -2042,7 +2074,7 @@ ${authHeaderLines ? '\n # ── Credential auth headers (envsubst-resolvconst callerIsCurrent = options.isCurrent ?? (() => true)const isCurrent = () => {if (!callerIsCurrent()) return false- if (!this.inventoryAuthorityConfigured) return true+ if (!this.inventoryAuthorityConfigured) return this.currentWhenUnconfigured()if (!this.authorityMatches(capturedAuthority)) return falseconst current = this.resolveCurrentServer?.(server.name)return current !== undefined && sameMcpServerDesiredRevision(server, current)@@ -2481,13 +2513,15 @@ ${authHeaderLines ? '\n # ── Credential auth headers (envsubst-resolv// ahead of that safety policy.if (!current || !sameMcpServerDesiredRevision(server, current)) returnconst isCurrent = () => {- if (this.inventoryAuthorityConfigured && !this.authorityMatches(capturedAuthority)) {+ if (!this.inventoryAuthorityConfigured) {+ if (!this.currentWhenUnconfigured()) return false+ } else if (!this.authorityMatches(capturedAuthority)) {return false}const latest = this.resolveCurrentServer?.(current.name)return latest? sameMcpServerDesiredRevision(current, latest)- : this.resolveCurrentServer === undefined+ : this.resolveCurrentServer === undefined && this.currentWhenUnconfigured()}await this.reconcile(current, { isCurrent })})