mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-29 08:06:46 +00:00
* feat: make new tokens workspace-bound and rights-free unless opted in Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: honour withheld token rights in devops, instance db and webhook rotation Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: bump ee ref Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: name token admin explicitly in every token insert Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: carry withheld token rights through caller JWTs and keep nonmember superadmin mints working Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: bump ee ref Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: update ee-repo-ref to 74c3a4ce446d8d9abd69c69da5be8bfdb6d775f4 This commit updates the EE repository reference after PR #1018 was merged in windmill-ee-private. Previous ee-repo-ref: 28e9391cff06b84fff9bd420a8b244c35588523a New ee-repo-ref: 74c3a4ce446d8d9abd69c69da5be8bfdb6d775f4 Automated by sync-ee-ref workflow. * feat: make the instance-wide token choice explicit in the token form Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat: rename the token scope switch to restrict to specific scopes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: refuse mcp oauth approval from a token withholding admin, warn on empty scope restriction Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat: workspace choice on the cli login page and hints for workspace-bound cli tokens Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: bind a cli login token only to the workspace the cli names Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
147 lines
5.0 KiB
Rust
147 lines
5.0 KiB
Rust
//! A superadmin's MCP token carries their superadmin rights (every workspace) only when asked,
|
|
//! and the OAuth consent path and the token-create path agree on it.
|
|
#![cfg(feature = "mcp")]
|
|
|
|
use serde_json::json;
|
|
use sqlx::{Pool, Postgres};
|
|
|
|
use windmill_test_utils::*;
|
|
|
|
const VERIFIER: &str = "e2e-pkce-verifier-0123456789-0123456789-abcdef";
|
|
const CHALLENGE: &str = "q9x8Sam6B6iSaQRwyLQdPrK3Ob2wfH1sNsUhYehHwh8";
|
|
const REDIRECT: &str = "http://localhost:9/cb";
|
|
|
|
async fn token_is_super_admin(db: &Pool<Postgres>, token: &str) -> anyhow::Result<bool> {
|
|
Ok(sqlx::query_scalar(
|
|
"SELECT super_admin FROM token WHERE token_hash = encode(sha256($1::bytea), 'hex')",
|
|
)
|
|
.bind(token.as_bytes())
|
|
.fetch_one(db)
|
|
.await?)
|
|
}
|
|
|
|
#[sqlx::test(migrations = "../migrations", fixtures("base"))]
|
|
async fn test_mcp_token_super_admin_is_opt_in(db: Pool<Postgres>) -> anyhow::Result<()> {
|
|
initialize_tracing().await;
|
|
set_jwt_secret().await;
|
|
let server = ApiServer::start_mcp(db.clone()).await?;
|
|
let base = format!("http://localhost:{}/api", server.addr.port());
|
|
let http = reqwest::Client::new();
|
|
|
|
let client_id = http
|
|
.post(format!("{base}/mcp/oauth/server/register"))
|
|
.json(&json!({ "client_name": "test", "redirect_uris": [REDIRECT] }))
|
|
.send()
|
|
.await?
|
|
.json::<serde_json::Value>()
|
|
.await?["client_id"]
|
|
.as_str()
|
|
.unwrap()
|
|
.to_string();
|
|
let approve = |bearer: &str, super_admin: bool| {
|
|
http.post(format!("{base}/mcp/gateway/oauth/server/approve"))
|
|
.bearer_auth(bearer)
|
|
.json(&json!({
|
|
"client_id": client_id, "redirect_uri": REDIRECT, "scope": "mcp:all", "state": "",
|
|
"code_challenge": CHALLENGE, "code_challenge_method": "S256",
|
|
"all_workspaces": true, "super_admin": super_admin,
|
|
}))
|
|
.send()
|
|
};
|
|
|
|
for super_admin in [false, true] {
|
|
let code = approve("SECRET_TOKEN", super_admin)
|
|
.await?
|
|
.json::<serde_json::Value>()
|
|
.await?["code"]
|
|
.as_str()
|
|
.unwrap()
|
|
.to_string();
|
|
let issued = http
|
|
.post(format!("{base}/mcp/gateway/oauth/server/token"))
|
|
.form(&[
|
|
("grant_type", "authorization_code"),
|
|
("code", &code),
|
|
("client_id", &client_id),
|
|
("redirect_uri", REDIRECT),
|
|
("code_verifier", VERIFIER),
|
|
])
|
|
.send()
|
|
.await?
|
|
.json::<serde_json::Value>()
|
|
.await?;
|
|
let oauth_token = issued["access_token"].as_str().expect(&issued.to_string());
|
|
assert_eq!(token_is_super_admin(&db, oauth_token).await?, super_admin);
|
|
|
|
let refreshed = http
|
|
.post(format!("{base}/mcp/gateway/oauth/server/token"))
|
|
.form(&[
|
|
("grant_type", "refresh_token"),
|
|
("refresh_token", issued["refresh_token"].as_str().unwrap()),
|
|
("client_id", &client_id),
|
|
])
|
|
.send()
|
|
.await?
|
|
.json::<serde_json::Value>()
|
|
.await?;
|
|
let refreshed = refreshed["access_token"].as_str().unwrap();
|
|
assert_eq!(token_is_super_admin(&db, refreshed).await?, super_admin);
|
|
|
|
let user_token = http
|
|
.post(format!("{base}/users/tokens/create"))
|
|
.bearer_auth("SECRET_TOKEN")
|
|
.json(&json!({ "label": "mcp", "scopes": ["mcp:all"], "super_admin": super_admin }))
|
|
.send()
|
|
.await?
|
|
.text()
|
|
.await?;
|
|
assert_eq!(token_is_super_admin(&db, &user_token).await?, super_admin);
|
|
}
|
|
|
|
assert_eq!(
|
|
approve("SECRET_TOKEN_2", true).await?.status(),
|
|
401,
|
|
"only a superadmin may grant superadmin rights"
|
|
);
|
|
|
|
let opted_out = http
|
|
.post(format!("{base}/users/tokens/create"))
|
|
.bearer_auth("SECRET_TOKEN")
|
|
.json(&json!({ "label": "mcp", "scopes": ["mcp:all"] }))
|
|
.send()
|
|
.await?
|
|
.text()
|
|
.await?;
|
|
assert_eq!(
|
|
approve(&opted_out, true).await?.status(),
|
|
401,
|
|
"an MCP token without superadmin access cannot approve one that has it"
|
|
);
|
|
|
|
let without_admin = http
|
|
.post(format!("{base}/users/tokens/create"))
|
|
.bearer_auth("SECRET_TOKEN")
|
|
.json(&json!({ "label": "api" }))
|
|
.send()
|
|
.await?
|
|
.text()
|
|
.await?;
|
|
assert_eq!(
|
|
approve(&without_admin, false).await?.status(),
|
|
401,
|
|
"a token withholding its owner's admin rights cannot approve a token that carries them"
|
|
);
|
|
|
|
http.post(format!("{base}/users/update/test@windmill.dev"))
|
|
.bearer_auth("SECRET_TOKEN")
|
|
.json(&json!({ "is_super_admin": true }))
|
|
.send()
|
|
.await?
|
|
.error_for_status()?;
|
|
assert!(
|
|
!token_is_super_admin(&db, &opted_out).await?,
|
|
"a promotion must not hand superadmin access to an MCP token minted without it"
|
|
);
|
|
Ok(())
|
|
}
|