mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-21 15:33:45 +00:00
🔓 fix: Keep owner as the Default Mode for API Key Runs (#18448)
#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.
This commit is contained in:
parent
b6a07cef0a
commit
254c2a9b06
12 changed files with 46 additions and 56 deletions
|
|
@ -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 });
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ type RemoteAgentAccessParams = Parameters<typeof checkRemoteAgentAccess>[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 }),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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 });
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ endpoints:
|
|||
agents:
|
||||
remoteApi:
|
||||
integrations:
|
||||
mode: delegated
|
||||
resources:
|
||||
warehouse:
|
||||
url: https://warehouse.example/mcp
|
||||
|
|
|
|||
|
|
@ -3,3 +3,8 @@ cache: true
|
|||
interface:
|
||||
remoteAgents:
|
||||
use: true
|
||||
endpoints:
|
||||
agents:
|
||||
remoteApi:
|
||||
integrations:
|
||||
mode: delegated
|
||||
|
|
|
|||
5
packages/api/src/app/__fixtures__/remote/unset.yaml
Normal file
5
packages/api/src/app/__fixtures__/remote/unset.yaml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
version: 1.3.8
|
||||
cache: true
|
||||
interface:
|
||||
remoteAgents:
|
||||
use: true
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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.',
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue