Skip to content

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

TypeScript

fix(control-api): emit the unverified-scope audit once the CR is persisted (F2-M1)

Diego Zacarias865d3d58b3c4
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 99e2da674..67f816c02 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.796",
+ "version": "0.1.797",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.796",
+ "version": "0.1.797",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",
diff --git a/control-api/package.json b/control-api/package.json
index 5be313c80..afe0530d1 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.796",
+ "version": "0.1.797",
"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/remoteMcp.ts b/control-api/src/routes/admin/remoteMcp.ts
index cbe8bc157..85d3e9d1f 100644
--- a/control-api/src/routes/admin/remoteMcp.ts
+++ b/control-api/src/routes/admin/remoteMcp.ts
@@ -1445,6 +1445,21 @@ export function createAdminRemoteMcpRouter(
}
throw err
}
+ if (unverifiedScopes.length > 0) {
+ // Audit trail of who vouched for a token audience the platform could not verify.
+ // Emitted as soon as the CR exists: a CR that outlives a failed later step or a
+ // failed rollback is used at runtime, and writing it counts as the confirmation.
+ // Scopes are not secret; this record exists to name them.
+ reqLog.info(
+ {
+ event: 'remote_install_unverified_scopes_confirmed',
+ serverName,
+ admin: req.adminAuth?.sub,
+ scopes: unverifiedScopes,
+ },
+ 'remote install: operator confirmed scopes whose API cannot be tied to the server'
+ )
+ }
// ── Saga step 2b (DCR only): bind the pending row to the created CR's uid ──
// Only DCR wrote a dynamic_clients row; other modes skip this. Binding seals the
@@ -1571,19 +1586,6 @@ export function createAdminRemoteMcpRouter(
},
'remote oauth mcp server installed'
)
- if (unverifiedScopes.length > 0) {
- // Audit trail of who vouched for a token audience the platform could not verify.
- // Scopes are not secret; this record exists to name them.
- reqLog.info(
- {
- event: 'remote_install_unverified_scopes_confirmed',
- serverName,
- admin: req.adminAuth?.sub,
- scopes: unverifiedScopes,
- },
- 'remote install: operator confirmed scopes whose API cannot be tied to the server'
- )
- }
// Names-only summary — never echo the secret material or the pinned tokens.
res.status(201).json({
diff --git a/control-api/test/routes.adminRemoteMcp.test.ts b/control-api/test/routes.adminRemoteMcp.test.ts
index cdb5b099f..2b07d52f1 100644
--- a/control-api/test/routes.adminRemoteMcp.test.ts
+++ b/control-api/test/routes.adminRemoteMcp.test.ts
@@ -2970,6 +2970,31 @@ describe('Microsoft Entra ID — remote install with scopes, scope audience and
})
})
+ it('row 14: the confirmation is audited once the CR exists, even if attach and its rollback fail', async () => {
+ const gw = gatewayWithContext()
+ vi.spyOn(gw, 'updateResource').mockRejectedValueOnce(new Error('attach boom'))
+ vi.spyOn(gw, 'deleteResource').mockRejectedValue(new Error('delete boom'))
+ const reqLog = { info: vi.fn(), warn: vi.fn(), error: vi.fn() }
+ const res = await entraInstall(
+ ENTRA_UNKNOWN_GUID_PILOT,
+ gw,
+ { scopes: [UNKNOWN_GUID_SCOPE], confirmedUnverifiedScopes: [UNKNOWN_GUID_SCOPE] },
+ { reqLog }
+ )
+ expect(res.status).toBe(500)
+ // The rollback failed, so the CR — and with it the confirmation — is live.
+ expect((await installedOauth(gw)).scopes).toEqual([UNKNOWN_GUID_SCOPE, 'offline_access'])
+ expect(reqLog.info).toHaveBeenCalledWith(
+ {
+ event: 'remote_install_unverified_scopes_confirmed',
+ serverName: 'workiq',
+ admin: 'admin-7',
+ scopes: [UNKNOWN_GUID_SCOPE],
+ },
+ expect.any(String)
+ )
+ })
+
it('row 13: a known GUID on its host needs no confirmation and leaves no audit record', async () => {
const gw = gatewayWithContext()
const reqLog = { info: vi.fn(), warn: vi.fn(), error: vi.fn() }