fix: render public apps unsandboxed for external jwt viewers (#12806)

* fix: render public apps unsandboxed for external jwt viewers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore: update ee-repo-ref to ae0aad4eb1f18c6d51150600579efec910480947

This commit updates the EE repository reference after PR #1040 was merged in windmill-ee-private.

Previous ee-repo-ref: 0ee026b17e83136f66fee9972c6773ccc7f1ed83

New ee-repo-ref: ae0aad4eb1f18c6d51150600579efec910480947

Automated by sync-ee-ref workflow.

---------

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>
This commit is contained in:
Ruben Fiszel
2026-12-02 01:05:10 +01:00
committed by GitHub
co-authored by Claude Opus 5.5 windmill-internal-app[bot]
parent b0f7573a66
commit f6c9f55dfd
3 changed files with 108 additions and 2 deletions
+1 -1
View File
@@ -1 +1 @@
b278e6b2bcaa04c27faa7293474d0ac5132dcaf9
ae0aad4eb1f18c6d51150600579efec910480947
@@ -0,0 +1,92 @@
//! A viewer authenticated by an external JWT (`jwt_ext_`) has no `usr` row, yet is a
//! member of the workspace its JWT names. Isolating it would hand it an embed token
//! owned by its email, which token auth can never resolve, so the embedded app would
//! reload forever on 401s. It keeps the publisher's unsandboxed render instead.
//!
//! The RSA keypair is a fixed test vector: `JWT_EXT_PUBLIC_KEY` is read once per
//! process, so it is set before the server first authenticates a `jwt_ext_` bearer.
#![cfg(all(feature = "enterprise", feature = "private"))]
use std::time::{SystemTime, UNIX_EPOCH};
use jsonwebtoken::{encode, Algorithm, EncodingKey, Header};
use serde_json::json;
use sqlx::{Pool, Postgres};
use windmill_test_utils::*;
const APP_PATH: &str = "u/test-user/ext_jwt_app";
const PRIV: &str = "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDW0+VQN2+bO2ZA\nlXLaJgDvOxWL8Yt8JAjKxtBuoEXm7LKSlTRY/5IXPtfNu5Now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\nrtCAwIaPxoRMHXNAvxzaqpvNaFRp3720c6mZaBjB2/nqxWMy+cj0MdIJDVHY5Gne\nOj4gOwcnFWRLgSp9y+evWATiwVi1I783D/w3KKgM6h9ChwPGCVBLvtRhAoGBAJtl\n0+i9KW9JTl1odjHnPIx/B0CP1uXEgGCYVqppsEMfWxp5j+KOWIUXYZzm9bH49j2q\noouzL/h29k8qRgA4ZfWN3r8ElDkTibhzejgknwS47qbPc77nsGZ/NFFdbkVbW9wZ\nR/HZyLd5xxeP3HZVHnn0nebEGoG7UU5YV3xfTuQNAoGBALKl0/GGg8A52+pV/0z1\n4ZSaP0/wBBk6IKMHCLM+4/2hWoNMW8SndD8HYegJ9TunxOGhuC0sXC0r/fAJ3HF8\nAjtlFwVPfLONjHEWwOG8ll77K9jy5eBDL+csySOHqHI9wzIyxSzKg65uDkIiP0ni\ndOQkC+Yq6YYGhMoOQShezBfm\n-----END PRIVATE KEY-----\n";
const PUB: &str = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1tPlUDdvmztmQJVy2iYA\n7zsVi/GLfCQIysbQbqBF5uyykpU0WP+SFz7XzbuTaMGLtn1vuClIfPZkOIIOKFel\ne5EtqjgRFAuDg5Mcinzjn7vp/rk4mbnw/sXpWsNgApQRcPL8wiHc2aH1CfBiUvVD\nXRLVEmKs54FdkDmzf3IDedCUSbcprG84IqDpLxMRmWPahTgqccbbDAWvx+psFz6Q\nDOHTuHGau+2i5/XqwY4AS+SmmGaB4zDkqFkQnGPZnYF8fxaEd+EpNJIVRdSRQM9Y\nw/N/mIfWP7Jcwg9gy/+vhh2tZTcKWig7GAEMrYRyLRK5yiiarGmsXah6lCxjM5Cp\ngwIDAQAB\n-----END PUBLIC KEY-----\n";
#[sqlx::test(fixtures("base"))]
async fn ext_jwt_viewer_keeps_the_unsandboxed_render(db: Pool<Postgres>) -> anyhow::Result<()> {
unsafe { std::env::set_var("JWT_EXT_PUBLIC_KEY", PUB) };
initialize_tracing().await;
let server = ApiServer::start(db.clone()).await?;
let ws = format!(
"http://localhost:{}/api/w/test-workspace",
server.addr.port()
);
let client = reqwest::Client::new();
let resp = client
.post(format!("{ws}/apps/create"))
.header("Authorization", "Bearer SECRET_TOKEN")
.json(&json!({
"path": APP_PATH,
"summary": "Embedded with an external JWT",
"value": {},
"policy": { "execution_mode": "publisher", "triggerables": {}, "sandbox": false }
}))
.send()
.await?;
assert_eq!(resp.status(), 201, "{}", resp.text().await?);
// Read access through the group the JWT claims, as a publisher-mode app requires.
sqlx::query("UPDATE app SET extra_perms = '{\"g/all\": false}' WHERE path = $1")
.bind(APP_PATH)
.execute(&db)
.await?;
let secret = client
.get(format!("{ws}/apps/secret_of/{APP_PATH}"))
.header("Authorization", "Bearer SECRET_TOKEN")
.send()
.await?
.text()
.await?;
let exp = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs() + 3600;
let jwt = encode(
&Header::new(Algorithm::RS256),
&json!({
"email": "embedded@example.com",
"username": "embedded",
"is_admin": false,
"is_operator": false,
"groups": ["all"],
"folders": [],
"workspace_id": "test-workspace",
"exp": exp,
}),
&EncodingKey::from_rsa_pem(PRIV.as_bytes())?,
)?;
let bearer = format!("Bearer jwt_ext_{jwt}");
let resp = client
.get(format!("{ws}/apps_u/embed_token/{secret}"))
.header("Authorization", &bearer)
.send()
.await?;
assert_eq!(resp.status(), 200, "{}", resp.text().await?);
let body: serde_json::Value = resp.json().await?;
assert_eq!(body["sandbox"], json!(false), "{body}");
assert!(body["token"].is_null(), "no embed token to mint: {body}");
let tokens: i64 = sqlx::query_scalar("SELECT count(*) FROM token WHERE email = $1")
.bind("embedded@example.com")
.fetch_one(&db)
.await?;
assert_eq!(tokens, 0);
Ok(())
}
+15 -1
View File
@@ -1700,10 +1700,12 @@ pub async fn build_embed_token_response(
raw_app: bool,
policy: &EmbedPolicyView,
opt_authed: Option<&ApiAuthed>,
viewer_token: Option<&str>,
sdk_consent: bool,
job_id: Option<uuid::Uuid>,
) -> Result<EmbedTokenResponse> {
let sandbox = policy.sandbox || !viewer_is_workspace_member(db, w_id, opt_authed).await?;
let sandbox =
policy.sandbox || !viewer_is_workspace_member(db, w_id, opt_authed, viewer_token).await?;
// Only advertise scopes where a token could actually be minted, so the viewer
// is never shown a permission prompt that can grant nothing: an anonymous
// visitor has no identity to mint against.
@@ -1769,10 +1771,16 @@ pub async fn build_embed_token_response(
/// author's `sandbox: false` holds. Anyone else (anonymous, a guest, a superadmin of
/// another workspace) holds a session the author has no business running code with,
/// so the app renders isolated for them whatever its policy says.
///
/// An external JWT (`jwt_ext_`) is a member without a `usr` row: the issuer vouches
/// for it in this workspace, and its auth already refused it for any other. It must
/// not be isolated, because the embed token isolation mints is owned by its email and
/// token auth resolves that owner through `usr`, so the token could never authenticate.
async fn viewer_is_workspace_member(
db: &DB,
w_id: &str,
opt_authed: Option<&ApiAuthed>,
viewer_token: Option<&str>,
) -> Result<bool> {
let Some(authed) = opt_authed else {
return Ok(false);
@@ -1780,6 +1788,9 @@ async fn viewer_is_workspace_member(
if windmill_api_auth::scopes::has_guest_sentinel(authed.scopes.as_deref()) {
return Ok(false);
}
if viewer_token.is_some_and(|t| t.starts_with("jwt_ext_")) {
return Ok(true);
}
let member: bool = sqlx::query_scalar(
"SELECT EXISTS(SELECT 1 FROM usr WHERE workspace_id = $1 AND email = $2 AND NOT disabled)",
)
@@ -2083,6 +2094,7 @@ async fn get_app_embed_token(
raw_app,
&policy,
authed_for_token.as_ref(),
token.as_deref(),
sdk_query.sdk_consent,
job_id,
)
@@ -2134,6 +2146,7 @@ pub fn parse_embed_policy(policy_str: &str) -> Result<EmbedPolicyView> {
async fn get_app_embed_token_for_path(
authed: ApiAuthed,
OptJobAuthed { job_id, .. }: OptJobAuthed,
OptTokened { token }: OptTokened,
Extension(user_db): Extension<UserDB>,
Extension(db): Extension<DB>,
Path((w_id, path)): Path<(String, StripPath)>,
@@ -2168,6 +2181,7 @@ async fn get_app_embed_token_for_path(
raw_app,
&policy,
Some(&authed),
token.as_deref(),
sdk_query.sdk_consent,
job_id,
)