Skip to content

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

TypeScript

fix(control-api): kill a vacuous assertion, reserve the name on the secrets router

Jose Ramirezdae824abacf8
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index df73d708a..29fd2274d 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.405",
+ "version": "0.1.406",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.405",
+ "version": "0.1.406",
"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 d20bbae0a..7d51e6fb2 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.405",
+ "version": "0.1.406",
"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/recipes.ts b/control-api/src/routes/admin/recipes.ts
index 2167d5807..78fcfcc06 100644
--- a/control-api/src/routes/admin/recipes.ts
+++ b/control-api/src/routes/admin/recipes.ts
@@ -1849,22 +1849,25 @@ export function createAdminRecipesRouter(gateway: K8sGateway): Router {
return
}
const pendingCredentials = workflowSecretResult.pendingCredentials
- // Same guard as create: an update is how a recipe FIRST acquires a platform image
- // (edit the workload's image, keep the name), and the stored CRD is what WRC
- // reconciles. Provision before the write, never after — a failure must leave the
- // persisted recipe as it was.
- if (recipeReferencesPlatformImage(body.spec ?? {})) {
- try {
- await ensureRegistryPullSecrets(gateway, platformWorkloadNamespaces())
- } catch (err) {
- const mapped = pullSecretErrorResponse(err)
- res.status(mapped.status).json(mapped.body)
- return
- }
- }
// Discover the canonical recipe resource and update it in sandbox-recipes.
try {
const { ns, resource } = await findRecipeNamespace(req.params.name)
+ // Same guard as create: an update is how a recipe FIRST acquires a platform image
+ // (edit the workload's image, keep the name), and the stored CRD is what WRC
+ // reconciles. Provision AFTER the existence lookup, so a PUT naming a recipe that
+ // does not exist 404s without minting — the mint is rotate-on-call, and it would
+ // revoke the org key every other namespace's Secret is already carrying. And
+ // before the write, never after — a failure must leave the persisted recipe as
+ // it was.
+ if (recipeReferencesPlatformImage(body.spec ?? {})) {
+ try {
+ await ensureRegistryPullSecrets(gateway, platformWorkloadNamespaces())
+ } catch (provisionErr) {
+ const mapped = pullSecretErrorResponse(provisionErr)
+ res.status(mapped.status).json(mapped.body)
+ return
+ }
+ }
const currentLabels = isPlainObject(resource)
? stringLabels(isPlainObject(resource.metadata) ? resource.metadata.labels : undefined)
: undefined
diff --git a/control-api/src/routes/admin/secrets.ts b/control-api/src/routes/admin/secrets.ts
index 82be1e0d4..cf9529bd5 100644
--- a/control-api/src/routes/admin/secrets.ts
+++ b/control-api/src/routes/admin/secrets.ts
@@ -1,5 +1,6 @@
import { Router } from 'express'
import { PROVIDER_CREDENTIAL_SLOTS } from '@clerum/llm-providers'
+import { EVENFIRE_REGISTRY_PULL_SECRET_NAME } from '@clerum/workflow-runtime-core'
import { config } from '../../config.js'
import { asyncHandler } from '../../http/asyncHandler.js'
import { enforceNamespace } from '../../http/namespaceAudit.js'
@@ -31,6 +32,23 @@ const VERTEX_SERVICE_ACCOUNT_KEY: string = PROVIDER_CREDENTIAL_SLOTS.vertex[0].d
const RECIPE_SECRET_LABEL_KEY = 'clerum.io/recipe-secret'
const RECIPE_SECRET_LABEL_VALUE = 'true'
+// `evenfire-registry-pull` is control-api's own image-pull credential, self-provisioned
+// into every platform workload namespace (registryPullSecretService). The mcp-secret and
+// recipe-secret routes below write into that SAME set of namespaces, so the name is
+// reachable from here — and the damage is not recoverable in place: the provisioner's
+// first invariant is "never write a Secret we do not own", so an operator who deletes the
+// platform Secret and creates an `Opaque` one under the reserved name makes every
+// private-image install into that namespace fail with `foreign_secret_unusable`, forever.
+// Reserve the name on the write and delete surfaces, exactly as the recipe surfaces do
+// (`isPlatformManagedWorkflowSecretName` in routes/admin/recipes.ts).
+function isPlatformManagedSecretName(name: unknown): boolean {
+ return typeof name === 'string' && name.trim() === EVENFIRE_REGISTRY_PULL_SECRET_NAME
+}
+
+const PLATFORM_MANAGED_SECRET_ERROR =
+ `Secret "${EVENFIRE_REGISTRY_PULL_SECRET_NAME}" is platform-managed (the evenfire ` +
+ 'registry image-pull credential) and cannot be created, modified, or deleted here'
+
// The plaintext data being written, merging base64 `data` and plaintext
// `stringData` (stringData wins, matching Kubernetes Secret semantics).
function effectiveSecretData(body: unknown): Record<string, string> {
@@ -318,6 +336,10 @@ export function createAdminSecretsRouter(gateway: K8sGateway): Router {
})
return
}
+ if (isPlatformManagedSecretName(name)) {
+ res.status(400).json({ error: PLATFORM_MANAGED_SECRET_ERROR })
+ return
+ }
if (!data || typeof data !== 'object' || Object.keys(data).length === 0) {
res
.status(400)
@@ -506,6 +528,12 @@ export function createAdminSecretsRouter(gateway: K8sGateway): Router {
'/admin/mcp-secrets/:name',
enforceNamespace(config.mcpServersNamespace),
asyncHandler(async (req, res) => {
+ // This route deletes by name with no ownership guard, so the reserved name is the
+ // only thing standing between a rollback call and the platform pull credential.
+ if (isPlatformManagedSecretName(req.params.name)) {
+ res.status(400).json({ error: PLATFORM_MANAGED_SECRET_ERROR })
+ return
+ }
const deleted = await gateway.deleteSecret(req.params.name, config.mcpServersNamespace)
res.status(200).json(deleted)
})
@@ -691,6 +719,10 @@ export function createAdminSecretsRouter(gateway: K8sGateway): Router {
})
return
}
+ if (isPlatformManagedSecretName(name)) {
+ res.status(400).json({ error: PLATFORM_MANAGED_SECRET_ERROR })
+ return
+ }
if (!data || typeof data !== 'object' || Object.keys(data).length === 0) {
res
.status(400)
diff --git a/control-api/test/routes.adminRecipes.pullSecret.test.ts b/control-api/test/routes.adminRecipes.pullSecret.test.ts
index 52783537b..adab100c1 100644
--- a/control-api/test/routes.adminRecipes.pullSecret.test.ts
+++ b/control-api/test/routes.adminRecipes.pullSecret.test.ts
@@ -17,7 +17,11 @@ import request from 'supertest'
import { config } from '../src/config.js'
import { createAdminRecipesRouter } from '../src/routes/admin/recipes.js'
import { EVENFIRE_REGISTRY_PULL_SECRET_NAME } from '../src/routes/admin/registryImagePullSecret.js'
-import { mintOrgPullCredential, resolvePublishScope } from '../src/services/registryClient.js'
+import {
+ RegistryProxyError,
+ mintOrgPullCredential,
+ resolvePublishScope,
+} from '../src/services/registryClient.js'
import { isRegistryAuthActive } from '../src/services/registryConnectionDb.js'
import { MockGateway } from './mockGateway.js'
@@ -134,6 +138,28 @@ describe('POST /admin/recipes — pull-secret provisioning (self-hosted)', () =>
})
await expect(gateway.getResource('workflowrecipes', 'plat', SANDBOX_NS)).rejects.toBeTruthy()
})
+
+ it('maps a registry rejection to 502 registry_rejected, not a bare 500', async () => {
+ // The mint endpoint 403s when the registry has not been upgraded to support tenant
+ // pull-credential minting, or this deployment lacks `registry:manage-keys`. That is a
+ // deploy-ordering problem the operator can act on — collapsing it into a generic 500
+ // (which is what a plain K8s-error mapping does, since it cannot read
+ // RegistryProxyError.status) makes it look like a control-api bug.
+ vi.mocked(mintOrgPullCredential).mockRejectedValue(
+ new RegistryProxyError(403, { error: 'forbidden' })
+ )
+ const gateway = new MockGateway(MCP_NS)
+
+ const res = await request(makeApp(gateway)).post('/admin/recipes').send(platformRecipe('plat'))
+
+ expect(res.status).toBe(502)
+ expect(res.body).toMatchObject({
+ error: 'registry_pull_secret_provision_failed',
+ reason: 'registry_rejected',
+ upstreamStatus: 403,
+ })
+ await expect(gateway.getResource('workflowrecipes', 'plat', SANDBOX_NS)).rejects.toBeTruthy()
+ })
})
describe('PUT /admin/recipes/:name — pull-secret provisioning (self-hosted)', () => {
@@ -165,6 +191,20 @@ describe('PUT /admin/recipes/:name — pull-secret provisioning (self-hosted)',
}
})
+ it('mints NOTHING for a PUT naming a recipe that does not exist', async () => {
+ const gateway = new MockGateway(MCP_NS)
+
+ const res = await request(makeApp(gateway))
+ .put('/admin/recipes/ghost')
+ .send({ spec: platformRecipe('ghost').spec })
+
+ // The mint is rotate-on-call — it revokes the org's previous key. A request that was
+ // always going to 404 must not spend one, or it strands every namespace already
+ // holding a Secret built from the key it just replaced.
+ expect(res.status).toBe(404)
+ expect(mintOrgPullCredential).not.toHaveBeenCalled()
+ })
+
it('provisions nothing when the update keeps a third-party image', async () => {
const gateway = new MockGateway(MCP_NS)
await seedForeignRecipe(gateway, 'ext')
diff --git a/control-api/test/routes.adminRecipes.test.ts b/control-api/test/routes.adminRecipes.test.ts
index f8e7255c5..98d105ff8 100644
--- a/control-api/test/routes.adminRecipes.test.ts
+++ b/control-api/test/routes.adminRecipes.test.ts
@@ -1654,6 +1654,26 @@ describe.sequential('routes/admin/recipes', () => {
).rejects.toThrow()
})
+ it('POST /admin/recipes/secrets — refuses a pull-secret-shaped payload', async () => {
+ // This route writes `type: Opaque`, and the kubelet honors ONLY
+ // kubernetes.io/dockerconfigjson (or .dockercfg) for image pulls. Storing the key on an
+ // Opaque Secret would be accepted here and then SILENTLY ignored at pull time — an
+ // unexplained ImagePullBackOff long after the 201 that caused it.
+ for (const key of ['.dockerconfigjson', '.dockercfg']) {
+ const res = await request(app)
+ .post('/admin/recipes/secrets')
+ .send({
+ name: 'third-party-pull',
+ ownership: { kind: 'owner-recipe', recipeName: 'snippet-secret-recipe' },
+ stringData: { [key]: '{"auths":{}}' },
+ })
+ .expect(400)
+
+ expect(res.body.error).toMatch(/Kubernetes ignores for image pulls/)
+ await expect(gateway.getSecret('third-party-pull', SANDBOX_NS)).rejects.toThrow()
+ }
+ })
+
it('POST /admin/recipes/secrets — rejects invalid keys and non-string values', async () => {
await request(app)
.post('/admin/recipes/secrets')
diff --git a/control-api/test/routes.registryInstall.pullSecret.test.ts b/control-api/test/routes.registryInstall.pullSecret.test.ts
index 019af230b..43e38f6ca 100644
--- a/control-api/test/routes.registryInstall.pullSecret.test.ts
+++ b/control-api/test/routes.registryInstall.pullSecret.test.ts
@@ -272,6 +272,27 @@ describe('POST /admin/registry/install-recipe — pull-secret provisioning (self
}
})
+ it('provisions BEFORE persisting the WorkflowRecipe CRD', async () => {
+ vi.mocked(getEntryVersion).mockResolvedValueOnce(
+ recipeEntry(`${REGISTRY_HOST}/acme/plugin:1.0`) as never
+ )
+ const { app, gw } = makeInstallApp()
+ // Spy AFTER the fixture context is seeded, so only route writes are recorded.
+ const createResource = vi.spyOn(gw, 'createResource')
+
+ await request(app).post('/admin/registry/install-recipe').send(recipeBody()).expect(201)
+
+ // Ordering is the point: a CRD persisted first would reference a Secret that does not
+ // exist yet, and a provisioning failure after the write leaves it stranded.
+ const recipeWrite = createResource.mock.calls.findIndex(
+ ([plural]) => plural === 'workflowrecipes'
+ )
+ expect(recipeWrite).toBeGreaterThanOrEqual(0)
+ expect(vi.mocked(mintOrgPullCredential).mock.invocationCallOrder[0]).toBeLessThan(
+ createResource.mock.invocationCallOrder[recipeWrite]
+ )
+ })
+
it('does not provision for a recipe with no platform-registry image', async () => {
vi.mocked(getEntryVersion).mockResolvedValueOnce(
recipeEntry('ghcr.io/acme/plugin:1.0') as never
@@ -297,6 +318,12 @@ describe('POST /admin/registry/install-recipe — pull-secret provisioning (self
expect(res.status).toBeGreaterThanOrEqual(500)
expect(res.body.error).toBe('registry_pull_secret_provision_failed')
// No WorkflowRecipe may be persisted referencing a credential that does not exist.
- await expect(gw.getResource('workflowrecipes', 'intel-report', NS)).rejects.toBeTruthy()
+ // Assert on the persisted SET, not on a guessed name: the route derives the CRD name
+ // (`recipe-<entry>-v<version>-<hash>`), so a by-name lookup 404s whether the route
+ // wrote something or nothing — an assertion that cannot fail.
+ const persisted = (await gw.listResource('workflowrecipes', '*')) as Array<{
+ metadata: { name: string }
+ }>
+ expect(persisted.map(r => r.metadata.name)).toEqual([])
})
})
diff --git a/control-api/test/routes.secrets.platformPullSecretName.test.ts b/control-api/test/routes.secrets.platformPullSecretName.test.ts
new file mode 100644
index 000000000..b26c1c23c
--- /dev/null
+++ b/control-api/test/routes.secrets.platformPullSecretName.test.ts
@@ -0,0 +1,96 @@
+/**
+ * The reserved platform Secret name, on the mcp-secret / recipe-secret surfaces.
+ *
+ * `evenfire-registry-pull` is control-api's own image-pull credential, self-provisioned
+ * into every platform workload namespace. These routes write into that SAME set of
+ * namespaces (`RECIPE_SECRET_NAMESPACES` is set-identical to `platformWorkloadNamespaces()`),
+ * so the name is reachable from here — and squatting it is unrepairable: the provisioner
+ * refuses to overwrite a Secret it does not own, so a foreign `Opaque` object under the
+ * reserved name makes every private-image install into that namespace 409 permanently.
+ *
+ * The recipe routes in `routes/admin/recipes.ts` already reserve the name; these three did
+ * not. The DELETE is the sharp one — it deletes by name with no ownership guard at all.
+ */
+import { describe, expect, it, vi } from 'vitest'
+import express from 'express'
+import request from 'supertest'
+import { EVENFIRE_REGISTRY_PULL_SECRET_NAME } from '@clerum/workflow-runtime-core'
+import { createAdminSecretsRouter } from '../src/routes/admin/secrets.js'
+
+function createGateway() {
+ return {
+ listSecrets: vi.fn(async () => []),
+ listResource: vi.fn(async () => [] as unknown[]),
+ getSecret: vi.fn(async () => null),
+ createSecret: vi.fn(async (body: unknown) => body),
+ updateSecret: vi.fn(async (body: unknown) => body),
+ deleteSecret: vi.fn(async (_name: string, _namespace?: string) => ({ deleted: true })),
+ }
+}
+
+function makeApp(gateway: ReturnType<typeof createGateway>) {
+ const app = express()
+ app.use(express.json())
+ app.use(createAdminSecretsRouter(gateway as never))
+ app.use(
+ (err: unknown, _req: express.Request, res: express.Response, _next: express.NextFunction) => {
+ res.status(500).json({ error: err instanceof Error ? err.message : 'unknown' })
+ }
+ )
+ return app
+}
+
+describe('platform-managed Secret name is reserved', () => {
+ it('POST /admin/recipe-secrets refuses the reserved name and writes nothing', async () => {
+ const gateway = createGateway()
+
+ const res = await request(makeApp(gateway))
+ .post('/admin/recipe-secrets')
+ .send({
+ name: EVENFIRE_REGISTRY_PULL_SECRET_NAME,
+ data: { token: 'squat' },
+ ownership: { kind: 'shared' },
+ targetNamespace: 'mcp-server',
+ })
+ .expect(400)
+
+ expect(res.body.error).toMatch(/platform-managed/)
+ expect(gateway.createSecret).not.toHaveBeenCalled()
+ })
+
+ it('POST /admin/mcp-secrets refuses the reserved name and writes nothing', async () => {
+ const gateway = createGateway()
+
+ const res = await request(makeApp(gateway))
+ .post('/admin/mcp-secrets')
+ .send({ name: EVENFIRE_REGISTRY_PULL_SECRET_NAME, data: { token: 'squat' } })
+ .expect(400)
+
+ expect(res.body.error).toMatch(/platform-managed/)
+ expect(gateway.createSecret).not.toHaveBeenCalled()
+ })
+
+ it('DELETE /admin/mcp-secrets/:name refuses the reserved name and deletes nothing', async () => {
+ const gateway = createGateway()
+
+ const res = await request(makeApp(gateway))
+ .delete(`/admin/mcp-secrets/${EVENFIRE_REGISTRY_PULL_SECRET_NAME}`)
+ .expect(400)
+
+ expect(res.body.error).toMatch(/platform-managed/)
+ expect(gateway.deleteSecret).not.toHaveBeenCalled()
+ })
+
+ it('still deletes an ordinary connector Secret whose name merely resembles it', async () => {
+ const gateway = createGateway()
+
+ await request(makeApp(gateway))
+ .delete(`/admin/mcp-secrets/${EVENFIRE_REGISTRY_PULL_SECRET_NAME}-backup`)
+ .expect(200)
+
+ expect(gateway.deleteSecret).toHaveBeenCalledWith(
+ `${EVENFIRE_REGISTRY_PULL_SECRET_NAME}-backup`,
+ 'mcp-server'
+ )
+ })
+})