Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(registry): guard boot-time connection read, close review gaps
Jose Ramirez376e3dc9ff5b
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex bf7ab7e22..80a33eaa3 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.389",+ "version": "0.1.390","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.389",+ "version": "0.1.390","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.jsonindex 7473ff6a4..a7e596286 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.389",+ "version": "0.1.390","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/src/registryBootGuard.ts b/control-api/src/registryBootGuard.tsindex 44c696ada..6734c8cae 100644--- a/control-api/src/registryBootGuard.ts+++ b/control-api/src/registryBootGuard.ts@@ -1,6 +1,7 @@import { config } from './config.js'import { rootLogger } from './observability/logger.js'import { getRegistryConnection } from './services/registryConnectionDb.js'+import type { RegistryConnectionRow } from './services/registryConnectionDb.js'/*** Boot-time observability for the self-hosted registry identity.@@ -16,13 +17,31 @@ import { getRegistryConnection } from './services/registryConnectionDb.js'* disappeared (bad restore, accidental delete). INFO rather than WARN so it* does not cry wolf on every first boot.*+ * The read itself is guarded separately: this now runs for every self-hosted+ * deployment on every boot (not just when auth was enabled), so a rotated+ * CLERUM_OAUTH_ENCRYPTION_KEY, a Postgres volume restored alongside a+ * different key Secret, or a transient pool blip can make getRegistryConnection+ * reject. That rejection must never escape — it would otherwise turn a+ * deployment that used to boot fine into a crashloop. WARN (not INFO) here,+ * because an unreadable row is a real operational problem, unlike a merely+ * absent one.+ ** Standalone module importing only config + logger + registryConnectionDb, so* its test does not pull in main.ts's server/cron graph.*/export async function logRegistryConnectionState(): Promise<void> {if (config.registryConnectionMode !== 'self-hosted') returnif (config.registryUrl === '') return- const row = await getRegistryConnection()+ let row: RegistryConnectionRow | null = null+ try {+ row = await getRegistryConnection()+ } catch (err) {+ rootLogger.warn(+ { event: 'registry_connection_state_unreadable', err: (err as Error).message },+ 'could not read the registry connection row at boot'+ )+ return+ }const connected = row?.clientId != nullrootLogger.info({ event: 'registry_connection_state', connected },diff --git a/control-api/test/main.selfHostedBootGuard.test.ts b/control-api/test/main.selfHostedBootGuard.test.tsindex 3fc4ac8e5..ce176effa 100644--- a/control-api/test/main.selfHostedBootGuard.test.ts+++ b/control-api/test/main.selfHostedBootGuard.test.ts@@ -37,6 +37,23 @@ describe('logRegistryConnectionState', () => {)})+ // A second deadlock regression guard, this time for the DB read itself. This+ // now runs on EVERY self-hosted boot (not gated behind+ // CLERUM_REGISTRY_AUTH_ENABLED), so getRegistryConnection rejecting — a+ // rotated CLERUM_OAUTH_ENCRYPTION_KEY, a restored Postgres volume paired with+ // a different key Secret, or a transient pool blip — must not escape as an+ // unhandled rejection. `.resolves` is the detector: a future change that+ // drops the try/catch fails this test with an unhandled rejection rather+ // than a clean assertion failure.+ it('does NOT throw when getRegistryConnection rejects', { retry: 0 }, async () => {+ connDb.getRegistryConnection.mockRejectedValue(new Error('decrypt failed'))+ await expect(logRegistryConnectionState()).resolves.toBeUndefined()+ expect(logger.rootLogger.warn).toHaveBeenCalledWith(+ expect.objectContaining({ event: 'registry_connection_state_unreadable' }),+ expect.any(String)+ )+ })+it('reports connected for a row holding client credentials', async () => {connDb.getRegistryConnection.mockResolvedValue({ status: 'connected', clientId: 'cid' })await expect(logRegistryConnectionState()).resolves.toBeUndefined()diff --git a/control-api/test/routes.adminRegistryKeys.test.ts b/control-api/test/routes.adminRegistryKeys.test.tsindex 7d23af578..cd85073ab 100644--- a/control-api/test/routes.adminRegistryKeys.test.ts+++ b/control-api/test/routes.adminRegistryKeys.test.ts@@ -120,8 +120,10 @@ describe('GET /admin/registry/keys', () => {cfg.registryConnectionMode = 'self-hosted'cfg.registryAuthEnabled = false // deliberately off — must be ignoredconnDb.isRegistryAuthActive.mockResolvedValue(true) // credentials exist+ vi.mocked(listKeys).mockResolvedValue({ keys: [{ id: 'k1' }] } as never)const res = await request(makeApp()).get('/admin/registry/keys')- expect(res.status).not.toBe(409)+ expect(res.status).toBe(200)+ expect(res.body).toEqual({ org: 'acme', keys: [{ id: 'k1' }] })})// isRegistryAuthActive() can now reject (self-hosted reaches a raw pool.querydiff --git a/control-api/test/services.registryConnectionDb.test.ts b/control-api/test/services.registryConnectionDb.test.tsindex 213b872e9..57f49ac84 100644--- a/control-api/test/services.registryConnectionDb.test.ts+++ b/control-api/test/services.registryConnectionDb.test.ts@@ -421,7 +421,15 @@ describe('getRegistryConnection — cache TTL', () => {const afterFirst = dbQuery.mock.calls.lengthawait getRegistryConnection()expect(dbQuery.mock.calls.length).toBe(afterFirst) // cache hit- vi.advanceTimersByTime(15_001)+ // Pin the TTL CONSTANT itself, not just its existence: 14_999ms elapsed+ // is still inside the 15_000ms window. Without this checkpoint, shrinking+ // CONNECTION_CACHE_TTL_MS to any smaller positive value would still pass+ // this test — the only two checks otherwise present (elapsed 0, elapsed+ // 15_001) cannot distinguish "TTL is 15_000" from "TTL is 1".+ vi.advanceTimersByTime(14_999)+ await getRegistryConnection()+ expect(dbQuery.mock.calls.length).toBe(afterFirst) // still cached+ vi.advanceTimersByTime(2) // total elapsed now 15_001await getRegistryConnection()expect(dbQuery.mock.calls.length).toBe(afterFirst + 1) // re-queried} finally {@@ -442,6 +450,15 @@ describe('getRegistryConnection — cache TTL', () => {await getRegistryConnection()await getRegistryConnection()expect(dbQuery.mock.calls.length).toBe(afterFirst)+ // The TTL must apply to a cached NULL exactly as it does to a cached row.+ // The three reads above all happen at elapsed 0, so a mutation that+ // special-cases `if (cached === null) return cached` ahead of the+ // `Date.now() - cachedAt < TTL` check would cache "never connected"+ // forever and this test would not catch it. Advancing past the TTL and+ // requiring a re-query does.+ vi.advanceTimersByTime(15_001)+ await getRegistryConnection()+ expect(dbQuery.mock.calls.length).toBe(afterFirst + 1) // re-queried} finally {vi.useRealTimers()}@@ -505,4 +522,33 @@ describe('isRegistryAuthActive', () => {})expect(await isRegistryAuthActive()).toBe(true)})++ // Discriminator pin: status and credential-presence deliberately disagree.+ // isRegistryAuthActive derives auth from resolveMachineCreds (credential+ // presence via clientId/clientSecret), never from row.status. Every fixture+ // above happens to have status and credential-presence pointing the same+ // way, so mutating the self-hosted branch to+ // `(await getRegistryConnection())?.status === 'connected'` would still pass+ // all of them. A 'pending' row that already holds real machine credentials+ // must still report auth ACTIVE — that combination is exactly what a+ // status-based implementation gets wrong.+ it('self-hosted: true for a pending-status row that already holds real credentials', async () => {+ cfg.registryConnectionMode = 'self-hosted'+ cfg.oauthEncryptionKey = randomBytes(32).toString('hex')+ const encSecret = encryptOAuthSecret(+ deriveOAuthEncryptionKey(cfg.oauthEncryptionKey),+ 'db-secret-abc'+ )+ dbQuery.mockResolvedValue({+ rows: [+ makeRawRow(cfg.oauthEncryptionKey, {+ status: 'pending',+ client_id: 'db-cid',+ client_secret_encrypted: encSecret,+ }),+ ],+ rowCount: 1,+ })+ expect(await isRegistryAuthActive()).toBe(true)+ })})diff --git a/control-ui/components/__tests__/RegistryConnectPanel.test.tsx b/control-ui/components/__tests__/RegistryConnectPanel.test.tsxindex 49bb8fac8..33d54e993 100644--- a/control-ui/components/__tests__/RegistryConnectPanel.test.tsx+++ b/control-ui/components/__tests__/RegistryConnectPanel.test.tsx@@ -177,39 +177,31 @@ describe('RegistryConnectPanel', () => {await waitFor(() => expect(screen.getByText('Disconnect')).toBeInTheDocument())})- // Regression guard: self-hosted derives auth from credential presence, so a- // real `connected` response always has authEnabled: true — this combination- // is unreachable in practice. The panel used to render an env-var banner for- // it; that banner is gone. Pin its absence so a future change cannot- // resurrect the old CLERUM_REGISTRY_AUTH_ENABLED guidance.- it('connected + authEnabled:false → shows no auth guidance (unreachable in practice)', async () => {- vi.mocked(api.getRegistryConnection).mockResolvedValue({- state: 'connected',- deploymentId: 'd',- org: 'acme',- authEnabled: false,- })- render(<RegistryConnectPanel />)- await waitFor(() =>- expect(screen.getByText(/Connected to the Evenfire Registry/)).toBeInTheDocument()- )- expect(screen.queryByText(/CLERUM_REGISTRY_AUTH_ENABLED/)).toBeNull()- expect(screen.queryByText(/enable registry authentication/i)).toBeNull()- })-- it('connected + authEnabled:true → does not show the enable-auth guidance', async () => {- vi.mocked(api.getRegistryConnection).mockResolvedValue({- state: 'connected',- deploymentId: 'd',- org: 'acme',- authEnabled: true,- })- render(<RegistryConnectPanel />)- await waitFor(() =>- expect(screen.getByText(/Connected to the Evenfire Registry/)).toBeInTheDocument()- )- expect(screen.queryByText(/enable registry authentication/i)).toBeNull()- })+ // Regression guard: the panel used to render an env-var banner+ // (CLERUM_REGISTRY_AUTH_ENABLED guidance) when connected without registry+ // auth active. That banner is gone entirely, so pin its absence for BOTH+ // authEnabled values, not just false. (Self-hosted derives auth from+ // credential presence, so a real `connected` response always has+ // authEnabled: true — connected + authEnabled:false is unreachable in+ // practice — but the assertion must hold under either value so a future+ // change cannot resurrect the old guidance behind just one of them.)+ it.each([false, true])(+ 'connected + authEnabled:%s → shows no auth guidance',+ async authEnabled => {+ vi.mocked(api.getRegistryConnection).mockResolvedValue({+ state: 'connected',+ deploymentId: 'd',+ org: 'acme',+ authEnabled,+ })+ render(<RegistryConnectPanel />)+ await waitFor(() =>+ expect(screen.getByText(/Connected to the Evenfire Registry/)).toBeInTheDocument()+ )+ expect(screen.queryByText(/CLERUM_REGISTRY_AUTH_ENABLED/)).toBeNull()+ expect(screen.queryByText(/enable registry authentication/i)).toBeNull()+ }+ )it('lands on the connected view when registration auto-claims', async () => {vi.mocked(api.getRegistryConnection).mockResolvedValue({ state: 'disconnected' })diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex 6d62431ec..497cc2ce7 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.359",+ "version": "0.1.360","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.359",+ "version": "0.1.360","dependencies": {"@clerum/llm-providers": "file:../packages/llm-providers","@clerum/workflow-recipe-capability-policy": "file:../packages/workflow-recipe-capability-policy",diff --git a/control-ui/package.json b/control-ui/package.jsonindex 5afbcdb83..eb9144e32 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.359",+ "version": "0.1.360","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",diff --git a/deploy/overlays/minikube/configmaps/control-api-config.yaml b/deploy/overlays/minikube/configmaps/control-api-config.yamlindex 2e1c12fd8..663027999 100644--- a/deploy/overlays/minikube/configmaps/control-api-config.yaml+++ b/deploy/overlays/minikube/configmaps/control-api-config.yaml@@ -60,10 +60,12 @@ data:# turns on by itself once the connect flow completes and this deployment# holds machine credentials: there is no flag to set and no restart needed.# To run your OWN in-cluster registry instead, set CLERUM_REGISTRY_URL to- # http://registry-api.registry.svc.cluster.local:8085 and add it via- # CLERUM_REGISTRY_URL_ALLOWLIST. The allowlist applies to any explicitly- # self-hosted deployment with a registry URL configured, regardless of- # whether auth is active.+ # http://registry-api.registry.svc.cluster.local:8085. That URL is already+ # built into the allowlist, so no CLERUM_REGISTRY_URL_ALLOWLIST entry is+ # needed for it; the setting is only for any OTHER registry URL. The+ # allowlist applies to any explicitly self-hosted deployment with a registry+ # URL configured, regardless of whether auth is active, and control-api+ # refuses to start if the configured URL is not allowlisted.CLERUM_REGISTRY_URL: 'https://registry.evenfire.ai'REGISTRY_CONNECTION_MODE: 'self-hosted'# The Publisher UI (Sidebar entry + /publisher route) defaults ON for everydiff --git a/docs/how-to/connect-to-registry.md b/docs/how-to/connect-to-registry.mdindex 0d419264d..0c48eaea5 100644--- a/docs/how-to/connect-to-registry.md+++ b/docs/how-to/connect-to-registry.md@@ -14,6 +14,10 @@ and use registry SSO from your Control UI.`managed`, and the connect flow only runs in self-hosted mode — a manageddeployment is connected automatically, so the panel has nothing to configure.- `CLERUM_REGISTRY_URL` set, with outbound HTTPS to the registry.+- `CLERUM_REGISTRY_URL` must be in the allowlist. `https://registry.evenfire.ai`+ and `http://registry-api.registry.svc.cluster.local:8085` are built in; add+ any other registry URL via `CLERUM_REGISTRY_URL_ALLOWLIST`. control-api+ refuses to start if the configured URL is not allowlisted.- You are an **admin** in your Control UI.## Connect