Skip to content

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

TypeScript

fix(secrets): harden CRD reference coverage

Alfredo Lopezf477e9551e2f
diff --git a/control-api/src/routes/admin/registry.ts b/control-api/src/routes/admin/registry.ts
index 7811fb949..6e42ee7bd 100644
--- a/control-api/src/routes/admin/registry.ts
+++ b/control-api/src/routes/admin/registry.ts
@@ -931,7 +931,7 @@ async function updateResourceWithConflictRetry(
} catch (err) {
if (extractK8sError(err)?.status !== 409) throw err
lastConflict = err
- if (attempt < UPDATE_CONFLICT_RETRY_ATTEMPTS) {
+ if (attempt < maxAttempts) {
await sleep(UPDATE_CONFLICT_RETRY_DELAY_MS * attempt)
}
}
diff --git a/control-api/src/services/secretReferenceService.ts b/control-api/src/services/secretReferenceService.ts
index 5dd63fb1a..4601e0be6 100644
--- a/control-api/src/services/secretReferenceService.ts
+++ b/control-api/src/services/secretReferenceService.ts
@@ -13,7 +13,7 @@ type ReferenceScope = {
secretNamespace: string
}
-const REFERENCE_SCOPES: ReferenceScope[] = [
+export const SECRET_REFERENCE_SCOPES = [
{
plural: 'mcpservers',
resourceNamespace: config.mcpServersNamespace,
@@ -39,20 +39,25 @@ const REFERENCE_SCOPES: ReferenceScope[] = [
resourceNamespace: config.communicationChannelsNamespace,
secretNamespace: config.communicationChannelsNamespace,
},
-]
+] as const satisfies readonly ReferenceScope[]
+
+const REFERENCE_SCOPES: readonly ReferenceScope[] = SECRET_REFERENCE_SCOPES
// Explicitly enumerate every Secret-bearing field in the deployed CRD schemas.
// A generic "*Ref" fallback would turn unrelated resource references into false
// dependencies and make compensation behavior implicit. Keep this list aligned
// with charts/clerum-crds/crds/{mcpserver,llmhook,workflowrecipe,communicationchannel,host}.yaml.
-const REFERENCE_KEYS = new Set([
+export const SECRET_REFERENCE_FIELDS = [
+ 'authHeadersSecret',
'credentialsSecretRef',
'envSecret',
'secretRef',
'imagePullSecrets',
'clientIdRef',
'clientSecretRef',
-])
+] as const
+
+const REFERENCE_KEYS: ReadonlySet<string> = new Set(SECRET_REFERENCE_FIELDS)
function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === 'object' && value !== null
diff --git a/control-api/test/crd.secretReferenceCoverage.test.ts b/control-api/test/crd.secretReferenceCoverage.test.ts
new file mode 100644
index 000000000..6bdea7a56
--- /dev/null
+++ b/control-api/test/crd.secretReferenceCoverage.test.ts
@@ -0,0 +1,92 @@
+import { describe, expect, it } from 'vitest'
+import { readFileSync, readdirSync } from 'node:fs'
+import { dirname, resolve } from 'node:path'
+import { fileURLToPath } from 'node:url'
+import { parse } from 'yaml'
+import {
+ SECRET_REFERENCE_FIELDS,
+ SECRET_REFERENCE_SCOPES,
+} from '../src/services/secretReferenceService.js'
+
+const crdsDir = resolve(dirname(fileURLToPath(import.meta.url)), '../../charts/clerum-crds/crds')
+
+type OpenApiSchema = {
+ description?: unknown
+ type?: unknown
+ properties?: unknown
+ items?: unknown
+ allOf?: unknown
+ anyOf?: unknown
+ oneOf?: unknown
+}
+
+function asRecord(value: unknown): Record<string, unknown> | undefined {
+ return value && typeof value === 'object' && !Array.isArray(value)
+ ? (value as Record<string, unknown>)
+ : undefined
+}
+
+function schemaDeclaresSecretReference(fieldName: string, schema: OpenApiSchema): boolean {
+ if (fieldName === 'imagePullSecrets') return true
+
+ const description = typeof schema.description === 'string' ? schema.description : ''
+ if (!/\bSecret\b/.test(description) || /secret.*key$/i.test(fieldName)) return false
+ if (/secret/i.test(fieldName)) return true
+ if (!fieldName.endsWith('Ref')) return false
+
+ const properties = asRecord(schema.properties)
+ return schema.type === 'string' || properties?.name !== undefined
+}
+
+function collectSecretReferenceFields(schema: unknown, fields: Set<string>): void {
+ const record = asRecord(schema)
+ if (!record) return
+
+ const properties = asRecord(record.properties)
+ if (properties) {
+ for (const [fieldName, value] of Object.entries(properties)) {
+ const fieldSchema = asRecord(value) as OpenApiSchema | undefined
+ if (fieldSchema && schemaDeclaresSecretReference(fieldName, fieldSchema)) {
+ fields.add(fieldName)
+ }
+ collectSecretReferenceFields(value, fields)
+ }
+ }
+
+ collectSecretReferenceFields(record.items, fields)
+ for (const branch of [record.allOf, record.anyOf, record.oneOf]) {
+ if (Array.isArray(branch)) branch.forEach(item => collectSecretReferenceFields(item, fields))
+ }
+}
+
+function collectCrdSecretReferences(): Array<{ plural: string; field: string }> {
+ const references: Array<{ plural: string; field: string }> = []
+ for (const file of readdirSync(crdsDir).filter(name => name.endsWith('.yaml')).sort()) {
+ const document = asRecord(parse(readFileSync(resolve(crdsDir, file), 'utf8')))
+ const crdName = asRecord(document?.metadata)?.name
+ const plural = typeof crdName === 'string' ? crdName.split('.', 1)[0] : undefined
+ const versions = asRecord(document?.spec)?.versions
+ if (!plural || !Array.isArray(versions)) throw new Error(`Invalid CRD schema: ${file}`)
+
+ const fields = new Set<string>()
+ for (const version of versions) {
+ const openApiSchema = asRecord(asRecord(asRecord(version)?.schema)?.openAPIV3Schema)
+ collectSecretReferenceFields(openApiSchema, fields)
+ }
+ for (const field of fields) references.push({ plural, field })
+ }
+ return references
+}
+
+describe('Secret reference CRD coverage', () => {
+ it('keeps every schema-declared Secret reference covered by the safety scanner', () => {
+ const references = collectCrdSecretReferences()
+
+ expect([...new Set(references.map(reference => reference.field))].sort()).toEqual(
+ [...SECRET_REFERENCE_FIELDS].sort()
+ )
+ expect([...new Set(references.map(reference => reference.plural))].sort()).toEqual(
+ [...new Set(SECRET_REFERENCE_SCOPES.map(scope => scope.plural))].sort()
+ )
+ })
+})
diff --git a/control-api/test/services.secretReferenceService.test.ts b/control-api/test/services.secretReferenceService.test.ts
index 3edf80884..f819b3e52 100644
--- a/control-api/test/services.secretReferenceService.test.ts
+++ b/control-api/test/services.secretReferenceService.test.ts
@@ -34,6 +34,11 @@ describe('findSecretReferenceState', () => {
plural: 'llmhooks',
resource: { spec: { target: { image: { imagePullSecrets: [referencedName] } } } },
},
+ {
+ namespace: config.llmHooksNamespace,
+ plural: 'llmhooks',
+ resource: { spec: { target: { remote: { authHeadersSecret: referencedName } } } },
+ },
]
for (const { namespace, plural, resource } of cases) {
diff --git a/control-api/test/services.secretService.test.ts b/control-api/test/services.secretService.test.ts
index 3a07e8032..49e796502 100644
--- a/control-api/test/services.secretService.test.ts
+++ b/control-api/test/services.secretService.test.ts
@@ -837,6 +837,23 @@ describe('SecretService — preserved Secret state is constrained before mutatio
})
})
+ it('preserves the catalog annotation pair during key removal', async () => {
+ const annotations = {
+ 'clerum.io/catalog-id': 'registry/example',
+ 'clerum.io/catalog-version': '1.2.3',
+ }
+ coreApi.readNamespacedSecret.mockResolvedValueOnce({
+ metadata: { annotations, resourceVersion: '14' },
+ type: 'Opaque',
+ })
+
+ await svc.removeSecretKey({ name: 's', namespace: 'test-ns', key: VALID_KEYS[0] })
+
+ const body = coreApi.patchNamespacedSecret.mock.calls[0][0].body
+ expect(body.data).toEqual({ [VALID_KEYS[0]]: null })
+ expect(body).not.toHaveProperty('metadata.annotations')
+ })
+
it('rejects update when an omitted type preserves a forbidden existing type', async () => {
coreApi.readNamespacedSecret.mockResolvedValueOnce({
metadata: {},
diff --git a/control-ui/components/EgressEditor.tsx b/control-ui/components/EgressEditor.tsx
index c30d91f75..ceb26a455 100644
--- a/control-ui/components/EgressEditor.tsx
+++ b/control-ui/components/EgressEditor.tsx
@@ -1,6 +1,6 @@
'use client'
-import React, { useEffect, useMemo, useRef, useState } from 'react'
+import React, { useEffect, useId, useMemo, useRef, useState } from 'react'
import {
MAX_EGRESS_BINDINGS,
buildMcpEgressStatus,
@@ -33,6 +33,10 @@ export function EgressEditor({
const [mode, setMode] = useState<EgressMode>(initial.mode)
const [domainInput, setDomainInput] = useState(initial.domainInput)
const [portInput, setPortInput] = useState(initial.portInput)
+ const egressEditorId = useId().replace(/:/g, '-')
+ const egressModeId = `egress-mode-${egressEditorId}`
+ const egressTargetId = `egress-target-${egressEditorId}`
+ const egressPortId = `egress-port-${egressEditorId}`
const skippedInitialEmitRef = useRef(false)
const onChangeRef = useRef(onChange)
@@ -67,11 +71,11 @@ export function EgressEditor({
<FormSection description={description} title={title}>
<Field
description="Default is closed. Choose exact-host for known APIs or public-web only when hosts are not deterministic."
- htmlFor="egress-mode"
+ htmlFor={egressModeId}
label="Egress mode"
>
<SelectInput
- id="egress-mode"
+ id={egressModeId}
onChange={event => setMode(event.target.value as EgressMode)}
value={mode}
>
@@ -97,11 +101,13 @@ export function EgressEditor({
<>
<Field
description="Comma- or newline-separated public DNS hostnames. Do not enter URLs, wildcards, IPs, or cluster-local names."
+ htmlFor={egressTargetId}
label="Allowed domains"
required
>
<textarea
className="cu-input cu-input--monospace"
+ id={egressTargetId}
onChange={event => setDomainInput(event.target.value)}
placeholder="api.example.com, auth.example.com"
rows={3}
@@ -110,10 +116,12 @@ export function EgressEditor({
</Field>
<Field
description="Comma- or newline-separated TCP ports."
+ htmlFor={egressPortId}
label="Allowed ports"
required
>
<TextInput
+ id={egressPortId}
monospace
onChange={event => setPortInput(event.target.value)}
placeholder="443"
@@ -127,11 +135,13 @@ export function EgressEditor({
<>
<Field
description="Comma- or newline-separated public IPv4 CIDRs or IPs. Private, metadata, link-local, documentation, multicast, and reserved ranges are blocked."
+ htmlFor={egressTargetId}
label="Allowed CIDRs/IPs"
required
>
<textarea
className="cu-input cu-input--monospace"
+ id={egressTargetId}
onChange={event => setDomainInput(event.target.value)}
placeholder="203.0.114.10/32, 8.8.8.8"
rows={3}
@@ -140,10 +150,12 @@ export function EgressEditor({
</Field>
<Field
description="Comma- or newline-separated TCP ports."
+ htmlFor={egressPortId}
label="Allowed ports"
required
>
<TextInput
+ id={egressPortId}
monospace
onChange={event => setPortInput(event.target.value)}
placeholder="443"
diff --git a/control-ui/components/__tests__/EgressEditor.test.tsx b/control-ui/components/__tests__/EgressEditor.test.tsx
new file mode 100644
index 000000000..80bed995d
--- /dev/null
+++ b/control-ui/components/__tests__/EgressEditor.test.tsx
@@ -0,0 +1,18 @@
+import { afterEach, describe, expect, it, vi } from 'vitest'
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+import { EgressEditor } from '../EgressEditor'
+
+afterEach(() => {
+ cleanup()
+})
+
+describe('EgressEditor', () => {
+ it('associates the exact-CIDR labels with their editable controls', () => {
+ render(<EgressEditor allowCidr onChange={vi.fn()} />)
+
+ fireEvent.change(screen.getByLabelText('Egress mode'), { target: { value: 'exact-cidr' } })
+
+ expect(screen.getByLabelText(/^Allowed CIDRs\/IPs/)).toBeInstanceOf(HTMLTextAreaElement)
+ expect(screen.getByLabelText(/^Allowed ports/)).toBeInstanceOf(HTMLInputElement)
+ })
+})
diff --git a/control-ui/e2e/qa-recorder-connector-edit.spec.ts b/control-ui/e2e/qa-recorder-connector-edit.spec.ts
index 257536cb6..2cf4fbc16 100644
--- a/control-ui/e2e/qa-recorder-connector-edit.spec.ts
+++ b/control-ui/e2e/qa-recorder-connector-edit.spec.ts
@@ -296,19 +296,14 @@ test.describe('optional QA recorder: Control UI connector edit', () => {
await expect(page.getByText(/Rotating credentials/)).toBeVisible({ timeout: 20_000 })
// This rotates to a VALID credential, so the connector must come back
- // healthy: the terminal state is SUCCESS. A bounded "did not finish
- // within" is tolerated as cluster slowness. But "Rotation failed:" is NOT
- // an acceptable outcome here — it would mean the UI reported the normal
- // transitory DeploymentReady=False/WaitingForReplicas as a failure (the
- // B1 defect). Accepting it (as this spec used to) let the bug pass in
- // green; asserting its absence makes the test catch a regression.
+ // healthy: the only acceptable terminal state is SUCCESS. A timeout or
+ // failure is diagnostic evidence, not a passing outcome.
// Must exceed the UI's own POLL_TIMEOUT_MS (180s): the "did not finish
// within" terminal message is only emitted at 180s, so a 150s assertion
// timeout would expire in the dead window (150s–180s) and fail spuriously
// on a slow-but-valid rollout. 185s clears it.
- await expect(
- page.getByText(/Credentials rotated\./).or(page.getByText(/did not finish within/))
- ).toBeVisible({ timeout: 185_000 })
+ await expect(page.getByText(/Credentials rotated\./)).toBeVisible({ timeout: 185_000 })
+ await expect(page.getByText(/did not finish within/)).toHaveCount(0)
await expect(page.getByText(/Rotation failed:/)).toHaveCount(0)
await screenshotAndLog(page, testInfo, 'control-ui-connector-credential-rotation')