Skip to content

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

TypeScript

fix(control-api): match host channels by identifier not display (R1-H1)

Diego Zacarias7f100ed4a5ac
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/services/hostOverviewService.ts b/control-api/src/services/hostOverviewService.ts
index 8699fb176..f0f1d0b14 100644
--- a/control-api/src/services/hostOverviewService.ts
+++ b/control-api/src/services/hostOverviewService.ts
@@ -1,67 +1,72 @@
-import { HostOverview } from "../types.js";
-import { ResourceService } from "./resourceService.js";
+import { HostOverview } from '../types.js'
+import { ResourceService } from './resourceService.js'
export class HostOverviewService {
- constructor(private readonly resources: ResourceService, private readonly defaultNamespace: string) {}
+ constructor(
+ private readonly resources: ResourceService,
+ private readonly defaultNamespace: string
+ ) {}
async getHostOverview(hostName: string, namespace?: string): Promise<HostOverview> {
- const host = (await this.resources.getResource("hosts", hostName, namespace)) as {
- metadata?: { name?: string };
- spec?: { host?: string; contextRef?: string };
- };
+ const host = (await this.resources.getResource('hosts', hostName, namespace)) as {
+ metadata?: { name?: string }
+ spec?: { host?: string; contextRef?: string }
+ }
- const allChannels = (await this.resources.listResource("communicationchannels", "*")) as Array<{
+ const allChannels = (await this.resources.listResource('communicationchannels', '*')) as Array<{
spec?: {
- hostRef?: string;
- telegram?: Array<{ userIds?: string[] }>;
- email?: Array<{ emails?: string[] }>;
- slack?: Array<{ userNames?: string[] }>;
- };
- }>;
-
- const hostIdCandidates = new Set<string>(
- [hostName, host.spec?.host].filter((v): v is string => Boolean(v))
- );
+ hostRef?: string
+ telegram?: Array<{ userIds?: string[] }>
+ email?: Array<{ emails?: string[] }>
+ slack?: Array<{ userNames?: string[] }>
+ }
+ }>
- const communicationChannels = allChannels.filter((ch) =>
- hostIdCandidates.has(ch.spec?.hostRef || "")
- );
+ // A communication-channel's spec.hostRef is ALWAYS the host's RFC1123
+ // metadata.name (see the channel wizard / CRD schema), never the display
+ // name. Since PR #304 turned host.spec.host into an editable display label,
+ // it must NOT be used to match channels: a display that collides with
+ // another agent's metadata.name would surface that agent's channels — and
+ // their recipients (telegram userIds / emails / slack userNames aggregated
+ // below) — under the wrong agent. Match on the RFC1123 identifier only.
+ const communicationChannels = allChannels.filter(ch => (ch.spec?.hostRef || '') === hostName)
- let context = null as unknown;
- const contextRef = host.spec?.contextRef;
+ let context = null as unknown
+ const contextRef = host.spec?.contextRef
if (contextRef) {
try {
- context = await this.resources.getResource("contexts", contextRef, this.defaultNamespace);
+ context = await this.resources.getResource('contexts', contextRef, this.defaultNamespace)
} catch {
- const contexts = (await this.resources.listResource("contexts", "*")) as Array<{
- spec?: { contextId?: string };
- }>;
- context = contexts.find((c) => c.spec?.contextId === contextRef) || null;
+ const contexts = (await this.resources.listResource('contexts', '*')) as Array<{
+ spec?: { contextId?: string }
+ }>
+ context = contexts.find(c => c.spec?.contextId === contextRef) || null
}
}
- const allMcpServers = (await this.resources.listResource("mcpservers", "*")) as Array<{
- metadata?: { name?: string };
- }>;
+ const allMcpServers = (await this.resources.listResource('mcpservers', '*')) as Array<{
+ metadata?: { name?: string }
+ }>
const allowed = new Set<string>(
- ((context as { spec?: { mcpServers?: string[] } } | null)?.spec?.mcpServers || [])
- .filter((v): v is string => Boolean(v))
- );
- const mcpServers = allMcpServers.filter((s) => allowed.has(s.metadata?.name || ""));
+ ((context as { spec?: { mcpServers?: string[] } } | null)?.spec?.mcpServers || []).filter(
+ (v): v is string => Boolean(v)
+ )
+ )
+ const mcpServers = allMcpServers.filter(s => allowed.has(s.metadata?.name || ''))
- const telegramUserIds = new Set<string>();
- const emails = new Set<string>();
- const slackUserNames = new Set<string>();
+ const telegramUserIds = new Set<string>()
+ const emails = new Set<string>()
+ const slackUserNames = new Set<string>()
for (const ch of communicationChannels) {
for (const group of ch.spec?.telegram || []) {
- for (const id of group.userIds || []) telegramUserIds.add(id);
+ for (const id of group.userIds || []) telegramUserIds.add(id)
}
for (const group of ch.spec?.email || []) {
- for (const email of group.emails || []) emails.add(email);
+ for (const email of group.emails || []) emails.add(email)
}
for (const group of ch.spec?.slack || []) {
- for (const user of group.userNames || []) slackUserNames.add(user);
+ for (const user of group.userNames || []) slackUserNames.add(user)
}
}
@@ -75,6 +80,6 @@ export class HostOverviewService {
emails: [...emails].sort(),
slackUserNames: [...slackUserNames].sort(),
},
- };
+ }
}
}
diff --git a/control-api/test/services.hostOverviewCrossAgentChannel.test.ts b/control-api/test/services.hostOverviewCrossAgentChannel.test.ts
new file mode 100644
index 000000000..f9120693f
--- /dev/null
+++ b/control-api/test/services.hostOverviewCrossAgentChannel.test.ts
@@ -0,0 +1,103 @@
+import { describe, expect, it, vi } from 'vitest'
+import { HostOverviewService } from '../src/services/hostOverviewService.js'
+import { ResourceService } from '../src/services/resourceService.js'
+
+// R1-H1 (High) — cross-agent communication-channel leak in the admin overview.
+//
+// PR #304 turned host.spec.host from an RFC1123 identifier into an editable
+// display name. A communication-channel's spec.hostRef is still the host's
+// RFC1123 metadata.name (the channel wizard binds it to metadata.name). If the
+// overview matched channels against spec.host as well, an agent whose DISPLAY
+// name collides with ANOTHER agent's metadata.name would surface that other
+// agent's channels — and their recipients — under the wrong agent.
+//
+// Fixtures are derived from the REAL producers (T1): the real ResourceService
+// is driven through a customApi spy shaped exactly like @kubernetes/client-node
+// (getNamespacedCustomObject returns the object; listNamespacedCustomObject
+// returns { items }), and the real HostOverviewService consumes it. No layer is
+// hand-simulated.
+
+const NS = 'mcp-host'
+
+type Host = {
+ metadata: { name: string; namespace: string }
+ spec: { host?: string; contextRef?: string }
+}
+
+type Channel = {
+ metadata: { name: string; namespace: string }
+ spec: {
+ hostRef: string
+ telegram?: Array<{ userIds?: string[] }>
+ email?: Array<{ emails?: string[] }>
+ slack?: Array<{ userNames?: string[] }>
+ }
+}
+
+function buildOverviewService(hosts: Host[], channels: Channel[]): HostOverviewService {
+ const customApi = {
+ getNamespacedCustomObject: vi.fn(async ({ plural, name }: { plural: string; name: string }) => {
+ if (plural === 'hosts') {
+ const host = hosts.find(h => h.metadata.name === name)
+ if (host) return host
+ }
+ const err = new Error(`${plural}/${name} not found`) as Error & { statusCode: number }
+ err.statusCode = 404
+ throw err
+ }),
+ listNamespacedCustomObject: vi.fn(async ({ plural }: { plural: string }) => {
+ if (plural === 'communicationchannels') return { items: channels }
+ return { items: [] }
+ }),
+ }
+
+ const resources = new ResourceService(customApi as never, NS, {})
+ return new HostOverviewService(resources, NS)
+}
+
+describe('HostOverviewService — cross-agent communication-channel isolation (R1-H1)', () => {
+ // Agent A: metadata.name = "support" (owns the channel).
+ // Agent B: metadata.name = "sales", spec.host = "support" (display collides
+ // with A's metadata.name).
+ // Channel: spec.hostRef = "support" (bound to A's RFC1123 identifier).
+ const hosts: Host[] = [
+ { metadata: { name: 'support', namespace: NS }, spec: {} },
+ { metadata: { name: 'sales', namespace: NS }, spec: { host: 'support' } },
+ ]
+ const channels: Channel[] = [
+ {
+ metadata: { name: 'support-telegram', namespace: NS },
+ spec: {
+ hostRef: 'support',
+ telegram: [{ userIds: ['tg-secret-A'] }],
+ email: [{ emails: ['[email protected]'] }],
+ slack: [{ userNames: ['slack-A'] }],
+ },
+ },
+ ]
+
+ it('does NOT surface agent A’s channel under agent B whose display name collides', async () => {
+ const service = buildOverviewService(hosts, channels)
+
+ const overview = await service.getHostOverview('sales', NS)
+ const observed = overview.communicationChannels as Array<{ spec?: { hostRef?: string } }>
+
+ // Observable output (T4): the list the admin sees must not contain A's channel.
+ expect(observed.map(ch => ch.spec?.hostRef)).not.toContain('support')
+ expect(observed).toHaveLength(0)
+ // And none of A's recipients leak into B's aggregated access summary.
+ expect(overview.accessSummary.telegramUserIds).not.toContain('tg-secret-A')
+ expect(overview.accessSummary.emails).not.toContain('[email protected]')
+ expect(overview.accessSummary.slackUserNames).not.toContain('slack-A')
+ })
+
+ it('still surfaces the channel under agent A (its real RFC1123 owner)', async () => {
+ const service = buildOverviewService(hosts, channels)
+
+ const overview = await service.getHostOverview('support', NS)
+ const observed = overview.communicationChannels as Array<{ spec?: { hostRef?: string } }>
+
+ expect(observed.map(ch => ch.spec?.hostRef)).toEqual(['support'])
+ expect(overview.accessSummary.telegramUserIds).toEqual(['tg-secret-A'])
+ })
+})