Skip to content

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

TypeScript

feat(guardrails): install gate keys content-bearing on contentAccess (§8.4)

Andy Pavia23b5c0ebc16e
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 7a68d2d8d..c47b8b39f 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.440",
+ "version": "0.1.441",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.440",
+ "version": "0.1.441",
"dependencies": {
"@clerum/image-policy": "file:../packages/image-policy",
"@clerum/llm-providers": "file:../packages/llm-providers",
diff --git a/control-api/package.json b/control-api/package.json
index caddbdcb8..6c2fdadf9 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.440",
+ "version": "0.1.441",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/src/routes/admin/__tests__/installHookTrust.test.ts b/control-api/src/routes/admin/__tests__/installHookTrust.test.ts
index 7fa80bc04..6f424ccb3 100644
--- a/control-api/src/routes/admin/__tests__/installHookTrust.test.ts
+++ b/control-api/src/routes/admin/__tests__/installHookTrust.test.ts
@@ -47,14 +47,24 @@ describe('resolveHookTrustLevel', () => {
})
})
-describe('content-bearing classification (§8.4/§8.7 fix A)', () => {
- it('every message-carrying point is content-bearing — incl. preCall and onError', () => {
- expect(isContentBearingHook(['preCall'])).toBe(true)
+describe('content-bearing classification (§8.4/§8.7)', () => {
+ it('moderate/postCallSuccess/onError are always content-bearing', () => {
expect(isContentBearingHook(['moderate'])).toBe(true)
expect(isContentBearingHook(['postCallSuccess'])).toBe(true)
expect(isContentBearingHook(['onError'])).toBe(true)
})
+ it('preCall is content-bearing by default and when content, but NOT when metadata', () => {
+ expect(isContentBearingHook(['preCall'])).toBe(true) // absent ⇒ conservative
+ expect(isContentBearingHook(['preCall'], 'content')).toBe(true)
+ expect(isContentBearingHook(['preCall'], 'metadata')).toBe(false)
+ })
+
+ it('contentAccess: metadata cannot make an inherently-content point content-free', () => {
+ expect(isContentBearingHook(['moderate'], 'metadata')).toBe(true)
+ expect(isContentBearingHook(['preCall', 'moderate'], 'metadata')).toBe(true)
+ })
+
it('an empty/unknown point set is not content-bearing', () => {
expect(isContentBearingHook([])).toBe(false)
expect(isContentBearingHook(undefined)).toBe(false)
@@ -118,4 +128,16 @@ describe('content/egress separation gate (§8.4)', () => {
})
).toBe(false)
})
+
+ it('preCall metadata-only shaper + egress at low trust → allowed (content-free, B)', () => {
+ expect(
+ contentEgressRequiresHighTrust({
+ lifecyclePoints: ['preCall'],
+ contentAccess: 'metadata',
+ hasEgress: true,
+ isRemote: false,
+ trustLevel: 'low',
+ })
+ ).toBe(false)
+ })
})
diff --git a/control-api/src/routes/admin/registry.ts b/control-api/src/routes/admin/registry.ts
index c951cdbce..e36dd08dd 100644
--- a/control-api/src/routes/admin/registry.ts
+++ b/control-api/src/routes/admin/registry.ts
@@ -131,22 +131,26 @@ const NO_CREDENTIAL_SCHEMA: RegistryCredentialSchema = {
// ── install-hook trust policy (guardrails spec §8.4) ────────────────────────
const HOOK_TRUST_ORDER: Record<string, number> = { low: 0, mid: 1, high: 2 }
-// Lifecycle points that receive message/response CONTENT (§8.4/§8.7). The runtime
-// currently sends the full ToolCompletionRequest (messages) to preCall and onError
-// as well as moderate/postCallSuccess, and no content projection redacts it yet, so
-// EVERY message-carrying point is content-bearing for this gate (interim fix A,
-// §12.4). The target model (B) keys this on the per-hook `spec.contentAccess`
-// declaration once the projection enforces it — until then, treat them all as
-// content-bearing so a preCall/onError egress hook can't dodge the high-trust bar.
-const CONTENT_BEARING_POINTS = new Set(['preCall', 'moderate', 'postCallSuccess', 'onError'])
+// Lifecycle points that ALWAYS receive message/response content (§8.4/§8.7). preCall
+// is the one point with two flavors — content-bearing unless the hook declares
+// `contentAccess: metadata` — so it is handled separately in isContentBearingHook.
+const INHERENTLY_CONTENT_POINTS = new Set(['moderate', 'postCallSuccess', 'onError'])
/**
* §8.4/§8.7 — does this hook receive message/response CONTENT at any of its
- * lifecycle points? Interim fix A: every message-carrying point counts (see
- * CONTENT_BEARING_POINTS). Target model B keys this on `spec.contentAccess`.
+ * lifecycle points? moderate/postCallSuccess/onError always do; preCall does
+ * unless it explicitly declared `contentAccess: metadata` (mcp-host's projection
+ * enforces the same rule, so the gate and the runtime agree — the two land
+ * together, §12.4). Absent contentAccess ⇒ content-bearing (conservative).
*/
-export function isContentBearingHook(lifecyclePoints: string[] | undefined): boolean {
- return Array.isArray(lifecyclePoints) && lifecyclePoints.some(p => CONTENT_BEARING_POINTS.has(p))
+export function isContentBearingHook(
+ lifecyclePoints: string[] | undefined,
+ contentAccess?: string
+): boolean {
+ if (!Array.isArray(lifecyclePoints)) return false
+ if (lifecyclePoints.some(p => INHERENTLY_CONTENT_POINTS.has(p))) return true
+ if (lifecyclePoints.includes('preCall')) return contentAccess !== 'metadata'
+ return false
}
/**
@@ -157,12 +161,13 @@ export function isContentBearingHook(lifecyclePoints: string[] | undefined): boo
*/
export function contentEgressRequiresHighTrust(args: {
lifecyclePoints: string[] | undefined
+ contentAccess?: string
hasEgress: boolean
isRemote: boolean
trustLevel: string
}): boolean {
return (
- isContentBearingHook(args.lifecyclePoints) &&
+ isContentBearingHook(args.lifecyclePoints, args.contentAccess) &&
(args.hasEgress || args.isRemote) &&
args.trustLevel !== 'high'
)
@@ -176,6 +181,7 @@ type HookMetaShape = {
remote?: { baseUrl?: string }
}
lifecyclePoints: string[]
+ contentAccess?: string
path?: string
defaultConfig?: Record<string, unknown>
requiredEgress?: unknown[]
@@ -1779,9 +1785,23 @@ export function createAdminRegistryRouter(gateway?: K8sGateway): Router {
const hasEgress =
Array.isArray(hookMeta.requiredEgress) && hookMeta.requiredEgress.length > 0
const isRemote = !!hookMeta.target.remote
+ // contentAccess: metadata is contradictory for an inherently content-bearing
+ // point (mirrors the CRD CEL). Reject early with a clear error.
+ if (
+ hookMeta.contentAccess === 'metadata' &&
+ hookMeta.lifecyclePoints.some(p => INHERENTLY_CONTENT_POINTS.has(p))
+ ) {
+ res.status(400).json({
+ error: 'content_access_conflict',
+ reason:
+ 'contentAccess: metadata is not allowed for a hook using moderate/postCallSuccess/onError (§8.4)',
+ })
+ return
+ }
if (
contentEgressRequiresHighTrust({
lifecyclePoints: hookMeta.lifecyclePoints,
+ contentAccess: hookMeta.contentAccess,
hasEgress,
isRemote,
trustLevel,
@@ -1930,6 +1950,9 @@ export function createAdminRegistryRouter(gateway?: K8sGateway): Router {
target: targetSpec,
path: hookMeta.path ?? '/',
lifecyclePoints: hookMeta.lifecyclePoints,
+ ...(hookMeta.contentAccess === 'metadata' || hookMeta.contentAccess === 'content'
+ ? { contentAccess: hookMeta.contentAccess }
+ : {}),
order: typeof body.order === 'number' ? body.order : 100,
failMode,
...(capabilities.length > 0 ? { capabilities } : {}),