Skip to content

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

TypeScript

feat(guardrails): llm-hooks default-deny-egress + scoped CoreDNS (N3/N4/N5)

Andy Paviae381fa45d877
diff --git a/deploy/base/llm-hooks/networkpolicies.yaml b/deploy/base/llm-hooks/networkpolicies.yaml
index b66c0fba2..1e4a7b47d 100644
--- a/deploy/base/llm-hooks/networkpolicies.yaml
+++ b/deploy/base/llm-hooks/networkpolicies.yaml
@@ -1,23 +1,25 @@
-# Baseline default-deny-INGRESS for the llm-hooks namespace (guardrails §8.2).
+# Baseline default-deny (INGRESS + EGRESS) for the llm-hooks namespace (§8.2, N3).
#
-# Without this, a hook pod that no NetworkPolicy selects is default-ALLOW ingress
-# — which is the case for `service`-target hooks (host-context-controller only
-# emits per-podKey ingress policies for `image` targets). With this baseline in
-# place, an un-covered hook pod is fail-CLOSED: it accepts traffic only from what
-# an explicit allow-policy admits.
+# Every hook pod starts fully isolated — denied all inbound AND all outbound —
+# and reaches (or is reached) only through the narrow allow-policies HCC emits.
+# Without the ingress half, a pod no policy selects is default-ALLOW ingress
+# (the case for `service`-target hooks); without the egress half, a hook could
+# initiate outbound to any pod/namespace/internet (N4/N5).
#
-# This composes additively with the controller-managed allow-policies:
-# - image targets: `llmhook-<podKey>` admits the referencing mcp-hosts.
+# Composes additively with the controller-managed allow-policies:
+# - image targets: `llmhook-<podKey>` admits the referencing mcp-hosts
+# (ingress) and permits declared `egressBindings` + scoped
+# CoreDNS (egress, only for hooks that declare outbound).
# - service targets: `llmhook-svc-<crName>` admits the referencing mcp-hosts.
-# Kubelet health/readiness probes originate from the node and are not affected
-# (the existing per-podKey policies already coexist with pod probes).
+# A pure `/v1` responder hook (no egressBindings) gets NO egress — not even DNS
+# (N5, "no implicit DNS"); it still replies to mcp-host on the established
+# inbound connection (connection tracking), which needs no egress rule.
#
-# INGRESS only — hook egress (DNS, image-target egressBindings) is governed
-# separately and is not constrained here.
+# Kubelet health/readiness probes originate from the node and are unaffected.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
- name: default-deny-ingress
+ name: default-deny
namespace: llm-hooks
labels:
clerum.io/managed-by: host-context-controller
@@ -26,3 +28,4 @@ spec:
podSelector: {}
policyTypes:
- Ingress
+ - Egress
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index 2c021ccaf..f7a9bf6c5 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.169",
+ "version": "0.1.170",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.169",
+ "version": "0.1.170",
"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 d010a92de..b82fa88ea 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.169",
+ "version": "0.1.170",
"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/llmHookReconciler.test.ts b/host-context-controller/src/llmHookReconciler.test.ts
index 29065df06..c6ddefa63 100644
--- a/host-context-controller/src/llmHookReconciler.test.ts
+++ b/host-context-controller/src/llmHookReconciler.test.ts
@@ -778,6 +778,48 @@ describe('LlmHookReconciler', () => {
expect(appsApi.createNamespacedDeployment).not.toHaveBeenCalled()
})
+ it('grants scoped CoreDNS egress only when a hook declares egressBindings (N5)', async () => {
+ const withEgress = makeHook({
+ name: 'out',
+ spec: {
+ target: { image: { ref: IMG, port: 8080, egressBindings: [{ cidr: '8.8.8.8/32' }] } },
+ lifecyclePoints: ['preCall'],
+ },
+ })
+ hooks.set('out', withEgress)
+ await reconciler.reconcile(withEgress)
+
+ const np = (
+ networkingApi.createNamespacedNetworkPolicy.mock.calls.at(-1)![0] as {
+ body: k8s.V1NetworkPolicy
+ }
+ ).body
+ expect(np.spec?.policyTypes).toContain('Egress')
+ const egress = np.spec?.egress ?? []
+ // The declared binding …
+ expect(egress.some(r => r.to?.some(t => t.ipBlock?.cidr === '8.8.8.8/32'))).toBe(true)
+ // … plus a scoped CoreDNS allow (kube-system:53).
+ const dns = egress.find(r =>
+ r.to?.some(
+ t => t.namespaceSelector?.matchLabels?.['kubernetes.io/metadata.name'] === 'kube-system'
+ )
+ )
+ expect(dns).toBeDefined()
+ expect(dns?.ports?.map(p => p.port)).toEqual([53, 53])
+ })
+
+ it('grants NO egress (not even DNS) to a pure responder hook (no egressBindings)', async () => {
+ const responder = makeHook({ name: 'resp' }) // default image, no egressBindings
+ hooks.set('resp', responder)
+ await reconciler.reconcile(responder)
+
+ const np = networkingApi.createNamespacedNetworkPolicy.mock.calls
+ .map(c => c[0] as { body: k8s.V1NetworkPolicy })
+ .find(c => c.body.metadata?.name === podKeyResourceName(computePodKey(responder)!))!.body
+ expect(np.spec?.policyTypes).not.toContain('Egress')
+ expect(np.spec?.egress).toBeUndefined()
+ })
+
it('allows a valid public-CIDR egress binding as an Egress NetworkPolicy rule', async () => {
const a = makeHook({
name: 'a',
diff --git a/host-context-controller/src/llmHookReconciler.ts b/host-context-controller/src/llmHookReconciler.ts
index 3f55ca66b..43080b055 100644
--- a/host-context-controller/src/llmHookReconciler.ts
+++ b/host-context-controller/src/llmHookReconciler.ts
@@ -553,6 +553,22 @@ export class LlmHookReconciler {
failures.push('egress binding must declare toFQDN or cidr')
}
+
+ // Scoped DNS (N5): a hook that declares outbound egress must resolve its
+ // targets at runtime, so grant egress to CoreDNS (kube-system:53) — but ONLY
+ // for hooks that opted into egress. A pure /v1 responder (no egressBindings)
+ // gets no egress at all, "no implicit DNS".
+ if (rules.length > 0) {
+ rules.push({
+ to: [
+ { namespaceSelector: { matchLabels: { 'kubernetes.io/metadata.name': 'kube-system' } } },
+ ],
+ ports: [
+ { port: 53, protocol: 'UDP' },
+ { port: 53, protocol: 'TCP' },
+ ],
+ })
+ }
return { rules, failures }
}