From 254c2a9b06dc33b28e6201f687a378dd7d1712db Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Thu, 19 Nov 2026 06:58:22 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=93=20fix:=20Keep=20`owner`=20as=20the?= =?UTF-8?q?=20Default=20Mode=20for=20API=20Key=20Runs=20(#18448)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #18377 made `delegated` the default of endpoints.agents.remoteApi.integrations.mode, so on upgrade a run started with a personal API key lost its MCP tools until the operator declared servers and the key's owner granted them. That is a surprise for deployments that never asked for grants. The default is `owner` again: a key run uses the MCP servers its owner can, as before grants existed. `delegated` stays available as an opt-in. The config loader's warning now fires only for an operator who sets `delegated` and declares no server to grant. --- api/server/routes/__tests__/apiKeys.spec.js | 6 ++--- api/server/services/ApiKeys/grants.spec.js | 5 ++-- packages/api/src/apiKeys/grants.spec.ts | 19 ++++----------- packages/api/src/apiKeys/grants.ts | 6 ++--- packages/api/src/apiKeys/handlers.spec.ts | 9 ++++--- .../src/app/__fixtures__/remote/declared.yaml | 1 + .../app/__fixtures__/remote/ungrantable.yaml | 5 ++++ .../src/app/__fixtures__/remote/unset.yaml | 5 ++++ packages/api/src/app/loader.spec.ts | 9 +++---- packages/api/src/app/loader.ts | 24 +++++++------------ packages/api/src/schedules/README.md | 8 +++---- packages/data-provider/src/config.ts | 5 ++-- 12 files changed, 46 insertions(+), 56 deletions(-) create mode 100644 packages/api/src/app/__fixtures__/remote/unset.yaml diff --git a/api/server/routes/__tests__/apiKeys.spec.js b/api/server/routes/__tests__/apiKeys.spec.js index 54a3a13a8e..72e018e594 100644 --- a/api/server/routes/__tests__/apiKeys.spec.js +++ b/api/server/routes/__tests__/apiKeys.spec.js @@ -40,10 +40,8 @@ describe('API key routes', () => { }); }); - it('lists keys without the grants flag where the operator left key runs unlimited', async () => { - getAppConfig.mockResolvedValueOnce({ - endpoints: { agents: { remoteApi: { integrations: { mode: 'owner' } } } }, - }); + it('lists keys without the grants flag where key runs are not limited', async () => { + getAppConfig.mockResolvedValueOnce({ endpoints: { agents: {} } }); const response = await request(app).get('/api/api-keys'); expect(response.status).toBe(200); expect(response.body).toEqual({ keys: mockKeys }); diff --git a/api/server/services/ApiKeys/grants.spec.js b/api/server/services/ApiKeys/grants.spec.js index b44b657cb5..d9810af4c7 100644 --- a/api/server/services/ApiKeys/grants.spec.js +++ b/api/server/services/ApiKeys/grants.spec.js @@ -42,10 +42,9 @@ describe('API key grant wiring', () => { }); }); - it('lets a personal key run through untouched where the operator left key runs unlimited', async () => { + it('lets a personal key run through untouched where key runs are not limited', async () => { const host = require('./grants'); - const owner = { remoteApi: { integrations: { mode: 'owner' } } }; - for (const config of [{ endpoints: { agents: owner } }]) { + for (const config of [undefined, { endpoints: { agents: {} } }]) { getAppConfig.mockResolvedValueOnce(config); const req = { user: { id: 'owner', role: 'USER' } }; await expect( diff --git a/packages/api/src/apiKeys/grants.spec.ts b/packages/api/src/apiKeys/grants.spec.ts index 17d188639b..92fd19063d 100644 --- a/packages/api/src/apiKeys/grants.spec.ts +++ b/packages/api/src/apiKeys/grants.spec.ts @@ -26,8 +26,8 @@ import { getScheduleMCPExecution, bindScheduledMCPInvocation, } from '~/schedules/authorization/execution'; -import { getRemoteRunKeyId, resolveRemoteIntegrations, createAgentKeyMCPGrantHost } from './grants'; import { createRemoteExecutionContext } from '~/agents/authority/context'; +import { createAgentKeyMCPGrantHost, getRemoteRunKeyId } from './grants'; import { getMCPRequestContext } from '~/mcp/request'; const queryTool: Tool = { @@ -216,21 +216,10 @@ afterEach(() => jest.restoreAllMocks()); const refused = (reason: string) => ({ failure: { reason, automaticReplay: false } }); -it('leaves key runs as they were only where the operator says so', async () => { - const s = setup({ mode: 'owner', resources: { warehouse: resource } }); - await expect((await s.run()).call()).resolves.toBe('unrestricted'); - expect(await s.host.service.view(s.identity())).toMatchObject({ - state: 'unsupported', - offer: null, - }); -}); - -it('limits key runs to their grants unless told otherwise, even with nothing declared', async () => { - for (const integrations of [null, {}]) { +it('leaves key runs as they were unless the operator asks for grants', async () => { + for (const integrations of [null, {}, { mode: 'owner', resources: { warehouse: resource } }]) { const s = setup(integrations); - expect(resolveRemoteIntegrations(s.config).mode).toBe('delegated'); - await expect((await s.run()).call()).rejects.toMatchObject(refused('consent_missing')); - // Nothing is declared, so there is nothing the owner could grant. + await expect((await s.run()).call()).resolves.toBe('unrestricted'); expect(await s.host.service.view(s.identity())).toMatchObject({ state: 'unsupported', offer: null, diff --git a/packages/api/src/apiKeys/grants.ts b/packages/api/src/apiKeys/grants.ts index da6a57ff43..82f44b5a91 100644 --- a/packages/api/src/apiKeys/grants.ts +++ b/packages/api/src/apiKeys/grants.ts @@ -32,8 +32,8 @@ type RemoteAgentAccessParams = Parameters[0]; export interface RemoteIntegrations { /** - * `delegated`, the default: only what the key's owner granted it. `owner`: every server the - * owner can use, which is how key runs behaved before grants existed. + * `owner`, the default: every server the key's owner can use. `delegated`: only what a grant + * covers. */ mode: 'owner' | 'delegated'; maxLifetimeHours: number; @@ -44,7 +44,7 @@ export interface RemoteIntegrations { export function resolveRemoteIntegrations(appConfig?: AppConfig): RemoteIntegrations { const integrations = appConfig?.endpoints?.[EModelEndpoint.agents]?.remoteApi?.integrations; return { - mode: integrations?.mode ?? 'delegated', + mode: integrations?.mode ?? 'owner', maxLifetimeHours: integrations?.maxLifetimeHours ?? DEFAULT_SCHEDULE_MCP_CONSENT_LIFETIME_HOURS, ...(integrations?.resources && { resources: integrations.resources }), }; diff --git a/packages/api/src/apiKeys/handlers.spec.ts b/packages/api/src/apiKeys/handlers.spec.ts index 6f6213ceb6..2f8fa85429 100644 --- a/packages/api/src/apiKeys/handlers.spec.ts +++ b/packages/api/src/apiKeys/handlers.spec.ts @@ -30,15 +30,14 @@ function setup(getAppConfig?: ApiKeyHandlerDependencies['getAppConfig']) { } describe('listApiKeys', () => { - it('lists keys without the flag where the operator left key runs unlimited', async () => { + it('lists keys as before where nothing says grants are in use', async () => { const { list, keys } = setup(); expect(await list()).toEqual({ keys }); - expect(await setup(async () => configured('owner')).list()).toEqual({ keys }); + for (const config of [undefined, configured(), configured('owner')]) + expect(await setup(async () => config).list()).toEqual({ keys }); }); - it('tells the client when key runs are limited to what the owner granted, which is the default', async () => { - for (const config of [undefined, configured()]) - expect(await setup(async () => config).list()).toMatchObject({ grants: true }); + it('tells the client when key runs are limited to what the owner granted', async () => { const getAppConfig = jest.fn(async () => configured('delegated')); const { list, keys } = setup(getAppConfig); expect(await list()).toEqual({ keys, grants: true }); diff --git a/packages/api/src/app/__fixtures__/remote/declared.yaml b/packages/api/src/app/__fixtures__/remote/declared.yaml index 212cd19871..2eef3009a9 100644 --- a/packages/api/src/app/__fixtures__/remote/declared.yaml +++ b/packages/api/src/app/__fixtures__/remote/declared.yaml @@ -7,6 +7,7 @@ endpoints: agents: remoteApi: integrations: + mode: delegated resources: warehouse: url: https://warehouse.example/mcp diff --git a/packages/api/src/app/__fixtures__/remote/ungrantable.yaml b/packages/api/src/app/__fixtures__/remote/ungrantable.yaml index 09e636ca4b..00b3bc2789 100644 --- a/packages/api/src/app/__fixtures__/remote/ungrantable.yaml +++ b/packages/api/src/app/__fixtures__/remote/ungrantable.yaml @@ -3,3 +3,8 @@ cache: true interface: remoteAgents: use: true +endpoints: + agents: + remoteApi: + integrations: + mode: delegated diff --git a/packages/api/src/app/__fixtures__/remote/unset.yaml b/packages/api/src/app/__fixtures__/remote/unset.yaml new file mode 100644 index 0000000000..09e636ca4b --- /dev/null +++ b/packages/api/src/app/__fixtures__/remote/unset.yaml @@ -0,0 +1,5 @@ +version: 1.3.8 +cache: true +interface: + remoteAgents: + use: true diff --git a/packages/api/src/app/loader.spec.ts b/packages/api/src/app/loader.spec.ts index 2884a72836..f9a4ee102e 100644 --- a/packages/api/src/app/loader.spec.ts +++ b/packages/api/src/app/loader.spec.ts @@ -278,18 +278,19 @@ describe('createCustomConfigLoader retired schedule tool policy', () => { expect(warnings(warn)).not.toContain('readOnlyPolicy'); }); - it('tells an operator who uses the remote API that key runs have no MCP server to be granted', async () => { + it('tells an operator who limits key runs to grants that there is no MCP server to be granted', async () => { process.env.CONFIG_PATH = path.join(__dirname, '__fixtures__', 'remote', 'ungrantable.yaml'); const config = await createLoader()(false); expect(config?.interface?.remoteAgents).toMatchObject({ use: true }); expect(warnings(warn)).toContain('Agent API key runs cannot use MCP tools'); expect(warnings(warn)).toContain('endpoints.agents.remoteApi.integrations.resources'); - expect(warnings(warn)).toContain('"owner"'); + expect(warnings(warn)).toContain('"delegated"'); }); - it.each(['declared', 'owner'])( - 'says nothing about key runs when the %s configuration answers it', + // `unset` uses the remote API and leaves the mode alone: key runs are not limited there. + it.each(['declared', 'owner', 'unset'])( + 'says nothing about key runs when the %s configuration leaves nothing ungrantable', async (name) => { process.env.CONFIG_PATH = path.join(__dirname, '__fixtures__', 'remote', `${name}.yaml`); await createLoader()(false); diff --git a/packages/api/src/app/loader.ts b/packages/api/src/app/loader.ts index 07cd683a9d..2e39360aa3 100644 --- a/packages/api/src/app/loader.ts +++ b/packages/api/src/app/loader.ts @@ -159,21 +159,15 @@ function reportRetiredScheduleToolPolicy(configPath: string, config: unknown): v } /** - * API key runs may use only the MCP tools the key's owner granted, and an owner can grant only - * servers the operator declared. A deployment that uses the remote API and declares none has - * every key run's MCP tools refused with nothing to grant, so its operator is told how to - * declare them or how to keep the earlier behaviour. + * Under `delegated`, an API key run may use only the MCP tools the key's owner granted, and an + * owner can grant only servers the operator declared. An operator who chooses that mode and + * declares none has every key run's MCP tools refused with nothing to grant, so they are told. */ function reportUngrantableKeyRuns(configPath: string, config: unknown): void { const root = config as { - interface?: { remoteAgents?: unknown }; endpoints?: { agents?: { remoteApi?: { integrations?: unknown } } }; } | null; - const remoteApi = root?.endpoints?.agents?.remoteApi; - if (root?.interface?.remoteAgents == null && remoteApi == null) { - return; - } - const integrations = remoteApi?.integrations as + const integrations = root?.endpoints?.agents?.remoteApi?.integrations as | { mode?: unknown; resources?: unknown } | null | undefined; @@ -181,15 +175,15 @@ function reportUngrantableKeyRuns(configPath: string, config: unknown): void { integrations?.resources != null && typeof integrations.resources === 'object' && Object.keys(integrations.resources).length > 0; - if (integrations?.mode === 'owner' || declared) { + if (integrations?.mode !== 'delegated' || declared) { return; } logger.warn( - `Agent API key runs cannot use MCP tools with the configuration in ${configPath}: a key may ` + - 'use only the servers and tools its owner granted it, and no server is declared under ' + + `Agent API key runs cannot use MCP tools with the configuration in ${configPath}: ` + + 'endpoints.agents.remoteApi.integrations.mode is "delegated", so a key may use only the ' + + 'servers and tools its owner granted it, and no server is declared under ' + 'endpoints.agents.remoteApi.integrations.resources. Declare the servers keys may be ' + - 'granted, or set endpoints.agents.remoteApi.integrations.mode to "owner" to let a key ' + - 'use every server its owner can, as before.', + 'granted, or remove the mode to let a key use every server its owner can.', ); } diff --git a/packages/api/src/schedules/README.md b/packages/api/src/schedules/README.md index ee309ee8fe..328eee5106 100644 --- a/packages/api/src/schedules/README.md +++ b/packages/api/src/schedules/README.md @@ -141,15 +141,15 @@ endpoints: agents: remoteApi: integrations: - mode: delegated # the default. `owner`: every server the key's owner can use + mode: delegated # default `owner`: every server the key's owner can use maxLifetimeHours: 168 resources: # the servers a key may be granted, as for schedules warehouse: { url: ..., credentialMode: ..., issuer: ..., audience: ..., scopes: [] } ``` -`delegated` is the default. With no `resources` declared there is nothing an owner can grant, -so every key run's MCP tools are refused; the config loader warns a deployment that uses the -remote API about it. `mode: owner` restores the behaviour from before grants existed. +`owner` is the default: a key run can use every MCP server its owner can, and nothing here +applies. Under `delegated` with no `resources` declared there is nothing an owner can grant, so +every key run's MCP tools are refused; the config loader warns about that configuration. Under `delegated`, a run started with a personal key (chat completions, Responses, and a background Responses worker) is put under that key's grant for the agent before any tool is diff --git a/packages/data-provider/src/config.ts b/packages/data-provider/src/config.ts index 791143b5e9..032ed0e09e 100644 --- a/packages/data-provider/src/config.ts +++ b/packages/data-provider/src/config.ts @@ -1150,9 +1150,8 @@ const remoteApiAuthSchema = z.object({ /** * Which of the key owner's MCP servers a run started with an API key may use. - * `delegated`, the default: only the servers and tools the owner approved for that key and - * that agent; anything else is refused. `owner`: every server the owner can use, which is how - * key runs behaved before grants existed. + * `owner`, the default: every server the owner can use. `delegated`: only the servers and + * tools the owner approved for that key and that agent; anything else is refused. */ const remoteApiIntegrationsSchema = z.object({ mode: z.enum(['owner', 'delegated']).optional(),