Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(pr-231): preserve names-only fixes and gate hardening
Alfredo Lopez892bc9151060
diff --cc control-api/package-lock.jsonindex e0697b7ef,e274676d8..86fb0fcd1--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@@ -1,14 -1,13 +1,14 @@@{"name": "clerum-control-api",- "version": "0.1.489",- "version": "0.1.399",++ "version": "0.1.490","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.489",- "version": "0.1.399",++ "version": "0.1.490","dependencies": {+ "@clerum/display-field": "file:../packages/display-field","@clerum/image-policy": "file:../packages/image-policy","@clerum/llm-providers": "file:../packages/llm-providers","@clerum/workflow-recipe-capability-policy": "file:../packages/workflow-recipe-capability-policy",diff --cc control-api/package.jsonindex ed0cabcc0,342e9df2e..9b05f4639--- a/control-api/package.json+++ b/control-api/package.json@@@ -1,6 -1,6 +1,6 @@@{"name": "clerum-control-api",- "version": "0.1.489",- "version": "0.1.399",++ "version": "0.1.490","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --cc control-api/src/routes/admin/communicationChannelCredentials.tsindex f8bc4b4e4,0248bc30c..a86fed956--- a/control-api/src/routes/admin/communicationChannelCredentials.ts+++ b/control-api/src/routes/admin/communicationChannelCredentials.ts@@@ -3,8 -3,6 +3,7 @@@ import { config } from '../../config.jsimport { asyncHandler } from '../../http/asyncHandler.js'import { enforceNamespace } from '../../http/namespaceAudit.js'import type { K8sGateway } from '../../k8s.js'+import { secretKeyNames } from '../../services/secretKeyNames.js'- import { toPublicSecretSummary } from '../../services/secretService.js'function ccCredentialsSecretName(ccName: string): string {return `cc-${ccName}-credentials`diff --cc control-api/src/services/secretService.tsindex fe7971b86,df3695a5b..8ed40554c--- a/control-api/src/services/secretService.ts+++ b/control-api/src/services/secretService.ts@@@ -1,56 -1,30 +1,61 @@@import * as k8s from '@kubernetes/client-node'-import { SecretUpsertRequest } from '../types.js'+import { SecretPreconditions, SecretUpsertRequest } from '../types.js'import { assertValidSecretDataKey, assertValidSecretWriteKeys } from './secretKeys.js'+ // A write-side summary of a Secret — NEVER carries `.data` values. Every admin+ // secret-write route echoes this, so secret values cannot leave the Secret store-// via an HTTP response body (mirrors the names-only policy in-// routes/admin/secrets.ts). Reads that legitimately need values use `getSecret`,++// via an HTTP response body. Reads that legitimately need values use `getSecret`,+ // which deliberately stays full-fat.export interface SecretSummary {name: stringnamespace: stringkeys: string[]- data?: never- stringData?: never}-// Trim a k8s write response to a names-only summary. `name`/`namespace` come from-// the request (always defined); `keys` from the returned Secret's data — for a-// merge-patch this is the merged WHOLE keyset, but still only NAMES, never values.+export interface DeleteSecretSummary {+ name: string+ namespace: string+ deleted: true+}++export function toPublicSecretSummary(summary: SecretSummary): SecretSummary {+ return {+ name: summary.name,+ namespace: summary.namespace,+ keys: [...summary.keys],+ }+}++export function toPublicDeleteSecretSummary(summary: DeleteSecretSummary): DeleteSecretSummary {+ return {+ name: summary.name,+ namespace: summary.namespace,+ deleted: true,+ }+}++type Assert<T extends true> = T+type HasExactKeys<T, Keys extends PropertyKey> =+ Exclude<keyof T, Keys> extends never+ ? Exclude<Keys, keyof T> extends never+ ? true+ : false+ : false++// Compile-time ratchet: adding `data`, `stringData`, or another field to either+// public write DTO fails the production typecheck.+type _SecretSummaryIsNamesOnly = Assert<HasExactKeys<SecretSummary, 'name' | 'namespace' | 'keys'>>+type _DeleteSecretSummaryIsNamesOnly = Assert<+ HasExactKeys<DeleteSecretSummary, 'name' | 'namespace' | 'deleted'>+>+- function summarizeSecret(result: k8s.V1Secret, name: string, namespace: string): SecretSummary {+ function summarizeSecret(result: unknown, name: string, namespace: string): SecretSummary {+ const data = (result as k8s.V1Secret | undefined)?.data- return {+ return toPublicSecretSummary({name,namespace,- keys: Object.keys(result.data ?? {}).sort((a, b) => a.localeCompare(b)),+ keys: Object.keys(data ?? {}).sort((a, b) => a.localeCompare(b)),- }+ })}export class SecretService {diff --cc control-api/test/routes.adminCommunicationChannelCredentials.test.tsindex c6fc3b4b6,06deb028f..33722490a--- a/control-api/test/routes.adminCommunicationChannelCredentials.test.ts+++ b/control-api/test/routes.adminCommunicationChannelCredentials.test.ts@@@ -239,17 -226,6 +239,13 @@@ describe('admin communicationchannels �.send({ 'telegram-bot-token': 'new-token' })expect(res.status).toBe(200)+ expect(res.body).toEqual({+ name: 'foo',+ secretName: 'cc-foo-credentials',+ namespace: 'channels',+ rotated: true,- result: {- name: 'cc-foo-credentials',- namespace: 'channels',- keys: ['telegram-bot-token'],- },++ rotatedKeys: ['telegram-bot-token'],+ })expect(gatewayMock.mergeSecret).toHaveBeenCalledWith(expect.objectContaining({name: 'cc-foo-credentials',diff --cc control-api/test/services.secretService.test.tsindex 10e8c569e,90f82148e..024bd78e8--- a/control-api/test/services.secretService.test.ts+++ b/control-api/test/services.secretService.test.ts@@@ -57,155 -271,6 +273,155 @@@ function createCoreApiMock(): CoreApiMo}}+const SENT_SECRET_VALUE = Buffer.from('caller-sent-value', 'utf8').toString('base64')+const ADJACENT_SECRET_VALUE = Buffer.from('adjacent-owner-value', 'utf8').toString('base64')+const RAW_WRITE_RESULT: k8s.V1Secret = {+ apiVersion: 'v1',+ kind: 'Secret',+ metadata: {+ name: 'credentials',+ namespace: 'channels',+ resourceVersion: '42',+ uid: 'uid-1',+ },+ type: 'Opaque',+ data: {+ 'caller-key': SENT_SECRET_VALUE,+ 'adjacent-owner-key': ADJACENT_SECRET_VALUE,+ },+}+- function expectNamesOnly(++function expectSecretSummaryNamesOnly(+ result: unknown,+ expected: { name: string; namespace: string; keys: string[] }+): void {+ expect(result).toEqual(expected)+ const serialized = JSON.stringify(result)+ expect(serialized).not.toContain(SENT_SECRET_VALUE)+ expect(serialized).not.toContain(ADJACENT_SECRET_VALUE)+ expect(result).not.toHaveProperty('data')+ expect(result).not.toHaveProperty('stringData')+}++describe('SecretService — write responses are names-only', () => {+ let coreApi: CoreApiMock+ let svc: SecretService++ beforeEach(() => {+ coreApi = createCoreApiMock()+ coreApi.createNamespacedSecret.mockResolvedValue(RAW_WRITE_RESULT)+ coreApi.readNamespacedSecret.mockResolvedValue(RAW_WRITE_RESULT)+ coreApi.replaceNamespacedSecret.mockResolvedValue(RAW_WRITE_RESULT)+ coreApi.patchNamespacedSecret.mockResolvedValue(RAW_WRITE_RESULT)+ svc = new SecretService(coreApi as unknown as k8s.CoreV1Api, 'default-ns')+ })++ it.each([+ [+ 'createSecret',+ () =>+ svc.createSecret({+ name: 'credentials',+ namespace: 'channels',+ stringData: { 'caller-key': 'caller-sent-value' },+ }),+ ],+ [+ 'updateSecret',+ () =>+ svc.updateSecret({+ name: 'credentials',+ namespace: 'channels',+ stringData: { 'caller-key': 'caller-sent-value' },+ }),+ ],+ [+ 'mergeSecret',+ () =>+ svc.mergeSecret({+ name: 'credentials',+ namespace: 'channels',+ stringData: { 'caller-key': 'caller-sent-value' },+ }),+ ],+ [+ 'removeSecretKey',+ () =>+ svc.removeSecretKey({+ name: 'credentials',+ namespace: 'channels',+ key: 'caller-key',+ }),+ ],+ ])('%s returns only identity and sorted key names', async (_operation, invoke) => {+ const result = await invoke()- expectNamesOnly(result, {++ expectSecretSummaryNamesOnly(result, {+ name: 'credentials',+ namespace: 'channels',+ keys: ['adjacent-owner-key', 'caller-key'],+ })+ })++ it('uses the default namespace in the write summary', async () => {+ coreApi.createNamespacedSecret.mockResolvedValue({+ ...RAW_WRITE_RESULT,+ metadata: { ...RAW_WRITE_RESULT.metadata, namespace: 'default-ns' },+ })+ const result = await svc.createSecret({+ name: 'credentials',+ stringData: { 'caller-key': 'caller-sent-value' },+ })+ expect((result as { namespace: string }).namespace).toBe('default-ns')+ })++ it('returns a names-only delete acknowledgement after the apiserver succeeds', async () => {+ const result = await svc.deleteSecret('credentials', 'channels', {+ uid: 'uid-1',+ resourceVersion: '42',+ })+ expect(result).toEqual({ name: 'credentials', namespace: 'channels', deleted: true })+ expect(coreApi.deleteNamespacedSecret.mock.calls[0][0].body.preconditions).toEqual({+ uid: 'uid-1',+ resourceVersion: '42',+ })+ })++ it('propagates delete failures instead of synthesizing success', async () => {+ coreApi.deleteNamespacedSecret.mockRejectedValueOnce(new Error('delete rejected'))+ await expect(svc.deleteSecret('credentials', 'channels')).rejects.toThrow('delete rejected')+ })++ it('omits annotations from the list projection', async () => {+ coreApi.listNamespacedSecret.mockResolvedValue({+ items: [+ {+ metadata: {+ name: 'credentials',+ namespace: 'channels',+ labels: { owner: 'platform' },+ annotations: { 'example.invalid/private': 'do-not-return' },+ },+ type: 'Opaque',+ data: { 'caller-key': SENT_SECRET_VALUE },+ },+ ],+ })++ const result = await svc.listSecrets('channels')+ expect(result).toEqual([+ {+ metadata: {+ name: 'credentials',+ namespace: 'channels',+ labels: { owner: 'platform' },+ },+ type: 'Opaque',+ keys: ['caller-key'],+ },+ ])+ })+})+describe('SecretService — invalid Secret keys never reach the apiserver', () => {let coreApi: CoreApiMocklet svc: SecretService