mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-10-13 16:02:59 +00:00
* feat: let operators compose full-code apps when the workspace grants it Adds operator_settings.builder_apps, the second builder right, granted independently of flows because the two are not equally verifiable: a composed flow is checked in full server-side, while a full-code app is a browser-built bundle no check can read. The app right rests instead on forced sandbox isolation, a refusal of Viewer execution mode, and a deploy-time check of every runnable the app can reach. BuilderKind arrives with the second kind and is a mandatory argument, so no gate can mean "either" by accident: one that did would authorize an app write on a flows-only workspace. The only surfaces reading .any() are the ones that are genuinely not per-kind, the seat a membership costs and listing drafts. validate_operator_composed_app checks two surfaces rather than one, because they are not the same list: the policy's triggerables and the runnableByPath entries in the app value, which is what the deployed bundle actually resolves against. Every colon in a triggerable key is a possible split, since execute_component looks up "<component>:<path>" with an unrestricted component string. create_app_raw_source stays closed: it compiles caller-supplied sources with a bundler job on a worker, which is arbitrary code execution. Builders lose nothing, since the browser and the CLI both bundle locally and deploy through the multipart endpoints. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dsf6VC4MVLisiEoeQkgbr4 * fix: list a builder's app drafts and refuse inline code in them Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: update ee-repo-ref to 6d15ff957df4dcd5129e1ab217eab1a13af62fbb Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: check a builder app as it will be stored Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: show the home list edit button to builder operators Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat: pause the raw app preview for an app an operator deployed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: let app builders save a full-code app's deploy settings Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: record the builder app settings path, public apps and the editor preview Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: cache the merged EE seat usage query The EE query now reads audit_partitioned and skips service accounts, so the cached entry for its builder_apps predicate no longer matched and offline EE builds failed with no cached data. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: pause the raw app preview for loaded drafts and unknown authors A draft loaded from an operator ran in the viewer's preview because the pause only checked the app's last deployer, and an author no longer in the workspace read as a developer. The pause now checks a loaded draft's owner, records it in the viewer's draft until the preview is run or deployed, and holds when the author cannot be found. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: name guest apps among the modes a builder may deploy Guest runs as the publisher with no Viewer fallback, like Publisher and Anonymous, and RestrictGuestAppDeployment refuses it per workspace. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: keep a loaded draft's preview paused in AI sessions and chat edits The session draft codec and the chat's draft save dropped loaded_from, so opening a paused operator draft in an AI session, or editing it through the chat, ran it with the viewer's session. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: pin builder refusals for low-code apps and unreviewed previews Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: keep the operator mark when loading a developer's copy of a draft Loading another user's draft recorded only who saved it, so a developer's copy of an operator draft they never previewed opened unpaused for the next person who loaded it, running the operator's code with their session. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: let builders restore a full-code app from deployment history Restore always sends allow_kind_change, which the builder check refused even for a full-code version restored over a full-code app. Builders now drop the flag, so the locked kind check still refuses an actual conversion. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * style: rustfmt the builder checks in jobs.rs Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: record the builder kind-check race as an accepted risk Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: never trust the owner name a loaded draft carries A loaded draft's loaded_from is written by its owner, so an operator could name a developer, or leave it empty, and the next person to load the draft previewed it unpaused. A loaded draft that carries any mark now stays paused as unattributable; an unmarked one is still checked against its real owner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: record viewer-supplied resources in builder apps as an accepted risk Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: say that the app right lets operators write frontend code The settings section and the docs told admins builder operators "still cannot write code", but the app right has them write the app's frontend bundle. Only backend code stays out of reach. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: state the raw-source closure once and drop an unreachable preview case Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * perf: look up only the author when deciding whether to pause the preview Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: pin that the app right alone bills operators as developers Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: point ee-repo-ref at the EE seat test Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor: drop the editor preview pause now that sandboxed apps preview isolated Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: refuse a builder operator's app draft without the sandbox Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: turn the sandbox on when a builder operator opens the app editor Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: refuse builder app drafts naming runnables they cannot read Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: note the editor preview asks before minting a builder app token Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor: trim the builder app check comments to the constraints Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: refuse an app runnable whose runType is not script, flow or hub Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: check builder app draft policy keys like a deploy does Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: count main's half-seat service accounts in the builder billing test Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor: name the builder policy check for drafts as well as deploys Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: let a builder app draft autosave with a stale triggerables_v2 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: check the script version a builder app would run, not any version Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: refuse viewer mode in a builder app draft as on deploy Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor: hold builder app drafts and deploys to one check Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: say a builder's script may not have finished deploying Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: cap builder app triggerable keys before reading every colon split Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: refuse a builder app draft that runs as someone else Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: conform builder app drafts saved by the AI chat as the editor does Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: record that a deployed builder draft runs as its deployer Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: refuse builder app runnables not written as plain text Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: a builder draft may carry its builder's own run identity Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: offer builders Start with AI only when it opens a session Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: name full-code apps in the builder rights confirmation Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: name only the granted builder rights in the confirmation Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: note a wm_deployers builder may keep another run identity Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: give builders a starter app that calls no missing runnables Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: seed the builder starter under the picker for builders Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: qualify the builder run identity comment for wm_deployers Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: resolve builder app script hashes before opening the RLS transaction Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: run the builder app tests serially to share the rights cache safely Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: give builders the builder starter on a fresh editor load Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: drop a new-app load overtaken while waiting for the workspace list Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: keep main's 401 for operators previewing without the app right Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: update ee-repo-ref to 5d7726c4979070ee8db4fb9e8014152872a641ba This commit updates the EE repository reference after PR #816 was merged in windmill-ee-private. Previous ee-repo-ref: 7151060bfc02908e97d9344b3820ee33a4951322 New ee-repo-ref: 5d7726c4979070ee8db4fb9e8014152872a641ba Automated by sync-ee-ref workflow. * refactor: let the app row's edit button trust its write flag Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: point ee-repo-ref at the merged EE companion Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: note the session raw-app editor does not conform builder drafts yet Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
571 lines
19 KiB
Rust
571 lines
19 KiB
Rust
use serde_json::json;
|
|
use serial_test::serial;
|
|
use sqlx::{Pool, Postgres};
|
|
use windmill_common::workspaces::invalidate_operator_rights_cache;
|
|
use windmill_test_utils::*;
|
|
|
|
/// Every test here must be `#[serial]`: the rights cache is process-global and keyed by workspace id
|
|
/// alone, so parallel tests under this same id read each other's rights.
|
|
const WS: &str = "test-workspace";
|
|
|
|
fn client(token: &str) -> reqwest::Client {
|
|
let mut headers = reqwest::header::HeaderMap::new();
|
|
headers.insert(
|
|
reqwest::header::AUTHORIZATION,
|
|
reqwest::header::HeaderValue::from_str(&format!("Bearer {token}")).unwrap(),
|
|
);
|
|
reqwest::ClientBuilder::new()
|
|
.default_headers(headers)
|
|
.build()
|
|
.unwrap()
|
|
}
|
|
|
|
async fn set_builder(db: &Pool<Postgres>, flows: bool, apps: bool) -> anyhow::Result<()> {
|
|
sqlx::query(
|
|
"UPDATE workspace_settings SET operator_settings = $1::text::jsonb WHERE workspace_id = $2",
|
|
)
|
|
.bind(format!(
|
|
r#"{{"builder_flows": {flows}, "builder_apps": {apps}}}"#
|
|
))
|
|
.bind(WS)
|
|
.execute(db)
|
|
.await?;
|
|
// The rights are read through a process-global 60s cache keyed by workspace id.
|
|
invalidate_operator_rights_cache(WS);
|
|
Ok(())
|
|
}
|
|
|
|
async fn add_script(db: &Pool<Postgres>, hash: i64, path: &str, owner: &str) -> anyhow::Result<()> {
|
|
sqlx::query(
|
|
"INSERT INTO script (workspace_id, hash, path, content, language, kind, created_by, schema,
|
|
summary, description, lock, extra_perms)
|
|
VALUES ($1, $2, $3, 'x', 'bun', 'script', $4, '{}', '', '', '', '{}')",
|
|
)
|
|
.bind(WS)
|
|
.bind(hash)
|
|
.bind(path)
|
|
.bind(owner)
|
|
.execute(db)
|
|
.await?;
|
|
Ok(())
|
|
}
|
|
|
|
/// A full-code app is deployed multipart, the way the editor and the CLI use it.
|
|
fn raw_app_form(app: serde_json::Value) -> reqwest::multipart::Form {
|
|
reqwest::multipart::Form::new()
|
|
.part(
|
|
"app",
|
|
reqwest::multipart::Part::text(app.to_string())
|
|
.mime_str("application/json")
|
|
.unwrap(),
|
|
)
|
|
.part(
|
|
"js",
|
|
reqwest::multipart::Part::text("console.log(1)").file_name("app.js"),
|
|
)
|
|
}
|
|
|
|
fn raw_app(path: &str, mode: &str, runnable_path: &str) -> reqwest::multipart::Form {
|
|
raw_app_form(json!({
|
|
"path": path,
|
|
"summary": "",
|
|
"value": {"files": {}, "runnables": {"r": {
|
|
"name": "r", "type": "runnableByPath", "runType": "script",
|
|
"path": runnable_path
|
|
}}},
|
|
"policy": {"execution_mode": mode, "triggerables_v2": {}}
|
|
}))
|
|
}
|
|
|
|
fn composition_flow(path: &str) -> serde_json::Value {
|
|
json!({
|
|
"path": path, "summary": "", "description": "", "schema": {},
|
|
"value": {"modules": [{
|
|
"id": "a",
|
|
"value": {"type": "script", "path": "u/operator/some_script", "input_transforms": {}}
|
|
}]}
|
|
})
|
|
}
|
|
|
|
/// The app half of the builder boundary, plus the proof that the two rights are independent: a
|
|
/// gate reading "either" would authorize the kind its workspace never granted, which is the whole
|
|
/// point of splitting them.
|
|
#[sqlx::test(migrations = "../migrations", fixtures("base", "permissions_test"))]
|
|
#[serial]
|
|
async fn test_operator_builder_apps_boundary(db: Pool<Postgres>) -> anyhow::Result<()> {
|
|
initialize_tracing().await;
|
|
let server = ApiServer::start(db.clone()).await?;
|
|
let port = server.addr.port();
|
|
let api = format!("http://localhost:{port}/api/w/{WS}");
|
|
let c = client("OPERATOR_TOKEN_1");
|
|
|
|
add_script(&db, 4241, "u/operator/some_script", "operator").await?;
|
|
// `permissions_test` gives the operator fixture no rights on `u/alice/**`.
|
|
add_script(&db, 4243, "u/alice/private", "alice").await?;
|
|
// A version shared with the operator, then archived, and a newer one at the same path that is
|
|
// not: the newer one is what runs.
|
|
add_script(&db, 4244, "u/alice/reused", "alice").await?;
|
|
sqlx::query(
|
|
"UPDATE script SET archived = true, extra_perms = '{\"u/operator\": false}',
|
|
created_at = now() - interval '1 day' WHERE hash = 4244",
|
|
)
|
|
.execute(&db)
|
|
.await?;
|
|
add_script(&db, 4245, "u/alice/reused", "alice").await?;
|
|
|
|
set_builder(&db, false, false).await?;
|
|
let resp = c
|
|
.post(format!("{api}/apps/create_raw"))
|
|
.multipart(raw_app(
|
|
"u/operator/a0",
|
|
"publisher",
|
|
"u/operator/some_script",
|
|
))
|
|
.send()
|
|
.await?;
|
|
assert!(
|
|
!resp.status().is_success(),
|
|
"an operator without the builder right must not create a full-code app"
|
|
);
|
|
|
|
set_builder(&db, true, true).await?;
|
|
|
|
// `*_raw_source` compiles caller-supplied sources with a bundler job on a worker. It sits
|
|
// beside `create_app_raw`, which builders MAY use, so it is the gate most likely to be opened
|
|
// by mistake later.
|
|
let resp = c
|
|
.post(format!("{api}/apps/create_raw_source"))
|
|
.json(&json!({
|
|
"path": "u/operator/a1", "summary": "",
|
|
"value": {"files": {"index.ts": "console.log(1)"}, "runnables": {}},
|
|
"policy": {"execution_mode": "publisher"}
|
|
}))
|
|
.send()
|
|
.await?;
|
|
assert!(
|
|
!resp.status().is_success(),
|
|
"a builder must not compile app sources on a worker"
|
|
);
|
|
|
|
// Low-code apps carry inline scripts, so they stay shut too.
|
|
let resp = c
|
|
.post(format!("{api}/apps/create"))
|
|
.json(&json!({
|
|
"path": "u/operator/a2", "summary": "",
|
|
"value": {"grid": []}, "policy": {"execution_mode": "publisher"}
|
|
}))
|
|
.send()
|
|
.await?;
|
|
assert!(
|
|
!resp.status().is_success(),
|
|
"a builder must not create a low-code app"
|
|
);
|
|
|
|
let resp = c
|
|
.post(format!("{api}/apps/create_raw"))
|
|
.multipart(raw_app("u/operator/a3", "publisher", "u/alice/private"))
|
|
.send()
|
|
.await?;
|
|
assert!(
|
|
!resp.status().is_success(),
|
|
"a builder must not deploy an app referencing a runnable it cannot read"
|
|
);
|
|
|
|
let resp = c
|
|
.post(format!("{api}/apps/create_raw"))
|
|
.multipart(raw_app("u/operator/a4", "viewer", "u/operator/some_script"))
|
|
.send()
|
|
.await?;
|
|
assert!(
|
|
!resp.status().is_success(),
|
|
"a builder must not deploy a viewer-mode app: the policy stops bounding what it can invoke"
|
|
);
|
|
|
|
// Storage strips a NUL, turning this key into `inlineScript`.
|
|
let resp = c
|
|
.post(format!("{api}/apps/create_raw"))
|
|
.multipart(raw_app_form(json!({
|
|
"path": "u/operator/a_nul", "summary": "",
|
|
"value": {"files": {}, "runnables": {"r": {
|
|
"type": "inline",
|
|
"inline\u{0}Script": {"content": "x", "language": "bun"}
|
|
}}},
|
|
"policy": {"execution_mode": "publisher", "triggerables_v2": {}}
|
|
})))
|
|
.send()
|
|
.await?;
|
|
assert_eq!(
|
|
resp.status(),
|
|
403,
|
|
"a NUL in a key must not hide an inline script: {}",
|
|
resp.text().await?
|
|
);
|
|
|
|
let resp = c
|
|
.post(format!("{api}/apps/create_raw"))
|
|
.multipart(raw_app(
|
|
"u/operator/a5",
|
|
"publisher",
|
|
"u/operator/some_script",
|
|
))
|
|
.send()
|
|
.await?;
|
|
assert!(
|
|
resp.status().is_success(),
|
|
"a builder must be able to deploy a full-code app over readable runnables: {}",
|
|
resp.text().await?
|
|
);
|
|
let sandbox: Option<bool> = sqlx::query_scalar(
|
|
"SELECT (policy->>'sandbox')::boolean FROM app WHERE workspace_id = $1 AND path = $2",
|
|
)
|
|
.bind(WS)
|
|
.bind("u/operator/a5")
|
|
.fetch_one(&db)
|
|
.await?;
|
|
assert_eq!(
|
|
sandbox,
|
|
Some(true),
|
|
"a builder-authored app must be stored sandboxed"
|
|
);
|
|
|
|
// `execute_component` looks up `<component>:<path>` with an unrestricted component string, so
|
|
// a key with a second colon still resolves at run time and must not slip past validation.
|
|
let resp = c
|
|
.post(format!("{api}/apps/create_raw"))
|
|
.multipart(raw_app_form(json!({
|
|
"path": "u/operator/a6", "summary": "",
|
|
"value": {"files": {}, "runnables": {}},
|
|
"policy": {"execution_mode": "publisher", "triggerables_v2": {
|
|
"x:y:script/u/alice/private": {"static_inputs": {}, "one_of_inputs": {}}
|
|
}}
|
|
})))
|
|
.send()
|
|
.await?;
|
|
assert!(
|
|
!resp.status().is_success(),
|
|
"a multi-colon triggerable key must not hide an unreadable runnable from validation"
|
|
);
|
|
|
|
// The two rights are independent.
|
|
set_builder(&db, true, false).await?;
|
|
let resp = c
|
|
.post(format!("{api}/flows/create"))
|
|
.json(&composition_flow("u/operator/flows_only"))
|
|
.send()
|
|
.await?;
|
|
assert!(
|
|
resp.status().is_success(),
|
|
"flows-only must still create a flow: {}",
|
|
resp.text().await?
|
|
);
|
|
let resp = c
|
|
.post(format!("{api}/apps/create_raw"))
|
|
.multipart(raw_app(
|
|
"u/operator/flows_only_app",
|
|
"publisher",
|
|
"u/operator/some_script",
|
|
))
|
|
.send()
|
|
.await?;
|
|
assert!(
|
|
!resp.status().is_success(),
|
|
"flows-only must not deploy a full-code app"
|
|
);
|
|
|
|
set_builder(&db, false, true).await?;
|
|
let resp = c
|
|
.post(format!("{api}/flows/create"))
|
|
.json(&composition_flow("u/operator/apps_only"))
|
|
.send()
|
|
.await?;
|
|
assert!(
|
|
!resp.status().is_success(),
|
|
"apps-only must not create a flow"
|
|
);
|
|
let resp = c
|
|
.post(format!("{api}/apps/create_raw"))
|
|
.multipart(raw_app(
|
|
"u/operator/apps_only_app",
|
|
"publisher",
|
|
"u/operator/some_script",
|
|
))
|
|
.send()
|
|
.await?;
|
|
assert!(
|
|
resp.status().is_success(),
|
|
"apps-only must still deploy a full-code app: {}",
|
|
resp.text().await?
|
|
);
|
|
|
|
// The deploy panel saves access and frontend scopes through the settings-only endpoint.
|
|
for (body, expected) in [
|
|
(
|
|
json!({"policy": {"execution_mode": "anonymous", "triggerables_v2": {}}}),
|
|
200,
|
|
),
|
|
(
|
|
json!({"policy": {"execution_mode": "publisher", "sandbox": false, "triggerables_v2": {}}}),
|
|
403,
|
|
),
|
|
(
|
|
json!({"value": {"files": {}, "runnables": {}}, "policy": {"execution_mode": "publisher"}}),
|
|
403,
|
|
),
|
|
] {
|
|
let resp = c
|
|
.post(format!("{api}/apps/update/u/operator/apps_only_app"))
|
|
.json(&body)
|
|
.send()
|
|
.await?;
|
|
let status = resp.status();
|
|
assert_eq!(
|
|
status,
|
|
expected,
|
|
"settings update {body}: {}",
|
|
resp.text().await?
|
|
);
|
|
}
|
|
let sandbox: Option<bool> = sqlx::query_scalar(
|
|
"SELECT (policy->>'sandbox')::boolean FROM app WHERE workspace_id = $1 AND path = $2",
|
|
)
|
|
.bind(WS)
|
|
.bind("u/operator/apps_only_app")
|
|
.fetch_one(&db)
|
|
.await?;
|
|
assert_eq!(
|
|
sandbox,
|
|
Some(true),
|
|
"a settings update must not turn a builder app's sandbox off"
|
|
);
|
|
|
|
// The editor runs the runnables a draft names as whoever opens it, and its frontend code
|
|
// with their session unless the preview is sandboxed.
|
|
for (runnables, policy, expected) in [
|
|
(json!({}), json!({"sandbox": true}), 200),
|
|
(
|
|
json!({"a": {"type": "inline", "inlineScript": {"content": "x", "language": "bun"}}}),
|
|
json!({"sandbox": true}),
|
|
403,
|
|
),
|
|
(json!({}), json!({"sandbox": false}), 403),
|
|
(
|
|
json!({}),
|
|
json!({"sandbox": true, "execution_mode": "viewer"}),
|
|
403,
|
|
),
|
|
(json!({}), json!(null), 403),
|
|
(
|
|
json!({}),
|
|
json!({"sandbox": true, "on_behalf_of": "u/alice", "on_behalf_of_email": "alice@windmill.dev"}),
|
|
403,
|
|
),
|
|
(
|
|
json!({}),
|
|
json!({"sandbox": true, "on_behalf_of": "u/operator"}),
|
|
200,
|
|
),
|
|
(
|
|
json!({}),
|
|
json!({"sandbox": true, "triggerables": {
|
|
format!("{}script/u/operator/some_script", "a:".repeat(300)): {}
|
|
}}),
|
|
400,
|
|
),
|
|
(
|
|
json!({"r": {"type": "runnableByPath", "runType": "script", "path": "u/operator/some_script"}}),
|
|
json!({"sandbox": true}),
|
|
200,
|
|
),
|
|
(
|
|
json!({"r": {"type": "runnableByPath", "runType": "script", "path": "u/alice/private"}}),
|
|
json!({"sandbox": true}),
|
|
403,
|
|
),
|
|
(
|
|
json!({"r": {"type": "runnableByPath", "runType": "script", "path": "u/alice/reused"}}),
|
|
json!({"sandbox": true}),
|
|
403,
|
|
),
|
|
(
|
|
json!({"r": {"type": "path", "runType": "hubscript", "path": "hub/1/x/y"}}),
|
|
json!({"sandbox": true}),
|
|
403,
|
|
),
|
|
(
|
|
json!({"r": {"type": "path", "runType": "script/u/alice", "path": "u/operator/some_script"}}),
|
|
json!({"sandbox": true}),
|
|
400,
|
|
),
|
|
(
|
|
json!({"r": {"type": "path", "runType": "script", "path": ["u/alice/private"]}}),
|
|
json!({"sandbox": true}),
|
|
400,
|
|
),
|
|
(
|
|
json!({"r": {"type": ["path"], "runType": "script", "path": "u/alice/private"}}),
|
|
json!({"sandbox": true}),
|
|
400,
|
|
),
|
|
(
|
|
json!([{"type": "path", "runType": "script", "path": "u/alice/private"}]),
|
|
json!({"sandbox": true}),
|
|
400,
|
|
),
|
|
(
|
|
json!({"r": {"type": "path", "runType": "script", "path": "u/operator/some_script",
|
|
"fields": {"x": {"type": "static", "value": {"type": "path", "path": "/srv/out"}}}}}),
|
|
json!({"sandbox": true}),
|
|
200,
|
|
),
|
|
(
|
|
json!({}),
|
|
json!({"sandbox": true, "triggerables": {"x:rawscript/abc": {}}}),
|
|
403,
|
|
),
|
|
(
|
|
json!({}),
|
|
json!({"sandbox": true, "triggerables": {"x:script/u/alice/private": {}}}),
|
|
403,
|
|
),
|
|
(
|
|
json!({}),
|
|
json!({"sandbox": true, "triggerables_v2": {
|
|
"x:script/u/alice/private": {"static_inputs": {}, "one_of_inputs": {}},
|
|
"y:rawscript/abc": {"static_inputs": {}, "one_of_inputs": {}}
|
|
}}),
|
|
200,
|
|
),
|
|
] {
|
|
let resp = c
|
|
.post(format!("{api}/drafts/update/raw_app/u/operator/d1"))
|
|
.json(&json!({
|
|
"value": {"files": {}, "runnables": runnables, "summary": "", "policy": policy},
|
|
"force": true
|
|
}))
|
|
.send()
|
|
.await?;
|
|
let status = resp.status();
|
|
assert_eq!(
|
|
status,
|
|
expected,
|
|
"raw app draft {runnables} {policy}: {}",
|
|
resp.text().await?
|
|
);
|
|
}
|
|
|
|
// The component preview runs a deployed runnable for a builder; inline code and hub
|
|
// scripts are unreviewed code.
|
|
for (preview, expected) in [
|
|
(json!({"path": "script/u/operator/some_script"}), 200),
|
|
(json!({"path": "script/hub/1/x/y"}), 403),
|
|
(
|
|
json!({"raw_code": {"content": "x", "language": "bun"}}),
|
|
403,
|
|
),
|
|
] {
|
|
let mut body = json!({"component": "c", "args": {}, "force_viewer_static_fields": {}});
|
|
body.as_object_mut()
|
|
.unwrap()
|
|
.extend(preview.as_object().unwrap().clone());
|
|
let resp = c
|
|
.post(format!(
|
|
"{api}/apps_u/execute_component/u/operator/apps_only_app"
|
|
))
|
|
.json(&body)
|
|
.send()
|
|
.await?;
|
|
let status = resp.status();
|
|
assert_eq!(
|
|
status,
|
|
expected,
|
|
"component preview {preview}: {}",
|
|
resp.text().await?
|
|
);
|
|
}
|
|
|
|
// Delete and redeploy each serve both kinds; builder rights cover only full-code apps.
|
|
let resp = client("SECRET_TOKEN")
|
|
.post(format!("{api}/apps/create"))
|
|
.json(&json!({
|
|
"path": "u/operator/low_code", "summary": "",
|
|
"value": {"grid": []}, "policy": {"execution_mode": "publisher"}
|
|
}))
|
|
.send()
|
|
.await?;
|
|
assert!(resp.status().is_success(), "{}", resp.text().await?);
|
|
let resp = c
|
|
.post(format!("{api}/apps/update_raw/u/operator/low_code"))
|
|
.multipart(raw_app_form(json!({
|
|
"policy": {"execution_mode": "publisher", "triggerables_v2": {}}
|
|
})))
|
|
.send()
|
|
.await?;
|
|
assert_eq!(
|
|
resp.status(),
|
|
403,
|
|
"policy-only update of a low-code app: {}",
|
|
resp.text().await?
|
|
);
|
|
// Deployment history restores a full-code version with allow_kind_change set.
|
|
let resp = c
|
|
.post(format!("{api}/apps/update_raw/u/operator/apps_only_app"))
|
|
.multipart(raw_app_form(json!({
|
|
"value": {"files": {}, "runnables": {}},
|
|
"policy": {"execution_mode": "publisher", "triggerables_v2": {}},
|
|
"allow_kind_change": true
|
|
})))
|
|
.send()
|
|
.await?;
|
|
assert_eq!(
|
|
resp.status(),
|
|
200,
|
|
"restore of a full-code version: {}",
|
|
resp.text().await?
|
|
);
|
|
for (path, expected) in [("low_code", 403), ("apps_only_app", 200)] {
|
|
let resp = c
|
|
.delete(format!("{api}/apps/delete/u/operator/{path}"))
|
|
.send()
|
|
.await?;
|
|
let status = resp.status();
|
|
assert_eq!(status, expected, "delete {path}: {}", resp.text().await?);
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
/// The readability check must not hold its RLS transaction while it takes a second connection,
|
|
/// or a one-connection pool (`DATABASE_CONNECTIONS=1`) stalls every builder draft naming a script.
|
|
#[sqlx::test(migrations = "../migrations", fixtures("base", "permissions_test"))]
|
|
#[serial]
|
|
async fn test_operator_builder_app_check_fits_one_connection(
|
|
pool_opts: sqlx::postgres::PgPoolOptions,
|
|
connect_opts: sqlx::postgres::PgConnectOptions,
|
|
) -> anyhow::Result<()> {
|
|
initialize_tracing().await;
|
|
let db = pool_opts
|
|
.max_connections(1)
|
|
.acquire_timeout(std::time::Duration::from_secs(5))
|
|
.connect_with(connect_opts)
|
|
.await?;
|
|
let server = ApiServer::start(db.clone()).await?;
|
|
let api = format!("http://localhost:{}/api/w/{WS}", server.addr.port());
|
|
add_script(&db, 4241, "u/operator/some_script", "operator").await?;
|
|
set_builder(&db, false, true).await?;
|
|
|
|
let resp = client("OPERATOR_TOKEN_1")
|
|
.post(format!("{api}/drafts/update/raw_app/u/operator/d1"))
|
|
.json(&json!({
|
|
"value": {"files": {}, "summary": "", "runnables": {"r": {
|
|
"name": "r", "type": "runnableByPath", "runType": "script",
|
|
"path": "u/operator/some_script"
|
|
}}, "policy": {"sandbox": true, "triggerables_v2": {}}},
|
|
"force": true
|
|
}))
|
|
.send()
|
|
.await?;
|
|
let status = resp.status();
|
|
assert_eq!(status, 200, "{}", resp.text().await?);
|
|
Ok(())
|
|
}
|