Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(egress): only a positive DNS verdict may reach the sliding-window classifier
Alfredo Lopez104f3e83aeb0
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.jsonindex e09d87ca2..c76d3e955 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.284",+ "version": "0.1.285","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-host-context-controller",- "version": "0.1.284",+ "version": "0.1.285","license": "SEE LICENSE IN LICENSE","dependencies": {"@clerum/codex-catalog-projection": "file:../packages/codex-catalog-projection",diff --git a/host-context-controller/package.json b/host-context-controller/package.jsonindex a0eb362b8..31e93dd0b 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.284",+ "version": "0.1.285","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.egressClassification.test.ts b/host-context-controller/src/networkPolicyReconciler.egressClassification.test.tsnew file mode 100644index 000000000..acf547644--- /dev/null+++ b/host-context-controller/src/networkPolicyReconciler.egressClassification.test.ts@@ -0,0 +1,294 @@+// Issue #513: the external-egress catch classifies EVERY exception as a DNS+// condition. classifyDnsError keys on `.code` and defaults anything unknown or+// codeless to 'permanent' (network-policy-core/index.cjs:83), and 'permanent'+// PRUNES the accumulated window instead of freezing it. So a programming fault+// raised anywhere inside the ~60-line try — a TypeError from a contract+// violation, an ERR_* argument error — is laundered into the prune branch and+// reported to the operator as `permanent DNS failure for "<host>"`, pointing at+// DNS while the actual fault is in the reconciler.+//+// The injection here is deliberately production-shaped rather than a test hook:+// the resolver returns one valid record and one non-object, so `records.map(r =>+// r.address)` throws a real TypeError INSIDE the try, AFTER resolution. That is+// the contract violation the catch cannot tell apart from a DNS answer.+//+// T3 is the semantics guard: a genuine NXDOMAIN must keep pruning and failing+// loud exactly as before. Without it, "stop classifying" could be satisfied by+// simply never pruning, which would break the permanent branch the platform+// depends on.+import { type Mock, beforeEach, describe, expect, it, vi } from 'vitest'+import * as k8s from '@kubernetes/client-node'+import type { RecordWithTtl } from 'node:dns'+import * as dns from 'node:dns/promises'+import { NetworkPolicyReconciler } from './networkPolicyReconciler'+import { McpServerCRD } from './types'++vi.mock('./mcpServerSafety', async () => {+ const actual = await vi.importActual<typeof import('./mcpServerSafety')>('./mcpServerSafety')+ return {+ ...actual,+ confirmAuthoritativeMcpServerAbsence: vi.fn(actual.confirmAuthoritativeMcpServerAbsence),+ }+})++const rec = (...ips: string[]): RecordWithTtl[] => ips.map(address => ({ address, ttl: 300 }))+const resolve4Mock = vi.mocked(dns.resolve4) as unknown as Mock++vi.mock('./config', () => ({+ config: {+ namespace: 'mcp-server',+ controlPlaneNamespace: 'control-plane',+ hostNamespace: 'mcp-host',+ rpcProxyNamespace: 'rpc-proxy',+ port: 8081,+ runtimeNamespaces: ['mcp-server', 'mcp-host', 'sandbox-recipes', 'rpc-proxy'],+ k8sApiCidrs: [],+ externalEgressDnsResolveTimeoutMs: 5_000,+ externalEgressOverlapSec: 300,+ externalEgressMaxEntries: 128,+ },+}))++vi.mock('node:dns/promises', () => ({+ resolve4: vi.fn().mockResolvedValue([{ address: '1.2.3.4', ttl: 300 }]),+}))++vi.mock('./metrics', () => ({+ networkPolicySafetyPassDurationSeconds: { observe: vi.fn() },+ networkPolicySafetyPassPoliciesTotal: { inc: vi.fn() },+ writesTotal: { inc: vi.fn() },+ writeSkipsTotal: { inc: vi.fn() },+}))++function makeMockNetworkingApi() {+ return {+ createNamespacedNetworkPolicy: vi.fn().mockResolvedValue({}),+ readNamespacedNetworkPolicy: vi.fn().mockResolvedValue({ metadata: { resourceVersion: '1' } }),+ replaceNamespacedNetworkPolicy: vi.fn().mockResolvedValue({}),+ listNamespacedNetworkPolicy: vi.fn().mockResolvedValue({ items: [] }),+ deleteNamespacedNetworkPolicy: vi.fn().mockResolvedValue({}),+ }+}++function makeMockCustomApi() {+ return {+ getNamespacedCustomObject: vi+ .fn()+ .mockRejectedValue(Object.assign(new Error('not found'), { code: 404 })),+ listNamespacedCustomObject: vi.fn().mockResolvedValue({ items: [] }),+ getNamespacedCustomObjectStatus: vi.fn().mockResolvedValue({+ metadata: { generation: 7, resourceVersion: 'status-rv-default' },+ status: {},+ }),+ patchNamespacedCustomObjectStatus: vi.fn().mockResolvedValue({}),+ }+}++function makeReconciler(+ mockApi: ReturnType<typeof makeMockNetworkingApi>,+ mockCustomApi: ReturnType<typeof makeMockCustomApi>+): NetworkPolicyReconciler {+ const kc = new k8s.KubeConfig()+ kc.loadFromOptions({+ clusters: [{ name: 'test', server: 'https://test' }],+ users: [{ name: 'test' }],+ contexts: [{ name: 'test', cluster: 'test', user: 'test' }],+ currentContext: 'test',+ })+ const reconciler = new NetworkPolicyReconciler(kc, new Map())+ const networkingApi = {+ ...mockApi,+ listNamespacedNetworkPolicy: async (args: { namespace: string }) => {+ const response = await mockApi.listNamespacedNetworkPolicy(args)+ const items = (response.items ?? []).map((policy: k8s.V1NetworkPolicy, index: number) => {+ const name = policy.metadata?.name ?? `unnamed-${index}`+ return {+ ...policy,+ metadata: {+ ...policy.metadata,+ name,+ namespace: policy.metadata?.namespace ?? args.namespace,+ uid: policy.metadata?.uid ?? `${args.namespace}:${name}:uid`,+ resourceVersion: policy.metadata?.resourceVersion ?? '1',+ },+ }+ })+ return { ...response, items }+ },+ }+ ;(reconciler as unknown as { networkingApi: unknown }).networkingApi = networkingApi+ ;(reconciler as unknown as { customApi: unknown }).customApi = mockCustomApi+ return reconciler+}++const server: McpServerCRD = {+ name: 'classify-mcp',+ namespace: 'mcp-server',+ spec: {+ contextRef: 'dev',+ image: 'classify:latest',+ transport: { type: 'streamableHttp', url: 'http://classify:3000', port: 3000 },+ egressBindings: [{ dns: 'api.example.com', port: 443 }],+ },+}++describe('#513: a non-DNS exception inside the resolve block is not a DNS condition', () => {+ let mockApi: ReturnType<typeof makeMockNetworkingApi>+ let mockCustomApi: ReturnType<typeof makeMockCustomApi>+ let reconciler: NetworkPolicyReconciler++ beforeEach(() => {+ vi.useRealTimers()+ mockApi = makeMockNetworkingApi()+ mockCustomApi = makeMockCustomApi()+ reconciler = makeReconciler(mockApi, mockCustomApi)+ vi.clearAllMocks()+ resolve4Mock.mockResolvedValue(rec('1.2.3.4'))+ })++ /** Bootstrap a written policy, then re-serve it with the window optionally lapsed. */+ async function seedAccumulatedPolicy(opts: { lapsed: boolean }): Promise<void> {+ await reconciler.reconcileExternalEgress(server, { isCurrent: () => true })+ const written = (+ mockApi.createNamespacedNetworkPolicy.mock.calls[0][0] as { body: k8s.V1NetworkPolicy }+ ).body+ const annotations = { ...(written.metadata?.annotations ?? {}) }+ expect(annotations['clerum.io/egress-fqdn-state']).toBeTruthy()++ if (opts.lapsed) {+ const state = JSON.parse(annotations['clerum.io/egress-fqdn-state']) as Array<{+ expiresAt: number+ }>+ for (const e of state) e.expiresAt = Date.now() - 60_000+ annotations['clerum.io/egress-fqdn-state'] = JSON.stringify(state)+ }++ mockApi.listNamespacedNetworkPolicy.mockResolvedValue({+ items: [+ {+ metadata: {+ name: written.metadata?.name,+ labels: written.metadata?.labels,+ annotations,+ },+ spec: written.spec,+ },+ ],+ })+ mockApi.createNamespacedNetworkPolicy.mockClear()+ mockApi.replaceNamespacedNetworkPolicy.mockClear()+ mockApi.deleteNamespacedNetworkPolicy.mockClear()+ mockCustomApi.patchNamespacedCustomObjectStatus.mockClear()+ }++ /** A resolver answer whose second record is not an object: records.map() throws. */+ function injectPostResolutionTypeError(): void {+ resolve4Mock.mockResolvedValueOnce([+ { address: '1.2.3.4', ttl: 300 },+ null as unknown as RecordWithTtl,+ ])+ }++ type Condition = { type?: string; status?: string; reason?: string; message?: string }++ /**+ * The status write is a JSON Patch array, not a status object: conditions+ * arrive either as `/status/conditions` (status object already present) or+ * nested inside a whole-`/status` add (bootstrap). Read both shapes.+ */+ function statusConditions(): Condition[] {+ type Op = { op?: string; path?: string; value?: unknown }+ return mockCustomApi.patchNamespacedCustomObjectStatus.mock.calls.flatMap(+ (call: [{ body?: Op[] }]) =>+ (call[0]?.body ?? []).flatMap((op): Condition[] => {+ if (op.path === '/status/conditions') return (op.value ?? []) as Condition[]+ if (op.path === '/status') {+ return (((op.value ?? {}) as { conditions?: Condition[] }).conditions ??+ []) as Condition[]+ }+ return []+ })+ )+ }++ it('T1 reports a post-resolution TypeError as a reconcile error, not as a permanent DNS failure', async () => {+ await seedAccumulatedPolicy({ lapsed: false })+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined)+ injectPostResolutionTypeError()++ await expect(+ reconciler.reconcileExternalEgress(server, { isCurrent: () => true })+ ).rejects.toThrow(TypeError)++ // The operator must not be pointed at DNS for a fault in the reconciler.+ expect(warn.mock.calls.flat().join('\n')).not.toContain('permanent DNS failure')+ warn.mockRestore()++ // No mutation of the live policy on a fault we cannot classify.+ expect(mockApi.deleteNamespacedNetworkPolicy).not.toHaveBeenCalled()+ expect(mockApi.createNamespacedNetworkPolicy).not.toHaveBeenCalled()+ expect(mockApi.replaceNamespacedNetworkPolicy).not.toHaveBeenCalled()++ const egress = statusConditions().filter(c => c.type === 'ExternalEgressReady')+ expect(egress).not.toHaveLength(0)+ expect(egress.at(-1)?.status).toBe('False')+ expect(egress.at(-1)?.reason).toBe('ExternalEgressReconcileFailed')+ expect(egress.at(-1)?.message).toContain('api.example.com')+ })++ it('T2 does not prune the lapsed window on a post-resolution TypeError', async () => {+ await seedAccumulatedPolicy({ lapsed: true })+ injectPostResolutionTypeError()++ await expect(+ reconciler.reconcileExternalEgress(server, { isCurrent: () => true })+ ).rejects.toThrow(TypeError)++ // Pre-fix this prunes the lapsed set to zero, hits the `continue`, and the+ // policy is swept as undesired. D4 fail-static must hold for a fault that is+ // not a resolver condition at all.+ expect(mockApi.deleteNamespacedNetworkPolicy).not.toHaveBeenCalled()++ const egress = statusConditions().filter(c => c.type === 'ExternalEgressReady')+ expect(egress.at(-1)?.reason).toBe('ExternalEgressReconcileFailed')+ })++ it('T3 still prunes and fails loud on a genuine NXDOMAIN with a lapsed window', async () => {+ await seedAccumulatedPolicy({ lapsed: true })+ resolve4Mock.mockRejectedValueOnce(+ Object.assign(new Error('queryA ENOTFOUND api.example.com'), { code: 'ENOTFOUND' })+ )++ await expect(+ reconciler.reconcileExternalEgress(server, { isCurrent: () => true })+ ).rejects.toThrow(/failed to resolve hostname "api\.example\.com"/)++ // A real no-records answer is a DNS condition: the permanent branch is intact.+ expect(mockApi.deleteNamespacedNetworkPolicy).toHaveBeenCalledTimes(1)++ const egress = statusConditions().filter(c => c.type === 'ExternalEgressReady')+ expect(egress.at(-1)?.reason).toBe('ExternalEgressRejected')+ })++ it("T4 treats EBADNAME as the operator's malformed name, not as a controller fault", async () => {+ // EBADNAME is a POSITIVE verdict about the name: c-ares refused to send the+ // query at all. It is reachable from user input — the CRD pattern for+ // `egressBindings[].dns` admits consecutive dots and labels over 63 octets —+ // so it belongs with NXDOMAIN: prune and reject. Blaming the controller with+ // ExternalEgressReconcileFailed would send the operator hunting through our+ // logs for their own typo.+ await seedAccumulatedPolicy({ lapsed: true })+ resolve4Mock.mockRejectedValueOnce(+ Object.assign(new Error('queryA EBADNAME api.example.com'), { code: 'EBADNAME' })+ )++ await expect(+ reconciler.reconcileExternalEgress(server, { isCurrent: () => true })+ ).rejects.toThrow(/failed to resolve hostname "api\.example\.com"/)++ expect(mockApi.deleteNamespacedNetworkPolicy).toHaveBeenCalledTimes(1)++ const egress = statusConditions().filter(c => c.type === 'ExternalEgressReady')+ expect(egress.at(-1)?.reason).toBe('ExternalEgressRejected')+ })+})diff --git a/host-context-controller/src/networkPolicyReconciler.test.ts b/host-context-controller/src/networkPolicyReconciler.test.tsindex 218a4ff41..8682c09fe 100644--- a/host-context-controller/src/networkPolicyReconciler.test.ts+++ b/host-context-controller/src/networkPolicyReconciler.test.ts@@ -2660,7 +2660,15 @@ describe('NetworkPolicyReconciler', () => {})it('deletes stale policies and fails when DNS resolution for that binding fails', async () => {- vi.mocked(dns.resolve4).mockRejectedValueOnce(new Error('dns timeout'))+ // Issue #513: this used to inject a codeless `new Error('dns timeout')` and+ // expect the prune-and-delete path. That expectation encoded the defect —+ // classifyDnsError defaults an unknown code to 'permanent', so a codeless+ // error (a programming fault as easily as a resolver one) pruned the window+ // and deleted the policy. A codeless error is now rethrown, so this test+ // injects a real no-records answer: the permanent branch it means to cover.+ vi.mocked(dns.resolve4).mockRejectedValueOnce(+ Object.assign(new Error('queryA ENOTFOUND api.openai.com'), { code: 'ENOTFOUND' })+ )mockApi.listNamespacedNetworkPolicy.mockResolvedValue({items: [{ metadata: { name: 'ext-egress-openai-mcp-api.openai.com-443' } },@@ -2681,7 +2689,7 @@ describe('NetworkPolicyReconciler', () => {await expect(reconciler.reconcileExternalEgress(server, { isCurrent: () => true })- ).rejects.toThrow(/dns timeout/)+ ).rejects.toThrow(/ENOTFOUND/)expect(mockApi.deleteNamespacedNetworkPolicy).toHaveBeenCalledTimes(2)expect(mockApi.deleteNamespacedNetworkPolicy).toHaveBeenCalledWith(diff --git a/host-context-controller/src/networkPolicyReconciler.ts b/host-context-controller/src/networkPolicyReconciler.tsindex 0f87d59b9..baa9b392d 100644--- a/host-context-controller/src/networkPolicyReconciler.ts+++ b/host-context-controller/src/networkPolicyReconciler.ts@@ -16,7 +16,7 @@import * as k8s from '@kubernetes/client-node'import * as dns from 'node:dns/promises'import { isIP } from 'node:net'-import { STATE_ANNOTATION, classifyDnsError } from '@clerum/network-policy-core'+import { STATE_ANNOTATION, classifyDnsError, isPermanentDnsCode } from '@clerum/network-policy-core'import { config } from './config'import {EXTERNAL_EGRESS_POLICY_TYPE,@@ -2231,7 +2231,36 @@ export class NetworkPolicyReconciler {// Fail-static (H1): freeze the accumulated set on a transient resolver// failure; fail loud when there is nothing to serve (bootstrap, or a// permanent no-records answer).+ //+ // Issue #513: only a POSITIVELY identified DNS condition may reach the+ // sliding-window classifier. classifyDnsError defaults every unknown or+ // missing code to 'permanent' (network-policy-core index.cjs), and+ // 'permanent' PRUNES the accumulated set rather than freezing it. This+ // try covers the whole resolve-and-render block, so without this gate a+ // programming fault raised after resolution — a TypeError from a+ // contract violation, an ERR_* argument error — is laundered into the+ // prune branch and reported to the operator as a DNS failure, pointing+ // at the resolver while the fault is here. Transient codes are positive+ // by construction (TRANSIENT_DNS_CODES); 'permanent' is positive only for+ // PERMANENT_DNS_CODES — the two no-records answers plus EBADNAME, a name+ // c-ares refuses to query. EBADNAME passes the CRD pattern (`..`,+ // 64-octet labels) and is the operator's misconfiguration, so it must+ // keep pruning and reporting ExternalEgressRejected rather than blame+ // the controller.const kind = classifyDnsError(err)+ const code = err instanceof Error ? (err as NodeJS.ErrnoException).code : undefined+ if (kind !== 'transient' && !isPermanentDnsCode(code)) {+ if (!isCurrent()) return+ await this.writeExternalEgressStatus(+ server,+ resolvedEgressIPs,+ 'False',+ 'ExternalEgressReconcileFailed',+ `External egress reconciliation failed on binding "${binding.dns}" with a non-DNS error (not a resolver condition, accumulated egress left untouched): ${this.errorMessage(err)}`,+ isCurrent+ )+ throw err+ }const accumulated = accumulateHostExactHostEgress({fqdn: binding.dns,port: binding.port,diff --git a/packages/network-policy-core/index.cjs b/packages/network-policy-core/index.cjsindex 5192d454c..04983a7d1 100644--- a/packages/network-policy-core/index.cjs+++ b/packages/network-policy-core/index.cjs@@ -67,6 +67,29 @@ const TRANSIENT_DNS_CODES = new Set(['EADDRGETNETWORKPARAMS',])+/**+ * DNS codes that are a POSITIVE permanent verdict about the NAME (issue #513):+ * the two genuine no-records answers, plus EBADNAME — c-ares refused to send+ * the query because the name is malformed. EBADNAME is reachable from user+ * input: the CRD pattern for `egressBindings[].dns` admits consecutive dots and+ * labels over 63 octets, so a typo in a manifest lands here. A malformed name is+ * the operator's misconfiguration — not a resolver outage, not a controller+ * fault — so it prunes and is reported as rejected exactly like NXDOMAIN.+ *+ * Every other non-transient code stays OUT on purpose: EBADFAMILY, EBADFLAGS,+ * EBADHINTS, ENONAME, EBADQUERY and EBADSTR describe arguments neither+ * controller derives from user data, so if one of them fires the call is ours.+ * `classifyDnsError` still defaults those to 'permanent' — its contract is+ * pinned by this package's tests — which is exactly why the controllers gate on+ * THIS set to decide what may reach the sliding-window classifier, and rethrow+ * the rest instead of laundering a fault into a prune.+ */+const PERMANENT_DNS_CODES = new Set(['ENODATA', 'ENOTFOUND', 'EBADNAME'])++function isPermanentDnsCode(code) {+ return typeof code === 'string' && PERMANENT_DNS_CODES.has(code)+}+/*** Classify a DNS failure as 'transient' or 'permanent'. Accepts a raw code* string or an Error carrying `.code`. Unknown/missing codes default to@@ -417,4 +440,6 @@ module.exports = {serializeState,parseState,classifyDnsError,+ PERMANENT_DNS_CODES,+ isPermanentDnsCode,}diff --git a/packages/network-policy-core/index.d.ts b/packages/network-policy-core/index.d.tsindex 9972b2644..037415d05 100644--- a/packages/network-policy-core/index.d.ts+++ b/packages/network-policy-core/index.d.ts@@ -145,3 +145,14 @@ export declare const NETWORK_READY_GENERATION_ANNOTATION: stringexport declare function classifyDnsError(errOrCode: unknown): 'transient' | 'permanent'++/**+ * Codes that are a positive permanent verdict about the NAME (issue #513): the+ * two genuine no-records answers plus EBADNAME, a name c-ares refuses to query.+ * `classifyDnsError` returns 'permanent' for these AND for anything it does not+ * recognize; callers that must not launder an unclassified fault into a prune+ * gate on this set instead.+ */+export declare const PERMANENT_DNS_CODES: ReadonlySet<string>++export declare function isPermanentDnsCode(code: unknown): booleandiff --git a/packages/network-policy-core/index.test.cjs b/packages/network-policy-core/index.test.cjsindex 0dea8e1f3..666b648eb 100644--- a/packages/network-policy-core/index.test.cjs+++ b/packages/network-policy-core/index.test.cjs@@ -334,6 +334,50 @@ test('classifyDnsError defaults unknown/undefined codes to permanent (matches WRassert.equal(core.classifyDnsError(new Error('no code')), 'permanent')})+// ─── #513: the positive permanent set, which is NOT classifyDnsError's default ──+// classifyDnsError answers "is this transient?" and says 'permanent' for+// everything else, unknown codes included. That default is load-bearing for the+// window (an unrecognized transient must not freeze forever), but it makes the+// return value useless for deciding whether a failure was a DNS answer at all.+// PERMANENT_DNS_CODES is that second, narrower question, and the gap between the+// two sets is exactly the bug in issue #513.+test('#513: PERMANENT_DNS_CODES is the positive verdict set, not the default', () => {+ assert.deepEqual([...core.PERMANENT_DNS_CODES].sort(), ['EBADNAME', 'ENODATA', 'ENOTFOUND'])+ for (const code of core.PERMANENT_DNS_CODES) {+ assert.equal(core.classifyDnsError(code), 'permanent', `${code} must classify as permanent`)+ }+})++test('#513: isPermanentDnsCode rejects what classifyDnsError merely defaults', () => {+ // Every one of these yields 'permanent' from classifyDnsError. None is a DNS+ // answer: they are c-ares complaints about the query WE built, or no code at+ // all. Telling them apart is the whole point of the controllers' gates.+ for (const code of [+ undefined,+ null,+ 'ESOMETHINGWEIRD',+ 'EBADFAMILY',+ 'EBADFLAGS',+ 'EBADHINTS',+ 'EBADQUERY',+ 'EBADSTR',+ 'ENONAME',+ ]) {+ assert.equal(core.classifyDnsError(code), 'permanent')+ assert.equal(core.isPermanentDnsCode(code), false, `${String(code)} must not be a DNS verdict`)+ }+})++test('#513: the transient and permanent sets never overlap', () => {+ for (const code of core.PERMANENT_DNS_CODES) {+ assert.equal(+ core.classifyDnsError(code),+ 'permanent',+ `${code} appears in both sets — a code cannot be both a retry and a verdict`+ )+ }+})+// ─── H-A: revocation/freeze keyed by (fqdn,port,protocol), not fqdn alone ──────// The state map is keyed by (fqdn,ip,port,protocol) but classification used to be// keyed by fqdn only, so an entry whose declared PORT was removed survived underdiff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.jsonindex 386b77e65..523c9265d 100644--- a/workflow-recipes/package-lock.json+++ b/workflow-recipes/package-lock.json@@ -1,12 +1,12 @@{"name": "workload-recipes-controller",- "version": "0.1.322",+ "version": "0.1.323","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "workload-recipes-controller",- "version": "0.1.322",+ "version": "0.1.323","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 a8b8f3a4a..b26da66da 100644--- a/workflow-recipes/package.json+++ b/workflow-recipes/package.json@@ -1,6 +1,6 @@{"name": "workload-recipes-controller",- "version": "0.1.322",+ "version": "0.1.323","description": "Workload Recipes Controller (WRC) - WorkloadRecipe lifecycle management and MCP server interface","main": "dist/main.js","engines": {diff --git a/workflow-recipes/src/reconciler/fqdnResolver.test.ts b/workflow-recipes/src/reconciler/fqdnResolver.test.tsindex 2b6bef92f..6ba0104bc 100644--- a/workflow-recipes/src/reconciler/fqdnResolver.test.ts+++ b/workflow-recipes/src/reconciler/fqdnResolver.test.ts@@ -226,6 +226,71 @@ describe('defaultFqdnLookup classification', () => {const result = await defaultFqdnLookup('partial.example.com')expect(result).toMatchObject({ kind: 'error', retryable: true })})++ // ─── issue #513: only a positive DNS verdict may become a lookup result ──────+ // `FqdnLookupResult` is a DNS verdict type. Before the fix its final branch was+ // an unconditional `return { error: 'no A or AAAA records' }`, so anything the+ // transient set did not recognize — a c-ares complaint about the query WE+ // built, or a rejection with no code at all — was reported as an empty answer+ // the resolver never gave, and travelled on as a permanent misconfiguration.++ it.each(['EBADFAMILY', 'EBADQUERY'])(+ 'T4a throws on %s: a complaint about our own query is not a DNS answer',+ async code => {+ resolve4Mock.mockRejectedValue(dnsError(code))+ resolve6Mock.mockRejectedValue(dnsError(code))++ await expect(defaultFqdnLookup('h.example.com')).rejects.toThrow(code)+ await expect(defaultFqdnLookup('h.example.com')).rejects.toThrow('"h.example.com"')+ await expect(defaultFqdnLookup('h.example.com')).rejects.toMatchObject({+ cause: expect.objectContaining({ code }),+ })+ }+ )++ it('T4b throws when a rejection carries no code at all', async () => {+ resolve4Mock.mockRejectedValue(new Error('boom'))+ resolve6Mock.mockRejectedValue(dnsError('ENODATA'))++ await expect(defaultFqdnLookup('nocode.example.com')).rejects.toThrow(/no code/)+ await expect(defaultFqdnLookup('nocode.example.com')).rejects.toThrow(/boom/)+ })++ it('T4c reports EBADNAME as a malformed name, not as an empty answer', async () => {+ // Permanent like NXDOMAIN, but the resolver never queried the name. Saying+ // "no A or AAAA records" sends the operator hunting for missing records+ // instead of at the typo in their own manifest.+ resolve4Mock.mockRejectedValue(dnsError('EBADNAME'))+ resolve6Mock.mockRejectedValue(dnsError('EBADNAME'))++ const result = await defaultFqdnLookup('foo..example.com')+ expect(result).toMatchObject({ kind: 'error' })+ expect((result as { error: string }).error).toContain('EBADNAME')+ expect((result as { error: string }).error).toContain('foo..example.com')+ expect((result as { error: string }).error).not.toContain('no A or AAAA')+ expect((result as { retryable?: boolean }).retryable).toBeFalsy()+ })++ it('T4d still reports a genuinely empty answer as no-records', async () => {+ // A family that RESOLVED to an empty list contributes no rejection at all.+ // The gate keys on rejections, so this must not be mistaken for an+ // unclassified fault.+ resolve4Mock.mockResolvedValue([])+ resolve6Mock.mockRejectedValue(dnsError('ENODATA'))++ const result = await defaultFqdnLookup('empty.example.com')+ expect(result).toEqual({ kind: 'error', error: 'no A or AAAA records' })+ })++ it('T4e lets a transient code win over an unclassified one', async () => {+ // Retrying is harmless, and if the resolver recovers the fault surfaces on+ // the next pass with a real answer to contrast it against.+ resolve4Mock.mockRejectedValue(dnsError('EBADFAMILY'))+ resolve6Mock.mockRejectedValue(dnsError('ESERVFAIL'))++ const result = await defaultFqdnLookup('mixed.example.com')+ expect(result).toMatchObject({ kind: 'error', retryable: true })+ })})// ─── issue #299: TTL propagation (feeds the sliding-window accumulator) ─────diff --git a/workflow-recipes/src/reconciler/fqdnResolver.ts b/workflow-recipes/src/reconciler/fqdnResolver.tsindex aed344d44..61f3b3178 100644--- a/workflow-recipes/src/reconciler/fqdnResolver.ts+++ b/workflow-recipes/src/reconciler/fqdnResolver.ts@@ -1,6 +1,6 @@import type { RecordWithTtl } from 'node:dns'import { resolve4, resolve6 } from 'node:dns/promises'-import { classifyDnsError } from '@clerum/network-policy-core'+import { classifyDnsError, isPermanentDnsCode } from '@clerum/network-policy-core'import type { SandboxUiExternalEgress } from '../types'const BLOCKED_EGRESS_CIDRS = [@@ -90,7 +90,9 @@ export type FqdnLookupResult =| { kind: 'ok'; ipv4: string[]; ipv6: string[]; ttlSeconds: number }// `retryable` distinguishes a transient resolver failure (SERVFAIL, timeout,// unreachable upstream) — worth retrying on a later reconcile — from a- // permanent one (the name genuinely has no A/AAAA records). Absent ⇒ permanent.+ // permanent one (the name genuinely has no A/AAAA records, or is malformed).+ // Absent ⇒ permanent. A failure that is not a DNS verdict at all never becomes+ // a result: the lookup throws (issue #513).| { kind: 'error'; error: string; retryable?: boolean }export type FqdnLookup = (host: string) => Promise<FqdnLookupResult>@@ -148,17 +150,50 @@ export const defaultFqdnLookup: FqdnLookup = async host => {return { kind: 'ok', ipv4, ipv6, ttlSeconds }}- const codes = ['err' in v4 ? v4.err.code : undefined, 'err' in v6 ? v6.err.code : undefined]- const transientCode = codes.find(- code => code !== undefined && classifyDnsError(code) === 'transient'- )- if (transientCode) {+ const rejections: NodeJS.ErrnoException[] = []+ if ('err' in v4) rejections.push(v4.err)+ if ('err' in v6) rejections.push(v6.err)++ const transient = rejections.find(e => classifyDnsError(e) === 'transient')+ if (transient) {return {kind: 'error',- error: `DNS resolution for "${host}" failed (${transientCode}) — resolver or upstream unavailable`,+ error: `DNS resolution for "${host}" failed (${transient.code}) — resolver or upstream unavailable`,retryable: true,}}++ // Issue #513: only a POSITIVE DNS verdict may become a lookup result. A family+ // that resolved to an empty list contributes no rejection at all; one that+ // rejected must carry a code in PERMANENT_DNS_CODES. Anything else — a+ // codeless rejection, or a c-ares complaint about the query WE built rather+ // than about the name — is not a DNS answer, and the old default branch turned+ // it into "no A or AAAA records": a reply that was never received, blamed on+ // the resolver, and routed on through egressResolutionError() as the+ // operator's permanent misconfiguration. Throw instead. The reconciler's catch+ // already routes a plain Error to the terminal `failed` phase with the real+ // message (walking `.cause` for socket codes), and this throw happens before+ // any policy write or delete, so the live NetworkPolicy is left untouched. The+ // message deliberately avoids the 'egress resolution failed' marker that catch+ // matches on: a raw fault is not a DNS classification worth protecting.+ const unclassified = rejections.find(e => !isPermanentDnsCode(e.code))+ if (unclassified) {+ throw new Error(+ `DNS lookup for "${host}" failed with a non-DNS error (${unclassified.code ?? 'no code'}): ${unclassified.message}`,+ { cause: unclassified }+ )+ }++ // EBADNAME is permanent like NXDOMAIN, but it is not an empty answer: c-ares+ // refused to send the query. Say so, or the operator hunts for missing records+ // on a name the resolver never asked about.+ if (rejections.some(e => e.code === 'EBADNAME')) {+ return {+ kind: 'error',+ error: `malformed hostname "${host}" (EBADNAME) — the resolver refused to query it`,+ }+ }+return { kind: 'error', error: 'no A or AAAA records' }}@@ -186,7 +221,10 @@ export interface ResolveResult {* apply a stale or partial NetworkPolicy off the back of one. Each failure* carries a `retryable` flag: transient resolver failures (SERVFAIL/timeout)* are retryable, while a genuine no-records answer or a blocked-address- * rejection fails closed permanently. If any A record for a hostname resolves+ * rejection fails closed permanently. A lookup that cannot produce a DNS verdict+ * at all throws instead of returning a failure, so the reconciler's existing+ * error routing reports the real fault (issue #513).+ * If any A record for a hostname resolves* to a blocked range, the entire hostname fails closed and no public siblings* are emitted.*/diff --git a/workflow-recipes/src/reconciler/reconciler.test.ts b/workflow-recipes/src/reconciler/reconciler.test.tsindex 1018b40a9..07bf7ade4 100644--- a/workflow-recipes/src/reconciler/reconciler.test.ts+++ b/workflow-recipes/src/reconciler/reconciler.test.ts@@ -2431,6 +2431,55 @@ describe('WorkflowRecipeReconciler', () => {)})+ it('#513: a lookup that throws fails the recipe without touching the egress policy', async () => {+ // Pins the routing the fqdnResolver gate relies on. `defaultFqdnLookup` now+ // throws rather than dressing an unclassifiable fault as "no A or AAAA+ // records"; that only helps if the throw lands somewhere honest. It must+ // reach the terminal `failed` phase carrying the real code, and it must do+ // so before any write or delete, leaving whatever egress policy is live+ // exactly as it was.+ const recipe = makeRecipe({+ spec: {+ contextRef: 'default',+ workloads: [+ {+ id: 'worker',+ type: 'deployment',+ image: 'worker:latest',+ port: 8080,+ egressBindings: [{ dns: 'api.example.com', port: 443 }],+ },+ ],+ },+ })+ const reconcilerWithLookup = new WorkflowRecipeReconciler(new k8s.KubeConfig(), undefined, {+ fqdnLookup: async () => {+ throw new Error(+ 'DNS lookup for "api.example.com" failed with a non-DNS error (EBADFAMILY): queryA EBADFAMILY',+ { cause: Object.assign(new Error('queryA EBADFAMILY'), { code: 'EBADFAMILY' }) }+ )+ },+ })++ const result = await reconcilerWithLookup.reconcile(recipe)++ expect(result.phase).toBe('failed')+ expect(result.message).toContain('EBADFAMILY')+ // Not laundered into the operator-facing no-records wording.+ expect(result.message).not.toContain('no A or AAAA records')++ const egressPolicy = expect.objectContaining({+ body: expect.objectContaining({+ metadata: expect.objectContaining({ name: 'wl-egress-test-recipe-worker' }),+ }),+ })+ expect(mockNetworkingApi.createNamespacedNetworkPolicy).not.toHaveBeenCalledWith(egressPolicy)+ expect(mockNetworkingApi.replaceNamespacedNetworkPolicy).not.toHaveBeenCalledWith(egressPolicy)+ expect(mockNetworkingApi.deleteNamespacedNetworkPolicy).not.toHaveBeenCalledWith(+ expect.objectContaining({ name: 'wl-egress-test-recipe-worker' })+ )+ })+it('returns failed phase when a workload egress binding uses wildcard DNS', async () => {const recipe = makeRecipe({spec: {