fix: name only what a connection gets, refuse scoped callers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
hugocasa
2026-12-02 13:23:22 +01:00
co-authored by Claude Opus 5.5
parent a7e5e9c84b
commit 16262e934e
7 changed files with 83 additions and 13 deletions
@@ -0,0 +1,28 @@
{
"db_name": "PostgreSQL",
"query": "SELECT workspace.id, workspace.name FROM workspace\n JOIN usr ON usr.workspace_id = workspace.id\n WHERE usr.email = $1 AND usr.disabled = false AND workspace.deleted = false\n ORDER BY workspace.name",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Varchar"
},
{
"ordinal": 1,
"name": "name",
"type_info": "Varchar"
}
],
"parameters": {
"Left": [
"Text"
]
},
"nullable": [
false,
false
]
},
"hash": "44f272788e9dcceef20348675db1bb22391e9ac7b9c4d11786d59fa9b17fc8f9"
}
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
"query": "SELECT workspace_id, is_admin, operator, workspace_role FROM usr\n WHERE email = $1 AND workspace_id = ANY($2) AND disabled = false",
"query": "SELECT workspace_id, username, is_admin, operator, workspace_role FROM usr\n WHERE email = $1 AND workspace_id = ANY($2) AND disabled = false",
"describe": {
"columns": [
{
@@ -10,16 +10,21 @@
},
{
"ordinal": 1,
"name": "username",
"type_info": "Varchar"
},
{
"ordinal": 2,
"name": "is_admin",
"type_info": "Bool"
},
{
"ordinal": 2,
"ordinal": 3,
"name": "operator",
"type_info": "Bool"
},
{
"ordinal": 3,
"ordinal": 4,
"name": "workspace_role",
"type_info": "Varchar"
}
@@ -34,8 +39,9 @@
false,
false,
false,
false,
true
]
},
"hash": "cc2d27c55c3dac7b0f287b56c66ec1ee8856df25ebe62074bb1628ee7f39415b"
"hash": "ee761c085738bb22b01a48627e067b145f92f1c396817e4c13e50019fc085d6c"
}
+26
View File
@@ -194,6 +194,32 @@ async fn role_setting_caps_every_token(db: Pool<Postgres>) -> anyhow::Result<()>
let out = call(DEFAULT, "ROLEUNBOUND_TOKEN", "list_workspaces", json!({})).await;
assert!(out["result"].to_string().contains("read only"), "{out}");
let listed = |bearer: &'static str| async move {
reqwest::Client::new()
.get(format!(
"http://localhost:{port}/api/mcp/gateway/oauth/server/workspace_access"
))
.bearer_auth(bearer)
.send()
.await
.unwrap()
};
let access: Value = listed("SECRET_TOKEN").await.json().await?;
let here = access
.as_array()
.unwrap()
.iter()
.find(|w| w["id"] == "test-workspace")
.unwrap();
assert_eq!(
(&here["access"], &here["limited"]),
(&json!("read_only"), &json!(true))
);
assert!(
!listed("ROLEUNBOUND_TOKEN").await.status().is_success(),
"a scoped token must not list its owner's other workspaces"
);
set_access(&db, json!({"access": "off"})).await;
assert!(tools(port, WORKSPACE, "ROLESEL_TOKEN").await.is_empty());
assert_eq!(
+2
View File
@@ -75,6 +75,8 @@ it must not restrict a role, cost a seat or reach an authoring gate.
`runnables` gets the tools server whatever the token, and an `mcp:all` token under another limit
the session toolset, since endpoint tools are never served under one. Where a connection covers
several workspaces the list is one for all, so the limit refuses at call time.
- The connect page and the MCP tab of the home page read `workspace_access`, the same computation
as `list_workspaces`, so a user is shown what they get rather than what they ask for.
- A selection intersects with the token's own (`McpScopeConfig::limited_by`).
- A lapsed license freezes it as it does roles: it keeps applying and can be removed, not changed.
On Community it is ignored and refused at write.
@@ -22,7 +22,7 @@
<p class="text-xs font-semibold text-emphasis">What it gets</p>
<ul class="flex flex-col divide-y rounded-md border max-h-60 overflow-y-auto">
{#each listed as workspace (workspace.id)}
{@const separate = connectsSeparately(workspace, all, covered)}
{@const separate = connectsSeparately(workspace, all, covered, access)}
<li class="flex flex-col gap-1 px-2 py-1.5">
<div class="flex items-baseline justify-between gap-2">
<span class="text-xs text-emphasis truncate">{workspace.name}</span>
@@ -35,8 +35,9 @@ it('names the lower of the picked access and the workspace one', () => {
})
it('tools are part of a connection to their workspace alone', () => {
expect(connectsSeparately(ws('a', 'runnables'), false, ['a'])).toBe(false)
expect(connectsSeparately(ws('a', 'runnables'), false, ['a', 'b'])).toBe(true)
expect(connectsSeparately(ws('a', 'runnables'), true, [])).toBe(true)
expect(connectsSeparately(ws('a', 'read_only'), true, [])).toBe(false)
expect(connectsSeparately(ws('a', 'runnables'), false, ['a'], 'full')).toBe(false)
expect(connectsSeparately(ws('a', 'runnables'), false, ['a', 'b'], 'full')).toBe(true)
expect(connectsSeparately(ws('a', 'runnables'), true, [], 'full')).toBe(true)
expect(connectsSeparately(ws('a', 'runnables'), true, [], 'read')).toBe(false)
expect(connectsSeparately(ws('a', 'read_only'), true, [], 'full')).toBe(false)
})
@@ -39,10 +39,17 @@ export function defaultConnection(workspaces: McpWorkspaceAccess[]): ConnectionD
const asTools = workspaces.filter((w) => w.access === 'runnables')
const session = workspaces.some((w) => w.access !== 'runnables' && w.access !== 'off')
if (session || asTools.length === 0) return { all: true, picked: [], oneEach: false }
return { all: false, picked: [asTools[0].id], oneEach: asTools.length > 1 }
const first = asTools.find((w) => w.runnables) ?? asTools[0]
return { all: false, picked: [first.id], oneEach: asTools.length > 1 }
}
/** Whether `workspace`, set to tools, needs its own connection next to the `covered` ones. */
export function connectsSeparately(workspace: McpWorkspaceAccess, all: boolean, covered: string[]) {
return workspace.access === 'runnables' && (all || covered.length > 1)
/** Whether `workspace`, set to tools, needs its own connection next to the `covered` ones. A
* read-only connection runs nothing there either way. */
export function connectsSeparately(
workspace: McpWorkspaceAccess,
all: boolean,
covered: string[],
picked: McpAccess
) {
return workspace.access === 'runnables' && picked !== 'read' && (all || covered.length > 1)
}