Files
open-connector/migrations/0011_runtime_token_connection_scope.sql
b028ecd38e feat: allow scoping runtime tokens to specific connections (#363)
Closes #357

## Summary
- Add optional `allowedConnections` on stored runtime tokens (`oct_…`)
so a token can be limited to exact bare `connectionName` values. Omitted
or `[]` keeps today's unrestricted behavior (same empty-allowlist
meaning as `allowedActions`, not `allowedProxies`).
- Enforce the grant **before** credential lookup on HTTP Actions, MCP
`execute_action`, and provider proxy. Denied names return `403
connection_not_allowed` so existence is not leaked; an
allowed-but-missing name can still return `connection_not_found`.
Unnamed requests resolve to `default` first, so a restricted token must
list `default` to use that path.
- Filter runtime discovery that currently returns connection identity
(`GET /v1/apps*`, MCP `list_connections` / `list_apps` /
`get_action_guide`). Admin `/api/connections` and `agent.md` stay
unfiltered. Bootstrap `OOMOL_CONNECT_RUNTIME_TOKEN`, JWTs, and admin
elevation remain unrestricted (they never receive a `RuntimeGrant`).
- Persist the grant in SQLite/D1
(`0011_runtime_token_connection_scope.sql`), expose it in OpenAPI and
the Access console, and document the contract.

## Test plan
- [x] `npm run fix-check`
- [x] `npm test` (1062 passing)
- [ ] Create two connections on one provider (`default` and `work`)
- [ ] `POST /api/runtime-tokens` with `allowedConnections: ["work"]`
- [ ] Unnamed `/v1/actions/:id` and `/v1/proxy/:service` return `403
connection_not_allowed`
- [ ] Same calls with `x-oo-connector-alias: work` succeed
- [ ] `GET /v1/apps` and MCP `list_connections` show only `work`
- [ ] `GET /api/connections` still lists both names
- [ ] Token with `allowedConnections: ["work", "ghost"]` requesting
`ghost` returns `404 connection_not_found`
- [ ] Admin, bootstrap runtime token, JWT, and `allowedConnections: []`
still use `default`


Made with [Cursor](https://cursor.com)

---------

Co-authored-by: 昆昆 <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: l1shen <[email protected]>
2026-08-19 18:38:53 +08:00

2 lines
86 B
SQL

alter table runtime_tokens add column allowed_connections text not null default '[]';