Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(egress): close the six minor findings from the #567 review

Alfredo Lopez892045785077
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index 3929e0371..9ac76e380 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.289",
+ "version": "0.1.290",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.289",
+ "version": "0.1.290",
"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.json
index 2b103109a..c4d48c15d 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.289",
+ "version": "0.1.290",
"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.ts
index f182dfb3e..d117fd0c0 100644
--- a/host-context-controller/src/networkPolicyReconciler.egressClassification.test.ts
+++ b/host-context-controller/src/networkPolicyReconciler.egressClassification.test.ts
@@ -23,14 +23,6 @@ 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
diff --git a/host-context-controller/src/networkPolicyReconciler.ts b/host-context-controller/src/networkPolicyReconciler.ts
index f5214db91..f280bab6d 100644
--- a/host-context-controller/src/networkPolicyReconciler.ts
+++ b/host-context-controller/src/networkPolicyReconciler.ts
@@ -2304,7 +2304,9 @@ export class NetworkPolicyReconciler {
})
}
reconcileFaults.push({
- dns: binding.dns ?? '(unnamed binding)',
+ // Inside `else if (binding.dns)`, so it is always a string here;
+ // a `??` fallback would be an unreachable branch pretending to be a guard.
+ dns: binding.dns,
err,
// Blocking only when there is nothing to serve. A fault on a
// binding that has never been written has no frozen set behind it,
diff --git a/packages/network-policy-core/index.cjs b/packages/network-policy-core/index.cjs
index 8321f2efd..c1c2fcbcb 100644
--- a/packages/network-policy-core/index.cjs
+++ b/packages/network-policy-core/index.cjs
@@ -67,6 +67,15 @@ const TRANSIENT_DNS_CODES = new Set([
'EADDRGETNETWORKPARAMS',
])
+/**
+ * The subset that means "the resolver answered, and the answer was empty". Split
+ * out because the two permanent shapes need different words to the operator: a
+ * name with no records is not the same event as a name the resolver refused to
+ * query, and reporting both as "no A or AAAA records" sends someone hunting for
+ * missing records on a query that was never sent.
+ */
+const NO_RECORDS_DNS_CODES = Object.freeze(['ENODATA', 'ENOTFOUND'])
+
/**
* 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
@@ -87,7 +96,22 @@ const TRANSIENT_DNS_CODES = new Set([
* 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'])
+/**
+ * Frozen array rather than a Set: a `Set` exported from a CommonJS module is a
+ * live mutable object, and `Object.freeze` does not stop `.add()` on one — the
+ * `ReadonlySet<string>` in index.d.ts would have been a claim the runtime did not
+ * back. Membership goes through `isPermanentDnsCode`.
+ */
+const PERMANENT_DNS_CODES = Object.freeze([...NO_RECORDS_DNS_CODES, 'EBADNAME'])
+
+function isPermanentDnsCode(code) {
+ return typeof code === 'string' && PERMANENT_DNS_CODES.includes(code)
+}
+
+/** True for the two genuine no-records answers, false for every other code. */
+function isNoRecordsDnsCode(code) {
+ return typeof code === 'string' && NO_RECORDS_DNS_CODES.includes(code)
+}
/**
* Seam worth knowing about, not a defect today: this set and TRANSIENT_DNS_CODES
@@ -102,10 +126,6 @@ const PERMANENT_DNS_CODES = new Set(['ENODATA', 'ENOTFOUND', 'EBADNAME'])
* another question.
*/
-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
@@ -458,4 +478,5 @@ module.exports = {
classifyDnsError,
PERMANENT_DNS_CODES,
isPermanentDnsCode,
+ isNoRecordsDnsCode,
}
diff --git a/packages/network-policy-core/index.d.ts b/packages/network-policy-core/index.d.ts
index 037415d05..a4322484e 100644
--- a/packages/network-policy-core/index.d.ts
+++ b/packages/network-policy-core/index.d.ts
@@ -153,6 +153,13 @@ export declare function classifyDnsError(
* 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 const PERMANENT_DNS_CODES: readonly string[]
export declare function isPermanentDnsCode(code: unknown): boolean
+
+/**
+ * True for the two genuine no-records answers (ENODATA, ENOTFOUND) and false for
+ * every other code, PERMANENT_DNS_CODES members included. Lets a caller word a
+ * permanent verdict correctly: an empty answer is not a refused query.
+ */
+export declare function isNoRecordsDnsCode(code: unknown): boolean
diff --git a/packages/network-policy-core/index.test.cjs b/packages/network-policy-core/index.test.cjs
index 666b648eb..9b8f1a64b 100644
--- a/packages/network-policy-core/index.test.cjs
+++ b/packages/network-policy-core/index.test.cjs
@@ -368,15 +368,6 @@ test('#513: isPermanentDnsCode rejects what classifyDnsError merely defaults', (
}
})
-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
diff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.json
index bd7095d74..fbee3b101 100644
--- a/workflow-recipes/package-lock.json
+++ b/workflow-recipes/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "workload-recipes-controller",
- "version": "0.1.339",
+ "version": "0.1.340",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "workload-recipes-controller",
- "version": "0.1.339",
+ "version": "0.1.340",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@aws-sdk/client-s3": "^3.1009.0",
diff --git a/workflow-recipes/package.json b/workflow-recipes/package.json
index c043e5cb5..7747bce78 100644
--- a/workflow-recipes/package.json
+++ b/workflow-recipes/package.json
@@ -1,6 +1,6 @@
{
"name": "workload-recipes-controller",
- "version": "0.1.339",
+ "version": "0.1.340",
"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.ts b/workflow-recipes/src/reconciler/fqdnResolver.ts
index 61f3b3178..265ff332a 100644
--- a/workflow-recipes/src/reconciler/fqdnResolver.ts
+++ b/workflow-recipes/src/reconciler/fqdnResolver.ts
@@ -1,6 +1,10 @@
import type { RecordWithTtl } from 'node:dns'
import { resolve4, resolve6 } from 'node:dns/promises'
-import { classifyDnsError, isPermanentDnsCode } from '@clerum/network-policy-core'
+import {
+ classifyDnsError,
+ isNoRecordsDnsCode,
+ isPermanentDnsCode,
+} from '@clerum/network-policy-core'
import type { SandboxUiExternalEgress } from '../types'
const BLOCKED_EGRESS_CIDRS = [
@@ -106,6 +110,16 @@ export type FqdnLookup = (host: string) => Promise<FqdnLookupResult>
* stable answers (ENODATA, ENOTFOUND/NXDOMAIN, empty) fail closed permanently.
*/
+/**
+ * `settleV4`/`settleV6` cast whatever the promise rejected with to
+ * `NodeJS.ErrnoException`; nothing guarantees it was an Error. Reading `.message`
+ * off a rejected string or object then interpolates `undefined` into the message
+ * an operator reads. Fall back to the value itself, never to a placeholder.
+ */
+function describeRejection(err: NodeJS.ErrnoException): string {
+ return typeof err?.message === 'string' ? err.message : String(err)
+}
+
/**
* Default FQDN lookup using node:dns/promises. Returns ipv4 and ipv6 record
* sets independently; a missing record type for one family is fine as long as
@@ -179,18 +193,21 @@ export const defaultFqdnLookup: FqdnLookup = async host => {
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}`,
+ `DNS lookup for "${host}" failed with a non-DNS error (${unclassified.code ?? 'no code'}): ${describeRejection(unclassified)}`,
{ 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')) {
+ // A permanent verdict that is NOT one of the two no-records answers means the
+ // resolver refused to send the query at all — EBADNAME today. Report the real
+ // code rather than testing for it: hardcoding 'EBADNAME' here would drift the
+ // moment PERMANENT_DNS_CODES gains another member, and the message would fall
+ // back to "no A or AAAA records" — the same lie this branch exists to remove.
+ const refused = rejections.find(e => !isNoRecordsDnsCode(e.code))
+ if (refused) {
return {
kind: 'error',
- error: `malformed hostname "${host}" (EBADNAME) — the resolver refused to query it`,
+ error: `malformed hostname "${host}" (${refused.code}) — the resolver refused to query it`,
}
}