Skip to content

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

TypeScript

feat(guardrails): reconcileByEnvSecret for LlmHook credential rotation (§8.2)

Andy Paviac601eafb1c0d
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index b9aaeba07..2c021ccaf 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.168",
+ "version": "0.1.169",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.168",
+ "version": "0.1.169",
"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 947dc9a61..d010a92de 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.168",
+ "version": "0.1.169",
"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/k8sClient.ts b/host-context-controller/src/k8sClient.ts
index 7ef36351a..ad28407a7 100644
--- a/host-context-controller/src/k8sClient.ts
+++ b/host-context-controller/src/k8sClient.ts
@@ -1619,6 +1619,31 @@ export class McpServerWatcher implements McpServerProvider {
}
}
+ /**
+ * Trigger a reconcile for any cached image `LlmHook` whose `envSecret` matches
+ * the changed Secret (spec §8.2). A rotation (same name, new contents) leaves
+ * the pod key unchanged but re-stamps the credentials-revision on the pod
+ * template → rolling restart onto the new credential — mirroring
+ * `reconcileByEnvSecret` for McpServer. Driven by the llm-hooks SecretInformer.
+ */
+ async reconcileLlmHookByEnvSecret(secretName: string, secretNamespace: string): Promise<void> {
+ if (secretNamespace !== config.llmHooksNamespace) return
+ for (const hook of this.llmHooks.values()) {
+ if (hook.spec.target?.image?.envSecret !== secretName) continue
+ try {
+ console.log(
+ `[K8s] Re-reconciling LlmHook "${hook.name}" after Secret "${secretName}" change`
+ )
+ // Pod key is unchanged by a contents-only rotation, so pass it as the
+ // previous key (no stale-workload teardown) — the reconcile re-stamps the
+ // credentials-revision and rolls the shared pod.
+ await this.llmHookReconciler.reconcile(hook, computePodKey(hook))
+ } catch (err) {
+ console.error(`[K8s] Secret-triggered LlmHook reconcile failed for "${hook.name}":`, err)
+ }
+ }
+ }
+
/**
* Get all cached servers.
*/
diff --git a/host-context-controller/src/main.ts b/host-context-controller/src/main.ts
index 0e1502aa5..b42516145 100644
--- a/host-context-controller/src/main.ts
+++ b/host-context-controller/src/main.ts
@@ -29,6 +29,7 @@ let provider: McpServerProvider | null = null
let server: ContextMapperServer | null = null
let secretInformer: SecretInformer | null = null
let channelSecretInformer: SecretInformer | null = null
+let llmHooksSecretInformer: SecretInformer | null = null
let lifecycleTracker: StatelessLifecycleTracker | null = null
let heartbeatPoller: HeartbeatPoller | null = null
let isShuttingDown = false
@@ -47,6 +48,7 @@ async function shutdown(signal: string): Promise<void> {
secretInformer?.stop()
channelSecretInformer?.stop()
+ llmHooksSecretInformer?.stop()
heartbeatPoller?.stop()
lifecycleTracker?.stop()
await provider?.stop()
@@ -219,6 +221,29 @@ async function main(): Promise<void> {
}
}
+ // Third SecretInformer: hook credential Secrets in the llm-hooks namespace.
+ // A rotation re-stamps the credentials-revision and rolls the hook pod
+ // (§8.2, mirroring the McpServer envSecret informer above).
+ if (!config.devMode && provider instanceof McpServerWatcher) {
+ const kc = getKubeConfig()
+ if (kc) {
+ const watcher = provider
+ llmHooksSecretInformer = new SecretInformer(kc, config.llmHooksNamespace, evt => {
+ watcher.reconcileLlmHookByEnvSecret(evt.name, evt.namespace).catch(err => {
+ console.error('[Main] reconcileLlmHookByEnvSecret failed:', err)
+ })
+ })
+ try {
+ await llmHooksSecretInformer.start()
+ console.log(
+ `[Main] llm-hooks SecretInformer started on namespace ${config.llmHooksNamespace}`
+ )
+ } catch (err) {
+ console.error('[Main] llm-hooks SecretInformer failed to start:', err)
+ }
+ }
+ }
+
console.log('\n[Main] Host Context Controller running. Press Ctrl+C to exit.\n')
// Handle graceful shutdown (use 'once' to prevent multiple handlers)