Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(control-api): derive the registry keys and grants auth gate
Jose Ramirez978fe6a468a7
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex 69c1f165e..eed550432 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.383",+ "version": "0.1.384","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.383",+ "version": "0.1.384","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 1b269f887..ce70f26db 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.383",+ "version": "0.1.384","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/registry.ts b/control-api/src/routes/admin/registry.tsindex 72ec9a41c..e87c523cf 100644--- a/control-api/src/routes/admin/registry.ts+++ b/control-api/src/routes/admin/registry.ts@@ -33,6 +33,7 @@ import {updateVersionMetadata,uploadArtifacts,} from '../../services/registryClient.js'+import { isRegistryAuthActive } from '../../services/registryConnectionDb.js'import {validateWorkflowRecipeEgressPreflight,validateWorkflowRecipeLimits,@@ -2165,7 +2166,7 @@ export function createAdminRegistryRouter(gateway?: K8sGateway): Router {req: Request,res: Response): Promise<{ admin: AdminUserRecord; orgName: string } | null> {- if (!config.registryAuthEnabled) {+ if (!(await isRegistryAuthActive())) {res.status(409).json({ error: 'registry_auth_disabled' })return null}@@ -2263,7 +2264,7 @@ export function createAdminRegistryRouter(gateway?: K8sGateway): Router {req: Request,res: Response): Promise<{ orgName: string; actingUserId: string } | null> {- if (!config.registryAuthEnabled) {+ if (!(await isRegistryAuthActive())) {res.status(409).json({ error: 'registry_auth_disabled' })return null}diff --git a/control-api/test/routes.adminRegistryGrants.test.ts b/control-api/test/routes.adminRegistryGrants.test.tsindex 272722668..159096afb 100644--- a/control-api/test/routes.adminRegistryGrants.test.ts+++ b/control-api/test/routes.adminRegistryGrants.test.ts@@ -53,7 +53,12 @@ vi.mock('../src/services/orgApiKeyClient.js', () => ({},}))vi.mock('../src/services/adminAuthService.js', () => ({ findAdminById: vi.fn() }))-const { cfg } = vi.hoisted(() => ({ cfg: { registryAuthEnabled: true } }))+// registryConnectionMode is required: the routes now call isRegistryAuthActive(),+// which branches on mode first. 'managed' makes it return registryAuthEnabled+// verbatim, which is the behaviour these tests intend to exercise.+const { cfg } = vi.hoisted(() => ({+ cfg: { registryAuthEnabled: true, registryConnectionMode: 'managed' },+}))vi.mock('../src/config.js', () => ({ config: cfg }))vi.mock('../src/services/rateLimiterService.js', () => ({checkAndIncrement: vi.fn(async () => ({diff --git a/control-api/test/routes.adminRegistryKeys.test.ts b/control-api/test/routes.adminRegistryKeys.test.tsindex 44803651a..dbea06d72 100644--- a/control-api/test/routes.adminRegistryKeys.test.ts+++ b/control-api/test/routes.adminRegistryKeys.test.ts@@ -39,8 +39,17 @@ vi.mock('../src/services/registryClient.js', () => ({resolvePublishScope: vi.fn(),}))vi.mock('../src/services/adminAuthService.js', () => ({ findAdminById: vi.fn() }))-const { cfg } = vi.hoisted(() => ({ cfg: { registryAuthEnabled: true } }))+// registryConnectionMode is required: the routes now call isRegistryAuthActive(),+// which branches on mode first. 'managed' makes it return registryAuthEnabled+// verbatim, which is the behaviour these tests intend to exercise.+const { cfg } = vi.hoisted(() => ({+ cfg: { registryAuthEnabled: true, registryConnectionMode: 'managed' },+}))vi.mock('../src/config.js', () => ({ config: cfg }))+// Narrow mock: registry.ts imports nothing else from registryConnectionDb, so+// stubbing only the accessor it now consumes is safe.+const connDb = vi.hoisted(() => ({ isRegistryAuthActive: vi.fn() }))+vi.mock('../src/services/registryConnectionDb.js', () => connDb)vi.mock('../src/services/rateLimiterService.js', () => ({checkAndIncrement: vi.fn(async () => ({allowed: true,@@ -65,6 +74,15 @@ function makeApp(adminId: string | null = 'admin-1') {beforeEach(() => {vi.clearAllMocks()cfg.registryAuthEnabled = true+ cfg.registryConnectionMode = 'managed'+ // Default mirrors the real accessor's managed-mode branch (registryAuthEnabled+ // verbatim) so the pre-existing tests below — which only flip+ // cfg.registryAuthEnabled, not this mock — still reach the same 200/409 they did+ // before this module was mocked. Reading cfg at call time (not a captured+ // literal) also means vi.clearAllMocks() can never silently freeze this to a+ // stale value. The self-hosted test overrides this per-call via+ // mockResolvedValue, independent of cfg.registryAuthEnabled.+ connDb.isRegistryAuthActive.mockImplementation(async () => cfg.registryAuthEnabled)vi.mocked(checkAndIncrement).mockResolvedValue({allowed: true,remaining: 29,@@ -98,6 +116,14 @@ describe('GET /admin/registry/keys', () => {expect(resolvePublishScope).not.toHaveBeenCalled()})+ it('self-hosted: keys work with NO auth env var once credentials exist', async () => {+ cfg.registryConnectionMode = 'self-hosted'+ cfg.registryAuthEnabled = false // deliberately off — must be ignored+ connDb.isRegistryAuthActive.mockResolvedValue(true) // credentials exist+ const res = await request(makeApp()).get('/admin/registry/keys')+ expect(res.status).not.toBe(409)+ })+it('401 when admin missing/inactive', async () => {vi.mocked(findAdminById).mockResolvedValue(null as never)const res = await request(makeApp()).get('/admin/registry/keys')