Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix: keep registry upgrades bound to live secret metadata
Alfredo Lopeze9876bbb7166
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex faefb55b7..b2ce7fe8d 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.502",+ "version": "0.1.503","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.502",+ "version": "0.1.503","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/image-policy": "file:../packages/image-policy",diff --git a/control-api/package.json b/control-api/package.jsonindex 072449e94..c60946ab6 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.502",+ "version": "0.1.503","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 279f7285f..7811fb949 100644--- a/control-api/src/routes/admin/registry.ts+++ b/control-api/src/routes/admin/registry.ts@@ -4067,7 +4067,11 @@ export function createAdminRegistryRouter(gateway?: K8sGateway): Router {'clerum.io/managed-by': 'control-api',},annotations: {- ...(previousSecretSnapshot?.annotations ?? {}),+ // Do not replay annotations from the preflight snapshot. The+ // SecretService reads the live object and preserves opaque+ // infrastructure/platform metadata that this writer does not+ // own. Replaying the old map would turn a concurrent metadata+ // update into a false 400 after preflight (R3-L1)....catalogAnnotations(body.registryEntryName, body.registryEntryVersion),[REGISTRY_SECRET_OPERATION_ID_ANNOTATION]: operationId,},diff --git a/control-api/test/routes.registryInstall.test.ts b/control-api/test/routes.registryInstall.test.tsindex 7ea2b7e4e..4953f295b 100644--- a/control-api/test/routes.registryInstall.test.ts+++ b/control-api/test/routes.registryInstall.test.ts@@ -3570,6 +3570,68 @@ describe('POST /admin/registry/upgrade', () => {expect(updateBody.metadata?.uid).toBe(before.metadata?.uid)})+ it('fails closed when live infrastructure metadata changes after credential preflight', async () => {+ vi.mocked(getEntryVersion).mockResolvedValueOnce(MOCK_ENTRY_V2 as any)+ vi.mocked(getCredentialSchema).mockResolvedValueOnce({+ required: true,+ authType: 'api-key',+ keys: [{ name: 'API_KEY' }],+ })+ const { app, gw } = makeApp()+ const secretName = 'my-srv-credentials'+ const credentialKey = ['API', 'KEY'].join('_')+ const annotationKey = 'kubectl.kubernetes.io/last-applied-configuration'+ const originalGetSecret = gw.getSecret.bind(gw)+ let raced = false++ gw.seedSecret(secretName, 'mcp-server', {+ type: 'Opaque',+ uid: 'uid-raced-credentials',+ resourceVersion: '1',+ annotations: { [annotationKey]: 'old-live-value' },+ data: { [credentialKey]: Buffer.from('old-value').toString('base64') },+ })+ vi.spyOn(gw, 'getSecret').mockImplementation(async (...args) => {+ const snapshot = await originalGetSecret(...args)+ if (args[0] === secretName && !raced) {+ raced = true+ gw.seedSecret(secretName, 'mcp-server', {+ type: 'Opaque',+ uid: 'uid-raced-credentials',+ resourceVersion: '2',+ annotations: { [annotationKey]: 'new-live-value' },+ data: { [credentialKey]: Buffer.from('old-value').toString('base64') },+ })+ }+ return snapshot+ })++ const res = await request(app)+ .post('/admin/registry/upgrade')+ .send({+ serverName: 'my-srv',+ registryEntryName: 'test-mcp',+ registryEntryVersion: '2.0.0',+ credentials: { [credentialKey]: 'new-value' },+ })+ .expect(409)++ expect(raced).toBe(true)+ expect(res.body.error).toContain('modified')+ expect(res.body.upgraded).toBeUndefined()+ await expect(gw.getSecret(secretName, 'mcp-server')).resolves.toMatchObject({+ metadata: {+ uid: 'uid-raced-credentials',+ resourceVersion: '2',+ annotations: { [annotationKey]: 'new-live-value' },+ },+ data: { [credentialKey]: Buffer.from('old-value').toString('base64') },+ })+ await expect(gw.getResource('mcpservers', 'my-srv', 'mcp-server')).resolves.toMatchObject({+ spec: { image: 'test:1.0' },+ })+ })+it('does not overwrite a same-name CR replacement with a new identity', async () => {vi.mocked(getEntryVersion).mockResolvedValueOnce(MOCK_ENTRY_V2 as any)const { app, gw } = makeApp()@@ -4734,9 +4796,7 @@ describe('POST /admin/registry/upgrade', () => {].map(code => String.fromCharCode(code)).join('')- expect(updateSecretSpy.mock.calls[0][0].annotations).toMatchObject({- [legacyApplyKey]: '{"old":"cfg"}',- })+ expect(updateSecretSpy.mock.calls[0][0].annotations).not.toHaveProperty(legacyApplyKey)expect(updateSecretSpy.mock.calls[1][0].annotations).toMatchObject({[legacyApplyKey]: '{"old":"cfg"}',})@@ -4786,9 +4846,7 @@ describe('POST /admin/registry/upgrade', () => {expect(res.body.error).toBe('upgrade conflict')expect(updateSecretSpy).toHaveBeenCalledTimes(2)- expect(updateSecretSpy.mock.calls[0][0].annotations).toMatchObject({- [futureKey]: futureValue,- })+ expect(updateSecretSpy.mock.calls[0][0].annotations).not.toHaveProperty(futureKey)expect(updateSecretSpy.mock.calls[1][0].annotations).toMatchObject({[futureKey]: futureValue,})