Skip to content

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

TypeScript

fix(control-api): close the whitespace hole and align the Slack target filter

Jose Ramirezc0afd1d60c8d
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 9b40bbd85..fe8a44aa0 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.437",
+ "version": "0.1.438",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.437",
+ "version": "0.1.438",
"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 513de4d55..8d342b02d 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.437",
+ "version": "0.1.438",
"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/resources.ts b/control-api/src/routes/admin/resources.ts
index 26033dfed..df401f419 100644
--- a/control-api/src/routes/admin/resources.ts
+++ b/control-api/src/routes/admin/resources.ts
@@ -266,7 +266,11 @@ async function providerTransitionError(
for (const provider of added) {
for (const key of PROVIDER_REQUIRED_KEYS[provider] || []) {
- if (!credentials?.[key] && !existingKeys.includes(key)) {
+ // Trimmed, because this reads the RAW envelope while the Secret is written
+ // from the CLEANED values: `validateCommunicationChannelCredentials` drops
+ // whitespace-only entries, so a truthy " " here would satisfy the guard
+ // and then never reach the Secret.
+ if (!credentials?.[key]?.trim() && !existingKeys.includes(key)) {
return `credentials["${key}"] is required to enable the ${provider} provider on this CommunicationChannel`
}
}
diff --git a/control-api/src/services/workflowApprovalMediumSlackVerificationService.ts b/control-api/src/services/workflowApprovalMediumSlackVerificationService.ts
index d69add4a7..19daf7dd3 100644
--- a/control-api/src/services/workflowApprovalMediumSlackVerificationService.ts
+++ b/control-api/src/services/workflowApprovalMediumSlackVerificationService.ts
@@ -65,6 +65,16 @@ export type SlackIdentity = {
const SLACK_WORKSPACE_ID_RE = /^T[A-Z0-9]+$/
+/**
+ * Keys a channel's credentials Secret must hold before it can serve Slack.
+ * Kept identical to `PROVIDER_REQUIRED_KEYS.slack` in
+ * `routes/admin/resources.ts`, which is the write-side gate: the picker must not
+ * offer a target the write path would have refused to create. Not imported from
+ * there — a service importing an admin route would invert the layering and
+ * close an import cycle.
+ */
+const SLACK_REQUIRED_SECRET_KEYS = ['slack-signing-secret', 'slack-bot-token']
+
function optionalString(value: unknown): string | null {
if (value === undefined || value === null) return null
const normalized = String(value).trim()
@@ -223,17 +233,28 @@ export async function listSlackApprovalTargets(params: {
if (!keysBySecret.has(cacheKey)) {
// Fails OPEN, unlike the write-path validator, and deliberately so: this
// is a read-only listing, and one channel with a broken or unreadable
- // Secret must not blank the user's entire verification picker.
+ // Secret must not blank the user's entire verification picker. Log the
+ // cause anyway: RBAC drift is a real condition on these clusters, and a
+ // target that silently vanishes from the picker is unreportable.
keysBySecret.set(
cacheKey,
- secretKeyNames(params.gateway, secretName, target.channelNamespace).catch(() => [])
+ secretKeyNames(params.gateway, secretName, target.channelNamespace).catch(error => {
+ console.warn(
+ `[WorkflowApprovalMedium] Slack target hidden: cannot read Secret "${cacheKey}": ${error instanceof Error ? error.message : String(error)}`
+ )
+ return []
+ })
)
}
const keys = await keysBySecret.get(cacheKey)!
// A channel can carry a Slack App Name while its Secret only ever held
// another provider's credentials. It projects as ready and then 409s on
// use, so it must not be offered as a target at all.
- return keys.includes('slack-signing-secret') ? target : null
+ //
+ // Both keys, matching PROVIDER_REQUIRED_KEYS.slack on the write path
+ // (routes/admin/resources.ts). Signing-secret-only would list a target
+ // that accepts events and then fails when the approval message is posted.
+ return SLACK_REQUIRED_SECRET_KEYS.every(key => keys.includes(key)) ? target : null
})
)
diff --git a/control-api/test/routes.providerTransition.test.ts b/control-api/test/routes.providerTransition.test.ts
index a38725d2d..5e87a1a89 100644
--- a/control-api/test/routes.providerTransition.test.ts
+++ b/control-api/test/routes.providerTransition.test.ts
@@ -104,6 +104,28 @@ describe('admin communicationchannels — provider transition validation (#312)'
expect(gatewayMock.createResource).not.toHaveBeenCalled()
})
+ it('POST declaring email with a whitespace-only credential → 400 naming the key', async () => {
+ // This guard reads the RAW envelope while the Secret is written from the
+ // CLEANED values, which drop whitespace-only entries. Untrimmed, " " is
+ // truthy here, `missingCreateCredentialKey` has no email branch to catch it,
+ // and the channel is created 201 advertising a provider whose Secret holds
+ // only email-password: exactly the #312 state, through the API.
+ const res = await request(makeApp())
+ .post('/admin/communicationchannels')
+ .send({
+ metadata: { name: 'jose-email' },
+ spec: { hostRef: 'h1', email: [{ emails: ['[email protected]'] }] },
+ credentials: { 'email-username': ' ', 'email-password': 'pw' },
+ })
+
+ expect(res.status).toBe(400)
+ expect(res.body.error).toBe(
+ 'credentials["email-username"] is required to enable the email provider on this CommunicationChannel'
+ )
+ expect(gatewayMock.createResource).not.toHaveBeenCalled()
+ expect(gatewayMock.createSecret).not.toHaveBeenCalled()
+ })
+
// ── ALLOWING ─────────────────────────────────────────────────────────────
// Without these, a validator that reads nothing at all still passes every
// blocking case above.
diff --git a/control-api/test/services.slackTargetFilter.test.ts b/control-api/test/services.slackTargetFilter.test.ts
index cc77f0f5d..ae00b98ce 100644
--- a/control-api/test/services.slackTargetFilter.test.ts
+++ b/control-api/test/services.slackTargetFilter.test.ts
@@ -30,6 +30,9 @@ function seedSecretKeys(namespace: string, name: string, keys: string[]): void {
secretKeys.set(`${namespace}/${name}`, keys)
}
+/** Both keys the write path requires before a channel may claim the Slack provider. */
+const WORKING_SLACK_KEYS = ['slack-signing-secret', 'slack-bot-token']
+
async function seedSlackChannel(
gateway: MockGateway,
options: {
@@ -79,7 +82,7 @@ describe('listSlackApprovalTargets Secret filtering', () => {
})
})
- it('lists a channel whose Secret holds a Slack signing secret', async () => {
+ it('lists a channel whose Secret holds both Slack keys', async () => {
const gateway = new MockGateway('channels')
await seedSlackChannel(gateway, { name: 'agent-a-slack' })
seedSecretKeys('channels', 'agent-a-slack-credentials', [
@@ -105,7 +108,7 @@ describe('listSlackApprovalTargets Secret filtering', () => {
const gateway = new MockGateway('channels')
await seedSlackChannel(gateway, { name: 'agent-a-slack' })
await seedSlackChannel(gateway, { name: 'agent-a-impostor' })
- seedSecretKeys('channels', 'agent-a-slack-credentials', ['slack-signing-secret'])
+ seedSecretKeys('channels', 'agent-a-slack-credentials', WORKING_SLACK_KEYS)
seedSecretKeys('channels', 'agent-a-impostor-credentials', ['telegram-bot-token'])
const targets = await listSlackApprovalTargets({ gateway: gateway as never, userId: 'user-1' })
@@ -113,6 +116,23 @@ describe('listSlackApprovalTargets Secret filtering', () => {
expect(targets.items.map(target => target.channelName)).toEqual(['agent-a-slack'])
})
+ it('hides a channel whose Secret holds the signing secret but no bot token', async () => {
+ // The picker filter and the write-path validator must agree on what "Slack
+ // works" means: PROVIDER_REQUIRED_KEYS.slack requires both keys. The signing
+ // secret only verifies INBOUND requests, so a half-configured channel is
+ // listed, accepts the events, and then fails when the approval message is
+ // posted through the Web API.
+ const gateway = new MockGateway('channels')
+ await seedSlackChannel(gateway, { name: 'agent-a-slack' })
+ await seedSlackChannel(gateway, { name: 'agent-a-half-configured' })
+ seedSecretKeys('channels', 'agent-a-slack-credentials', WORKING_SLACK_KEYS)
+ seedSecretKeys('channels', 'agent-a-half-configured-credentials', ['slack-signing-secret'])
+
+ const targets = await listSlackApprovalTargets({ gateway: gateway as never, userId: 'user-1' })
+
+ expect(targets.items.map(target => target.channelName)).toEqual(['agent-a-slack'])
+ })
+
it('never reads the Secret of a channel the caller cannot access', async () => {
// The ordering property. This endpoint lists communicationchannels across
// ALL namespaces and is gated only by a valid external session, so reading
@@ -128,8 +148,8 @@ describe('listSlackApprovalTargets Secret filtering', () => {
hostRef: 'agent-b',
users: ['user-2'],
})
- seedSecretKeys('channels', 'agent-a-slack-credentials', ['slack-signing-secret'])
- seedSecretKeys('other-tenant', 'agent-b-slack-credentials', ['slack-signing-secret'])
+ seedSecretKeys('channels', 'agent-a-slack-credentials', WORKING_SLACK_KEYS)
+ seedSecretKeys('other-tenant', 'agent-b-slack-credentials', WORKING_SLACK_KEYS)
const targets = await listSlackApprovalTargets({ gateway: gateway as never, userId: 'user-1' })
@@ -146,7 +166,7 @@ describe('listSlackApprovalTargets Secret filtering', () => {
const gateway = new MockGateway('channels')
await seedSlackChannel(gateway, { name: 'agent-a-slack-one', secretName: 'shared-credentials' })
await seedSlackChannel(gateway, { name: 'agent-a-slack-two', secretName: 'shared-credentials' })
- seedSecretKeys('channels', 'shared-credentials', ['slack-signing-secret'])
+ seedSecretKeys('channels', 'shared-credentials', WORKING_SLACK_KEYS)
const targets = await listSlackApprovalTargets({ gateway: gateway as never, userId: 'user-1' })
@@ -160,7 +180,7 @@ describe('listSlackApprovalTargets Secret filtering', () => {
const gateway = new MockGateway('channels')
await seedSlackChannel(gateway, { name: 'agent-a-slack' })
await seedSlackChannel(gateway, { name: 'agent-a-unreadable' })
- seedSecretKeys('channels', 'agent-a-slack-credentials', ['slack-signing-secret'])
+ seedSecretKeys('channels', 'agent-a-slack-credentials', WORKING_SLACK_KEYS)
// agent-a-unreadable-credentials is intentionally unseeded: the mock throws
// a 403 for it, the same shape secretKeyNames rethrows on an RBAC denial.
@@ -168,4 +188,23 @@ describe('listSlackApprovalTargets Secret filtering', () => {
expect(targets.items.map(target => target.channelName)).toEqual(['agent-a-slack'])
})
+
+ it('warns with the Secret ref and the cause when a target is dropped for an unreadable Secret', async () => {
+ // Failing open is right here, but silence is not: RBAC drift is a real
+ // condition on these clusters, and without this line a target disappears
+ // from the picker with nothing anywhere to say why.
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
+ const gateway = new MockGateway('channels')
+ await seedSlackChannel(gateway, { name: 'agent-a-unreadable' })
+
+ const targets = await listSlackApprovalTargets({ gateway: gateway as never, userId: 'user-1' })
+
+ expect(targets.items).toEqual([])
+ expect(warn).toHaveBeenCalledTimes(1)
+ expect(warn.mock.calls[0][0]).toBe(
+ '[WorkflowApprovalMedium] Slack target hidden: cannot read Secret ' +
+ '"channels/agent-a-unreadable-credentials": secrets "agent-a-unreadable-credentials" unreadable'
+ )
+ warn.mockRestore()
+ })
})